Commit f2114d0a35b95efef294f7527dfd64fbef61d993

Vicent Martí 2012-01-04T22:40:59

Merge remote-tracking branch 'nulltoken/topix/path_fromurl' into development Conflicts: tests-clay/clay.h tests-clay/clay_main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
diff --git a/src/oid.c b/src/oid.c
index 4b30804..61bf6da 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -11,24 +11,6 @@
 #include <string.h>
 #include <limits.h>
 
-static signed char from_hex[] = {
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */
--1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */
--1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 90 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* b0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* c0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* d0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* e0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* f0 */
-};
 static char to_hex[] = "0123456789abcdef";
 
 int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
@@ -43,8 +25,8 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
 		length = GIT_OID_HEXSZ;
 
 	for (p = 0; p < length - 1; p += 2) {
-		v = (from_hex[(unsigned char)str[p + 0]] << 4)
-				| from_hex[(unsigned char)str[p + 1]];
+		v = (git__fromhex(str[p + 0]) << 4)
+				| git__fromhex(str[p + 1]);
 
 		if (v < 0)
 			return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
@@ -53,7 +35,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
 	}
 
 	if (length % 2) {
-		v = (from_hex[(unsigned char)str[p + 0]] << 4);
+		v = (git__fromhex(str[p + 0]) << 4);
 		if (v < 0)
 			return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
 
@@ -346,7 +328,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
 	is_leaf = 0;
 
 	for (i = 0; i < GIT_OID_HEXSZ; ++i) {
-		int c = from_hex[(int)text_oid[i]];
+		int c = git__fromhex(text_oid[i]);
 		trie_node *node;
 
 		if (c == -1)
@@ -360,7 +342,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
 			tail = node->tail;
 			node->tail = NULL;
 
-			node = push_leaf(os, idx, from_hex[(int)tail[0]], &tail[1]);
+			node = push_leaf(os, idx, git__fromhex(tail[0]), &tail[1]);
 			if (node == NULL)
 				return GIT_ENOMEM;
 		}
diff --git a/src/path.c b/src/path.c
index e4b49f3..8c1bd41 100644
--- a/src/path.c
+++ b/src/path.c
@@ -237,3 +237,77 @@ void git_path_string_to_dir(char* path, size_t size)
 	}
 }
 
+int git__percent_decode(git_buf *decoded_out, const char *input)
+{
+	int len, hi, lo, i, error = GIT_SUCCESS;
+	assert(decoded_out && input);
+
+	len = strlen(input);
+	git_buf_clear(decoded_out);
+
+	for(i = 0; i < len; i++)
+	{
+		char c = input[i];
+
+		if (c != '%')
+			goto append;
+
+		if (i >= len - 2)
+			goto append;
+
+		hi = git__fromhex(input[i + 1]);
+		lo = git__fromhex(input[i + 2]);
+
+		if (hi < 0 || lo < 0)
+			goto append;
+
+		c = (char)(hi << 4 | lo);
+		i += 2;
+
+append:
+		error = git_buf_putc(decoded_out, c);
+		if (error < GIT_SUCCESS)
+			return git__rethrow(error, "Failed to percent decode '%s'.", input);
+	}
+
+	return error;
+}
+
+int git_path_fromurl(git_buf *local_path_out, const char *file_url)
+{
+	int error = GIT_SUCCESS, offset = 0, len;
+
+	assert(local_path_out && file_url);
+
+	if (git__prefixcmp(file_url, "file://") != 0)
+		return git__throw(GIT_EINVALIDPATH,
+			"Parsing of '%s' failed. A file Uri is expected (ie. with 'file://' scheme).",
+			file_url);
+
+	offset += 7;
+	len = strlen(file_url);
+
+	if (offset < len && file_url[offset] == '/')
+		offset++;
+	else if (offset < len && git__prefixcmp(file_url + offset, "localhost/") == 0)
+		offset += 10;
+	else
+		return git__throw(GIT_EINVALIDPATH,
+			"Parsing of '%s' failed. A local file Uri is expected.", file_url);
+
+	if (offset >= len || file_url[offset] == '/')
+		return git__throw(GIT_EINVALIDPATH, 
+			"Parsing of '%s' failed. Invalid file Uri format.", file_url);
+
+#ifndef _MSC_VER
+	offset--;	/* A *nix absolute path starts with a forward slash */
+#endif
+
+	git_buf_clear(local_path_out);
+
+	error = git__percent_decode(local_path_out, file_url + offset);
+	if (error < GIT_SUCCESS)
+		return git__rethrow(error, "Parsing of '%s' failed.", file_url);
+
+	return error;
+}
diff --git a/src/path.h b/src/path.h
index 0c8cc34..c308c5b 100644
--- a/src/path.h
+++ b/src/path.h
@@ -74,4 +74,7 @@ GIT_INLINE(void) git_path_mkposix(char *path)
 #	define git_path_mkposix(p) /* blank */
 #endif
 
+extern int git__percent_decode(git_buf *decoded_out, const char *input);
+extern int git_path_fromurl(git_buf *local_path_out, const char *file_url);
+
 #endif
diff --git a/src/transports/local.c b/src/transports/local.c
index 2937da0..a2135e7 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -13,6 +13,8 @@
 #include "refs.h"
 #include "transport.h"
 #include "posix.h"
+#include "path.h"
+#include "buffer.h"
 
 typedef struct {
 	git_transport parent;
@@ -148,7 +150,6 @@ static int local_ls(git_transport *transport, git_headlist_cb list_cb, void *pay
 	return GIT_SUCCESS;
 }
 
-
 /*
  * Try to open the url as a git directory. The direction doesn't
  * matter in this case because we're calulating the heads ourselves.
@@ -159,24 +160,26 @@ static int local_connect(git_transport *transport, int GIT_UNUSED(direction))
 	int error;
 	transport_local *t = (transport_local *) transport;
 	const char *path;
+	git_buf buf = GIT_BUF_INIT;
+
 	GIT_UNUSED_ARG(direction);
 
 	/* The repo layer doesn't want the prefix */
 	if (!git__prefixcmp(transport->url, "file://")) {
-		path = transport->url + strlen("file://");
-
-#ifdef _MSC_VER
-		/* skip the leading slash on windows before the drive letter */
-		if (*path != '/')
-			return git__throw(GIT_EINVALIDPATH, "Invalid local uri '%s'.", transport->url);
-
-		path++;
-#endif
-
-	} else
+		error = git_path_fromurl(&buf, transport->url);
+		if (error < GIT_SUCCESS) {
+			git_buf_free(&buf);
+			return git__rethrow(error, "Failed to parse remote path");
+		}
+		path = git_buf_cstr(&buf);
+
+	} else /* We assume transport->url is already a path */
 		path = transport->url;
 
 	error = git_repository_open(&repo, path);
+
+	git_buf_free(&buf);
+
 	if (error < GIT_SUCCESS)
 		return git__rethrow(error, "Failed to open remote");
 
diff --git a/src/util.h b/src/util.h
index 2367bb5..2654e2d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -138,5 +138,28 @@ typedef void (*git_refcount_freeptr)(void *r);
 
 #define GIT_REFCOUNT_OWNER(r) (((git_refcount *)(r))->owner)
 
+static signed char from_hex[] = {
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */
+-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */
+-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 90 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a0 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* b0 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* c0 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* d0 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* e0 */
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* f0 */
+};
+
+GIT_INLINE(int) git__fromhex(char h)
+{
+	return from_hex[(unsigned char) h];
+}
 
 #endif /* INCLUDE_util_h__ */
diff --git a/tests-clay/core/hex.c b/tests-clay/core/hex.c
new file mode 100644
index 0000000..391a286
--- /dev/null
+++ b/tests-clay/core/hex.c
@@ -0,0 +1,22 @@
+#include "clay_libgit2.h"
+#include "util.h"
+
+void test_core_hex__fromhex(void)
+{
+	/* Passing cases */
+	cl_assert(git__fromhex('0') == 0x0);
+	cl_assert(git__fromhex('1') == 0x1);
+	cl_assert(git__fromhex('3') == 0x3);
+	cl_assert(git__fromhex('9') == 0x9);
+	cl_assert(git__fromhex('A') == 0xa);
+	cl_assert(git__fromhex('C') == 0xc);
+	cl_assert(git__fromhex('F') == 0xf);
+	cl_assert(git__fromhex('a') == 0xa);
+	cl_assert(git__fromhex('c') == 0xc);
+	cl_assert(git__fromhex('f') == 0xf);
+
+	/* Failing cases */
+	cl_assert(git__fromhex('g') == -1);
+	cl_assert(git__fromhex('z') == -1);
+	cl_assert(git__fromhex('X') == -1);
+}
diff --git a/tests-clay/core/path.c b/tests-clay/core/path.c
index 49f85f0..bdebfb9 100644
--- a/tests-clay/core/path.c
+++ b/tests-clay/core/path.c
@@ -70,7 +70,7 @@ check_joinpath_n(
 
 
 /* get the dirname of a path */
-void test_core_path__0_dirname(void)
+void test_core_path__00_dirname(void)
 {
 	check_dirname(NULL, ".");
 	check_dirname("", ".");
@@ -90,7 +90,7 @@ void test_core_path__0_dirname(void)
 }
 
 /* get the base name of a path */
-void test_core_path__1_basename(void)
+void test_core_path__01_basename(void)
 {
 	check_basename(NULL, ".");
 	check_basename("", ".");
@@ -107,7 +107,7 @@ void test_core_path__1_basename(void)
 }
 
 /* get the latest component in a path */
-void test_core_path__2_topdir(void)
+void test_core_path__02_topdir(void)
 {
 	check_topdir(".git/", ".git/");
 	check_topdir("/.git/", ".git/");
@@ -124,7 +124,7 @@ void test_core_path__2_topdir(void)
 }
 
 /* properly join path components */
-void test_core_path__5_joins(void)
+void test_core_path__05_joins(void)
 {
 	check_joinpath("", "", "");
 	check_joinpath("", "a", "a");
@@ -159,7 +159,7 @@ void test_core_path__5_joins(void)
 }
 
 /* properly join path components for more than one path */
-void test_core_path__6_long_joins(void)
+void test_core_path__06_long_joins(void)
 {
 	check_joinpath_n("", "", "", "", "");
 	check_joinpath_n("", "a", "", "", "a/");
@@ -212,7 +212,7 @@ check_string_to_dir(
 }
 
 /* convert paths to dirs */
-void test_core_path__7_path_to_dir(void)
+void test_core_path__07_path_to_dir(void)
 {
 	check_path_to_dir("", "");
 	check_path_to_dir(".", "./");
@@ -240,7 +240,7 @@ void test_core_path__7_path_to_dir(void)
 }
 
 /* join path to itself */
-void test_core_path__8_self_join(void)
+void test_core_path__08_self_join(void)
 {
 	git_buf path = GIT_BUF_INIT;
 	ssize_t asize = 0;
@@ -273,3 +273,66 @@ void test_core_path__8_self_join(void)
 	
 	git_buf_free(&path);
 }
+
+static void check_percent_decoding(const char *expected_result, const char *input)
+{
+	git_buf buf = GIT_BUF_INIT;
+
+	cl_git_pass(git__percent_decode(&buf, input));
+	cl_assert_strequal(expected_result, git_buf_cstr(&buf));
+
+	git_buf_free(&buf);
+}
+
+void test_core_path__09_percent_decode(void)
+{
+	check_percent_decoding("abcd", "abcd");
+	check_percent_decoding("a2%", "a2%");
+	check_percent_decoding("a2%3", "a2%3");
+	check_percent_decoding("a2%%3", "a2%%3");
+	check_percent_decoding("a2%3z", "a2%3z");
+	check_percent_decoding("a,", "a%2c");
+	check_percent_decoding("a21", "a2%31");
+	check_percent_decoding("a2%1", "a2%%31");
+	check_percent_decoding("a bc ", "a%20bc%20");
+	check_percent_decoding("Vicent Mart" "\355", "Vicent%20Mart%ED");
+}
+
+static void check_fromurl(const char *expected_result, const char *input, int should_fail)
+{
+	git_buf buf = GIT_BUF_INIT;
+
+	assert(should_fail || expected_result);
+
+	if (!should_fail) {
+		cl_git_pass(git_path_fromurl(&buf, input));
+		cl_assert_strequal(expected_result, git_buf_cstr(&buf));
+	} else
+		cl_git_fail(git_path_fromurl(&buf, input));
+
+	git_buf_free(&buf);
+}
+
+#ifdef _MSC_VER
+#define ABS_PATH_MARKER ""
+#else
+#define ABS_PATH_MARKER "/"
+#endif
+
+void test_core_path__10_fromurl(void)
+{
+	/* Failing cases */
+	check_fromurl(NULL, "a", 1);
+	check_fromurl(NULL, "http:///c:/Temp%20folder/note.txt", 1);
+	check_fromurl(NULL, "file://c:/Temp%20folder/note.txt", 1);
+	check_fromurl(NULL, "file:////c:/Temp%20folder/note.txt", 1);
+	check_fromurl(NULL, "file:///", 1);
+	check_fromurl(NULL, "file:////", 1);
+	check_fromurl(NULL, "file://servername/c:/Temp%20folder/note.txt", 1);
+
+	/* Passing cases */
+	check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file:///c:/Temp%20folder/note.txt", 0);
+	check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file://localhost/c:/Temp%20folder/note.txt", 0);
+	check_fromurl(ABS_PATH_MARKER "c:/Temp+folder/note.txt", "file:///c:/Temp+folder/note.txt", 0);
+	check_fromurl(ABS_PATH_MARKER "a", "file:///a", 0);
+}
diff --git a/tests-clay/network/remotelocal.c b/tests-clay/network/remotelocal.c
index b9003e7..961c623 100644
--- a/tests-clay/network/remotelocal.c
+++ b/tests-clay/network/remotelocal.c
@@ -2,6 +2,7 @@
 #include "transport.h"
 #include "buffer.h"
 #include "path.h"
+#include "posix.h"
 
 static git_repository *repo;
 static git_buf file_path_buf = GIT_BUF_INIT;
@@ -9,9 +10,11 @@ static git_remote *remote;
 
 static void build_local_file_url(git_buf *out, const char *fixture)
 {
+	const char *in_buf;
+
 	git_buf path_buf = GIT_BUF_INIT;
 
-	cl_git_pass(git_path_prettify_dir(&path_buf, cl_fixture(fixture), NULL));
+	cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL));
 	cl_git_pass(git_buf_puts(out, "file://"));
 
 #ifdef _MSC_VER
@@ -27,21 +30,27 @@ static void build_local_file_url(git_buf *out, const char *fixture)
 	cl_git_pass(git_buf_putc(out, '/'));
 #endif
 
-	cl_git_pass(git_buf_puts(out, git_buf_cstr(&path_buf)));
+	in_buf = git_buf_cstr(&path_buf);
+
+	/*
+	 * A very hacky Url encoding that only takes care of escaping the spaces
+	 */
+	while (*in_buf) {
+		if (*in_buf == ' ')
+			cl_git_pass(git_buf_puts(out, "%20"));
+		else
+			cl_git_pass(git_buf_putc(out, *in_buf));
+
+		in_buf++;
+	}
 
 	git_buf_free(&path_buf);
 }
 
 void test_network_remotelocal__initialize(void)
 {
-	cl_fixture("remotelocal");
 	cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
 	cl_assert(repo != NULL);
-
-	build_local_file_url(&file_path_buf, "testrepo.git");
-
-	cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
-	cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
 }
 
 void test_network_remotelocal__cleanup(void)
@@ -62,11 +71,38 @@ static int count_ref__cb(git_remote_head *head, void *payload)
 	return GIT_SUCCESS;
 }
 
+static void connect_to_local_repository(const char *local_repository)
+{
+	build_local_file_url(&file_path_buf, local_repository);
+
+	cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
+	cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
+
+}
+
 void test_network_remotelocal__retrieve_advertised_references(void)
 {
 	int how_many_refs = 0;
 
+	connect_to_local_repository(cl_fixture("testrepo.git"));
+
 	cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
 
 	cl_assert(how_many_refs == 12); /* 1 HEAD + 9 refs + 2 peeled tags */
 }
+
+void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
+{
+	int how_many_refs = 0;
+
+	cl_fixture_sandbox("testrepo.git");
+	cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git"));
+
+	connect_to_local_repository("spaced testrepo.git");
+
+	cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+
+	cl_assert(how_many_refs == 12); /* 1 HEAD */
+
+	cl_fixture_cleanup("spaced testrepo.git");
+}
diff --git a/tests-clay/object/raw/chars.c b/tests-clay/object/raw/chars.c
index eba352b..83bcbeb 100644
--- a/tests-clay/object/raw/chars.c
+++ b/tests-clay/object/raw/chars.c
@@ -3,17 +3,6 @@
 
 #include "odb.h"
 
-static int from_hex(unsigned int i)
-{
-	if (i >= '0' && i <= '9')
-		return i - '0';
-	if (i >= 'a' && i <= 'f')
-		return 10 + (i - 'a');
-	if (i >= 'A' && i <= 'F')
-		return 10 + (i - 'A');
-	return -1;
-}
-
 void test_object_raw_chars__find_invalid_chars_in_oid(void)
 {
 	git_oid out;
@@ -28,8 +17,8 @@ void test_object_raw_chars__find_invalid_chars_in_oid(void)
 
 	for (i = 0; i < 256; i++) {
 		in[38] = (char)i;
-		if (from_hex(i) >= 0) {
-			exp[19] = (unsigned char)(from_hex(i) << 4);
+		if (git__fromhex(i) >= 0) {
+			exp[19] = (unsigned char)(git__fromhex(i) << 4);
 			cl_git_pass(git_oid_fromstr(&out, in));
 			cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0);
 		} else {
diff --git a/tests/t01-rawobj.c b/tests/t01-rawobj.c
index 8b05f33..7b9ca1e 100644
--- a/tests/t01-rawobj.c
+++ b/tests/t01-rawobj.c
@@ -52,17 +52,6 @@ BEGIN_TEST(oid2, "fail when parsing an invalid string as oid")
 	must_fail(git_oid_fromstr(&out, "moo"));
 END_TEST
 
-static int from_hex(unsigned int i)
-{
-	if (i >= '0' && i <= '9')
-		return i - '0';
-	if (i >= 'a' && i <= 'f')
-		return 10 + (i - 'a');
-	if (i >= 'A' && i <= 'F')
-		return 10 + (i - 'A');
-	return -1;
-}
-
 BEGIN_TEST(oid3, "find all invalid characters when parsing an oid")
 	git_oid out;
 	unsigned char exp[] = {
@@ -77,8 +66,8 @@ BEGIN_TEST(oid3, "find all invalid characters when parsing an oid")
 	for (i = 0; i < 256; i++) {
 		in[38] = (char)i;
 
-		if (from_hex(i) >= 0) {
-			exp[19] = (unsigned char)(from_hex(i) << 4);
+		if (git__fromhex(i) >= 0) {
+			exp[19] = (unsigned char)(git__fromhex(i) << 4);
 			must_pass(git_oid_fromstr(&out, in));
 			must_be_true(memcmp(out.id, exp, sizeof(out.id)) == 0);
 		} else {