Commit 6fd195d76c7f52baae5540e287affe2259900d36

Vicent Marti 2010-11-02T18:42:42

Change git_repository initialization to use a path The constructor to git_repository is now called 'git_repository_open(path)' and takes a path to a git repository instead of an existing ODB object. Unit tests have been updated accordingly and the two test repositories have been merged into one. Signed-off-by: Vicent Marti <tanoku@gmail.com>

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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
diff --git a/src/fileops.c b/src/fileops.c
index f101cec..e0a5ff4 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -53,6 +53,13 @@ int gitfo_write(git_file fd, void *buf, size_t cnt)
 	return GIT_SUCCESS;
 }
 
+int gitfo_isdir(const char *path)
+{
+	struct stat st;
+	return (path && gitfo_stat(path, &st) == 0 && S_ISDIR(st.st_mode)) ? 
+		GIT_SUCCESS : GIT_ENOTFOUND;
+}
+
 int gitfo_exists(const char *path)
 {
 	return access(path, F_OK);
diff --git a/src/fileops.h b/src/fileops.h
index 2da4231..618bddd 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -57,6 +57,7 @@ typedef struct {  /* file io buffer  */
 extern int gitfo_exists(const char *path);
 extern int gitfo_open(const char *path, int flags);
 extern int gitfo_creat(const char *path, int mode);
+extern int gitfo_isdir(const char *path);
 #define gitfo_close(fd) close(fd)
 
 extern int gitfo_read(git_file fd, void *buf, size_t cnt);
diff --git a/src/git/index.h b/src/git/index.h
index 46fccbd..3b26235 100644
--- a/src/git/index.h
+++ b/src/git/index.h
@@ -1,6 +1,7 @@
 #ifndef INCLUDE_git_index_h__
 #define INCLUDE_git_index_h__
 
+#include <stdint.h>
 #include "common.h"
 #include "oid.h"
 
@@ -16,18 +17,50 @@ GIT_BEGIN_DECL
 /** Memory representation of an index file. */
 typedef struct git_index git_index;
 
+
+/** Time used in a git index entry */
+typedef struct {
+	uint32_t seconds;
+	uint32_t nanoseconds;
+} git_index_time;
+
 /** Memory representation of a file entry in the index. */
-typedef struct git_index_entry git_index_entry;
+typedef struct git_index_entry {
+	git_index_time ctime;
+	git_index_time mtime;
+
+	uint32_t dev;
+	uint32_t ino;
+	uint32_t mode;
+	uint32_t uid;
+	uint32_t gid;
+	uint32_t file_size;
+
+	git_oid oid;
+
+	uint16_t flags;
+	uint16_t flags_extended;
+
+	char *path;
+} git_index_entry;
 
 
 /**
  * Create a new Git index object as a memory representation
  * of the Git index file in 'index_path'.
  *
+ * The argument 'working_dir' is the root path of the indexed
+ * files in the index and is used to calculate the relative path
+ * when inserting new entries from existing files on disk.
+ *
+ * If 'working _dir' is NULL (e.g for bare repositories), the
+ * methods working on on-disk files will fail.
+ *
  * @param index_path the path to the index file in disk
+ * @param working_dir working dir for the git repository
  * @return the index object; NULL if the index could not be created
  */
-GIT_EXTERN(git_index *) git_index_alloc(const char *index_path);
+GIT_EXTERN(git_index *) git_index_alloc(const char *index_path, const char *working_dir);
 
 /**
  * Clear the contents (all the entries) of an index object.
@@ -83,6 +116,19 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
  */
 GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
 
+/**
+ * Get a pointer to one of the entries in the index
+ *
+ * This entry can be modified, and the changes will be written
+ * back to disk on the next write() call.
+ *
+ * @param index an existing index object
+ * @param n the position of the entry
+ * @return a pointer to the entry; NULL if out of bounds
+ */
+GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, int n);
+
+
 /** @} */
 GIT_END_DECL
 #endif
diff --git a/src/git/repository.h b/src/git/repository.h
index 0a50fe1..058849b 100644
--- a/src/git/repository.h
+++ b/src/git/repository.h
@@ -4,6 +4,7 @@
 #include "common.h"
 #include "odb.h"
 #include "commit.h"
+#include "index.h"
 
 /**
  * @file git/repository.h
@@ -15,15 +16,28 @@
 GIT_BEGIN_DECL
 
 /**
- * Allocate a new repository object.
+ * Open a git repository.
  *
- * TODO: specify the repository's path instead
- * of its object database
+ * The 'path' argument must point to an existing git repository
+ * folder, e.g.
  *
- * @param odb an existing object database to back the repo
+ *		/path/to/my_repo/.git/	(normal repository)
+ *							objects/
+ *							index
+ *							HEAD
+ *
+ *		/path/to/bare_repo/		(bare repository)
+ *						objects/
+ *						index
+ *						HEAD
+ *
+ *	The method will automatically detect if 'path' is a normal
+ *	or bare repository or fail is 'path' is neither.
+ *
+ * @param path the path to the repository
  * @return the new repository handle; NULL on error
  */
-GIT_EXTERN(git_repository *) git_repository_alloc(git_odb *odb);
+GIT_EXTERN(git_repository *) git_repository_open(const char *path);
 
 
 /**
@@ -58,6 +72,15 @@ GIT_EXTERN(git_object *) git_repository_lookup(git_repository *repo, const git_o
 GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
 
 /**
+ * Get the Index file of a Git repository
+ *
+ * @param repo a repository object
+ * @return a pointer to the Index object; 
+ *	NULL if the index cannot be opened
+ */
+GIT_EXTERN(git_index *) git_repository_index(git_repository *rpeo);
+
+/**
  * Create a new in-memory repository object with
  * the given type.
  *
diff --git a/src/index.c b/src/index.c
index 991f1b1..9996c50 100644
--- a/src/index.c
+++ b/src/index.c
@@ -97,7 +97,7 @@ static int read_tree(git_index *index, const char *buffer, size_t buffer_size);
 static git_index_tree *read_tree_internal(const char **, const char *, git_index_tree *);
 
 
-git_index *git_index_alloc(const char *index_path)
+git_index *git_index_alloc(const char *index_path, const char *work_dir)
 {
 	git_index *index;
 
@@ -116,6 +116,9 @@ git_index *git_index_alloc(const char *index_path)
 		return NULL;
 	}
 
+	if (work_dir != NULL)
+		index->working_path = git__strdup(work_dir);
+
 	/* Check if index file is stored on disk already */
 	if (gitfo_exists(index->index_file_path) == 0)
 		index->on_disk = 1;
@@ -126,6 +129,9 @@ git_index *git_index_alloc(const char *index_path)
 void git_index_clear(git_index *index)
 {
 	unsigned int i;
+
+	assert(index);
+
 	for (i = 0; i < index->entry_count; ++i)
 		free(index->entries[i].path);
 
@@ -139,6 +145,9 @@ void git_index_clear(git_index *index)
 
 void git_index_free(git_index *index)
 {
+	if (index == NULL)
+		return;
+
 	git_index_clear(index);
 	free(index->entries);
 	index->entries = NULL;
@@ -213,6 +222,11 @@ int git_index_write(git_index *index)
 	return 0;
 }
 
+git_index_entry *git_index_get(git_index *index, int n)
+{
+	return (n >= 0 && (unsigned int)n < index->entry_count) ? &index->entries[n] : NULL;
+}
+
 int git_index_add(git_index *index, const char *filename, int stage)
 {
 	git_index_entry entry;
@@ -225,7 +239,7 @@ int git_index_add(git_index *index, const char *filename, int stage)
 	if (path_length < GIT_IDXENTRY_NAMEMASK)
 		entry.flags |= path_length;
 	else
-		entry.flags |= path_length;
+		entry.flags |= GIT_IDXENTRY_NAMEMASK;;
 
 	if (stage < 0 || stage > 3)
 		return GIT_ERROR;
diff --git a/src/index.h b/src/index.h
index 44da78f..6a3c11e 100644
--- a/src/index.h
+++ b/src/index.h
@@ -12,31 +12,6 @@
 #define GIT_IDXENTRY_VALID     (0x8000)
 #define GIT_IDXENTRY_STAGESHIFT 12
 
-typedef struct {
-	uint32_t seconds;
-	uint32_t nanoseconds;
-} git_index_time;
-
-struct git_index_entry {
-	git_index_time ctime;
-	git_index_time mtime;
-
-	uint32_t dev;
-	uint32_t ino;
-	uint32_t mode;
-	uint32_t uid;
-	uint32_t gid;
-	uint32_t file_size;
-
-	git_oid oid;
-
-	uint16_t flags;
-	uint16_t flags_extended;
-
-	char *path;
-};
-
-
 struct git_index_tree {
 	char *name;
 
@@ -53,6 +28,8 @@ typedef struct git_index_tree git_index_tree;
 struct git_index {
 
 	char *index_file_path;
+	char *working_path;
+
 	time_t last_modified;
 
 	git_index_entry *entries;
diff --git a/src/repository.c b/src/repository.c
index fe7b870..433e729 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -28,6 +28,7 @@
 #include "repository.h"
 #include "commit.h"
 #include "tag.h"
+#include "fileops.h"
 
 static const int default_table_size = 32;
 static const double max_load_factor = 0.65;
@@ -43,7 +44,7 @@ static const size_t object_sizes[] = {
 };
 
 
-uint32_t git_object_hash(const void *key)
+uint32_t git__objtable_hash(const void *key)
 {
 	uint32_t r;
 	git_oid *id;
@@ -53,7 +54,7 @@ uint32_t git_object_hash(const void *key)
 	return r;
 }
 
-int git_object_haskey(void *object, const void *key)
+int git__objtable_haskey(void *object, const void *key)
 {
 	git_object *obj;
 	git_oid *oid;
@@ -64,7 +65,62 @@ int git_object_haskey(void *object, const void *key)
 	return (git_oid_cmp(oid, &obj->id) == 0);
 }
 
-git_repository *git_repository_alloc(git_odb *odb)
+static int parse_repository_folders(git_repository *repo, const char *repository_path)
+{
+	char path_aux[GIT_PATH_MAX];
+	int path_len, i;
+
+	if (gitfo_isdir(repository_path) < 0)
+		return GIT_ERROR;
+
+	path_len = strlen(repository_path);
+	strcpy(path_aux, repository_path);
+
+	if (path_aux[path_len - 1] != '/') {
+		path_aux[path_len] = '/';
+		path_aux[path_len + 1] = 0;
+
+		path_len = path_len + 1;
+	}
+
+	repo->path_repository = git__strdup(path_aux);
+
+	/* objects database */
+	strcpy(path_aux + path_len, "objects/");
+	if (gitfo_isdir(path_aux) < 0)
+		return GIT_ERROR;
+	repo->path_odb = git__strdup(path_aux);
+
+	/* index file */
+	strcpy(path_aux + path_len, "index");
+	if (gitfo_exists(path_aux) < 0)
+		return GIT_ERROR;
+	repo->path_index = git__strdup(path_aux);
+
+	/* HEAD file */
+	strcpy(path_aux + path_len, "HEAD");
+	if (gitfo_exists(path_aux) < 0)
+		return GIT_ERROR;
+
+	i = path_len - 2;
+	while (path_aux[i] != '/')
+		i--;
+
+	if (strcmp(path_aux, "/.git/") == 0) {
+		repo->is_bare = 0;
+
+		path_aux[i + 1] = 0;
+		repo->path_workdir = git__strdup(path_aux);
+
+	} else {
+		repo->is_bare = 1;
+		repo->path_workdir = NULL;
+	}
+
+	return GIT_SUCCESS;
+}
+
+git_repository *git_repository__alloc()
 {
 	git_repository *repo = git__malloc(sizeof(git_repository));
 	if (!repo)
@@ -74,15 +130,30 @@ git_repository *git_repository_alloc(git_odb *odb)
 
 	repo->objects = git_hashtable_alloc(
 			default_table_size, 
-			git_object_hash,
-			git_object_haskey);
+			git__objtable_hash,
+			git__objtable_haskey);
 
 	if (repo->objects == NULL) {
 		free(repo);
 		return NULL;
 	}
 
-	repo->db = odb; /* TODO: create ODB manually! */
+	return repo;
+}
+
+git_repository *git_repository_open(const char *path)
+{
+	git_repository *repo;
+
+	repo = git_repository__alloc();
+	if (repo == NULL)
+		return NULL;
+
+	if (parse_repository_folders(repo, path) < 0 ||
+		git_odb_open(&repo->db, repo->path_odb) < 0) {
+		git_repository_free(repo);
+		return NULL;
+	}
 
 	return repo;
 }
@@ -92,6 +163,11 @@ void git_repository_free(git_repository *repo)
 	git_hashtable_iterator it;
 	git_object *object;
 
+	free(repo->path_workdir);
+	free(repo->path_index);
+	free(repo->path_repository);
+	free(repo->path_odb);
+
 	git_hashtable_iterator_init(repo->objects, &it);
 
 	while ((object = (git_object *)
@@ -99,10 +175,21 @@ void git_repository_free(git_repository *repo)
 		git_object_free(object);
 
 	git_hashtable_free(repo->objects);
-	/* TODO: free odb */
+	git_odb_close(repo->db);
+	git_index_free(repo->index);
 	free(repo);
 }
 
+git_index *git_repository_index(git_repository *repo)
+{
+	if (repo->index == NULL) {
+		repo->index = git_index_alloc(repo->path_index, repo->path_workdir);
+		assert(repo->index && repo->index->on_disk);
+	}
+
+	return repo->index;
+}
+
 static int source_resize(git_odb_source *src)
 {
 	size_t write_offset, new_size;
diff --git a/src/repository.h b/src/repository.h
index 0ccfc5e..ca76d45 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -7,6 +7,7 @@
 #include "git/repository.h"
 
 #include "hashtable.h"
+#include "index.h"
 
 typedef struct {
 	git_rawobj raw;
@@ -24,7 +25,15 @@ struct git_object {
 
 struct git_repository {
 	git_odb *db;
+	git_index *index;
 	git_hashtable *objects;
+
+	char *path_repository;
+	char *path_index;
+	char *path_odb;
+	char *path_workdir;
+
+	unsigned is_bare:1;
 };
 
 
diff --git a/tests/resources/index b/tests/resources/index
deleted file mode 100644
index a27fb9c..0000000
Binary files a/tests/resources/index and /dev/null differ
diff --git a/tests/resources/pack-odb/7b/4384978d2493e851f9cca7858815fac9b10980 b/tests/resources/pack-odb/7b/4384978d2493e851f9cca7858815fac9b10980
deleted file mode 100644
index 23c462f..0000000
Binary files a/tests/resources/pack-odb/7b/4384978d2493e851f9cca7858815fac9b10980 and /dev/null differ
diff --git a/tests/resources/pack-odb/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 b/tests/resources/pack-odb/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1
deleted file mode 100644
index f460f25..0000000
--- a/tests/resources/pack-odb/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1
+++ /dev/null
@@ -1,2 +0,0 @@
-xA
-0a9I	p'1Ѷv\x{cVpvWgǎ0x[]"g#{rD
Cot N U$?9-p+1^Qx9O\C	m'D
{mV(+l,
\ No newline at end of file
diff --git a/tests/resources/pack-odb/info/packs b/tests/resources/pack-odb/info/packs
deleted file mode 100644
index 895b1c3..0000000
--- a/tests/resources/pack-odb/info/packs
+++ /dev/null
@@ -1,2 +0,0 @@
-P pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack
-
diff --git a/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx b/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx
deleted file mode 100644
index 5068f28..0000000
Binary files a/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx and /dev/null differ
diff --git a/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack b/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack
deleted file mode 100644
index a6a1f30..0000000
Binary files a/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack and /dev/null differ
diff --git a/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx b/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx
deleted file mode 100644
index 555cfa9..0000000
Binary files a/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx and /dev/null differ
diff --git a/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack b/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack
deleted file mode 100644
index 4d539ed..0000000
Binary files a/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack and /dev/null differ
diff --git a/tests/resources/sample-odb/13/85f264afb75a56a5bec74243be9b367ba4ca08 b/tests/resources/sample-odb/13/85f264afb75a56a5bec74243be9b367ba4ca08
deleted file mode 100644
index cedb2a2..0000000
Binary files a/tests/resources/sample-odb/13/85f264afb75a56a5bec74243be9b367ba4ca08 and /dev/null differ
diff --git a/tests/resources/sample-odb/18/1037049a54a1eb5fab404658a3a250b44335d7 b/tests/resources/sample-odb/18/1037049a54a1eb5fab404658a3a250b44335d7
deleted file mode 100644
index 93a16f1..0000000
Binary files a/tests/resources/sample-odb/18/1037049a54a1eb5fab404658a3a250b44335d7 and /dev/null differ
diff --git a/tests/resources/sample-odb/18/10dff58d8a660512d4832e740f692884338ccd b/tests/resources/sample-odb/18/10dff58d8a660512d4832e740f692884338ccd
deleted file mode 100644
index ba0bfb3..0000000
Binary files a/tests/resources/sample-odb/18/10dff58d8a660512d4832e740f692884338ccd and /dev/null differ
diff --git a/tests/resources/sample-odb/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 b/tests/resources/sample-odb/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
deleted file mode 100644
index 7ca4cee..0000000
Binary files a/tests/resources/sample-odb/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 and /dev/null differ
diff --git a/tests/resources/sample-odb/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 b/tests/resources/sample-odb/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
deleted file mode 100644
index 8953b6c..0000000
--- a/tests/resources/sample-odb/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
+++ /dev/null
@@ -1,2 +0,0 @@
-xQ
-0D)6ͦ "xO-FbEo0Ǥ,ske[Pn8R,EpD?g}^3<GhYK8ЖDA);gݧjp4-r;sGA4ۺ=(in7IKFE
\ No newline at end of file
diff --git a/tests/resources/sample-odb/5b/5b025afb0b4c913b4c338a42934a3863bf3644 b/tests/resources/sample-odb/5b/5b025afb0b4c913b4c338a42934a3863bf3644
deleted file mode 100644
index c1f22c5..0000000
--- a/tests/resources/sample-odb/5b/5b025afb0b4c913b4c338a42934a3863bf3644
+++ /dev/null
@@ -1,2 +0,0 @@
-x	1ENi@k2 "X$YW0YcÅszMD08!sXgd::@X0Pw"F/RUzmZZV}|/o5I!1z:vUim}/>
-F-
\ No newline at end of file
diff --git a/tests/resources/sample-odb/75/057dd4114e74cca1d750d0aee1647c903cb60a b/tests/resources/sample-odb/75/057dd4114e74cca1d750d0aee1647c903cb60a
deleted file mode 100644
index 2ef4faa..0000000
Binary files a/tests/resources/sample-odb/75/057dd4114e74cca1d750d0aee1647c903cb60a and /dev/null differ
diff --git a/tests/resources/sample-odb/81/4889a078c031f61ed08ab5fa863aea9314344d b/tests/resources/sample-odb/81/4889a078c031f61ed08ab5fa863aea9314344d
deleted file mode 100644
index 2f9b6b6..0000000
Binary files a/tests/resources/sample-odb/81/4889a078c031f61ed08ab5fa863aea9314344d and /dev/null differ
diff --git a/tests/resources/sample-odb/84/96071c1b46c854b31185ea97743be6a8774479 b/tests/resources/sample-odb/84/96071c1b46c854b31185ea97743be6a8774479
deleted file mode 100644
index 5df58dd..0000000
Binary files a/tests/resources/sample-odb/84/96071c1b46c854b31185ea97743be6a8774479 and /dev/null differ
diff --git a/tests/resources/sample-odb/9f/d738e8f7967c078dceed8190330fc8648ee56a b/tests/resources/sample-odb/9f/d738e8f7967c078dceed8190330fc8648ee56a
deleted file mode 100644
index a796124..0000000
--- a/tests/resources/sample-odb/9f/d738e8f7967c078dceed8190330fc8648ee56a
+++ /dev/null
@@ -1,3 +0,0 @@
-x[
-0E*fդ "W0-Ft݁pS[Yx^
-Db	CLhut}8X*4ZsYUA
X3RM) s6輢Mរ&Jm;}<\@ޏpĀv?jۺL?H
\ No newline at end of file
diff --git a/tests/resources/sample-odb/a4/a7dce85cf63874e984719f4fdd239f5145052f b/tests/resources/sample-odb/a4/a7dce85cf63874e984719f4fdd239f5145052f
deleted file mode 100644
index f858869..0000000
--- a/tests/resources/sample-odb/a4/a7dce85cf63874e984719f4fdd239f5145052f
+++ /dev/null
@@ -1,2 +0,0 @@
-x;j1Dmdǎ|M3`V{>QvL0I?!4Z=!צ8F!rsQy9]$D&l6A>jFWҵIKNiZ%S
-	U~̽>'	w
[DGڡQ-M>dO}\8g_ШoYr
\ No newline at end of file
diff --git a/tests/resources/sample-odb/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd b/tests/resources/sample-odb/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
deleted file mode 100644
index d0d7e73..0000000
Binary files a/tests/resources/sample-odb/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd and /dev/null differ
diff --git a/tests/resources/sample-odb/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 b/tests/resources/sample-odb/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
deleted file mode 100644
index 18a7f61..0000000
Binary files a/tests/resources/sample-odb/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 and /dev/null differ
diff --git a/tests/resources/sample-odb/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 b/tests/resources/sample-odb/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
deleted file mode 100644
index 0817229..0000000
--- a/tests/resources/sample-odb/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
+++ /dev/null
@@ -1,3 +0,0 @@
-xKj1D)zUB-0uV9<#+W<J&8/seȕKJS
-Rv{QrYQN$H\E=6X5K Fr)(dCΆjs}9c-w8o\rI:
-l}FW$DsǣٚOWe]V8-Ý"U
\ No newline at end of file
diff --git a/tests/resources/sample-odb/c4/7800c7266a2be04c571c04d5a6614691ea99bd b/tests/resources/sample-odb/c4/7800c7266a2be04c571c04d5a6614691ea99bd
deleted file mode 100644
index 75f541f..0000000
--- a/tests/resources/sample-odb/c4/7800c7266a2be04c571c04d5a6614691ea99bd
+++ /dev/null
@@ -1,3 +0,0 @@
-xQ
-0D)ʦI<'lR+FjEo0<xha ]șXUlPF)z4y,\r	'S-mI4
-Xh&F}n+\Y-p|鷜oUz;-alt{?I,:oRcHK
\ No newline at end of file
diff --git a/tests/resources/sample-odb/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests/resources/sample-odb/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
deleted file mode 100644
index 7112238..0000000
Binary files a/tests/resources/sample-odb/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 and /dev/null differ
diff --git a/tests/resources/sample-odb/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 b/tests/resources/sample-odb/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
deleted file mode 100644
index 0377096..0000000
Binary files a/tests/resources/sample-odb/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 and /dev/null differ
diff --git a/tests/resources/sample-odb/fa/49b077972391ad58037050f2a75f74e3671e92 b/tests/resources/sample-odb/fa/49b077972391ad58037050f2a75f74e3671e92
deleted file mode 100644
index 112998d..0000000
Binary files a/tests/resources/sample-odb/fa/49b077972391ad58037050f2a75f74e3671e92 and /dev/null differ
diff --git a/tests/resources/sample-odb/fd/093bff70906175335656e6ce6ae05783708765 b/tests/resources/sample-odb/fd/093bff70906175335656e6ce6ae05783708765
deleted file mode 100644
index 12bf5f3..0000000
Binary files a/tests/resources/sample-odb/fd/093bff70906175335656e6ce6ae05783708765 and /dev/null differ
diff --git a/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx b/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx
deleted file mode 100644
index 94c3c71..0000000
Binary files a/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx and /dev/null differ
diff --git a/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack b/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack
deleted file mode 100644
index 74c7fe4..0000000
Binary files a/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack and /dev/null differ
diff --git a/tests/resources/testrepo.git/HEAD b/tests/resources/testrepo.git/HEAD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/resources/testrepo.git/HEAD
diff --git a/tests/resources/testrepo.git/index b/tests/resources/testrepo.git/index
new file mode 100644
index 0000000..a27fb9c
Binary files /dev/null and b/tests/resources/testrepo.git/index differ
diff --git a/tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 b/tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08
new file mode 100644
index 0000000..cedb2a2
Binary files /dev/null and b/tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 differ
diff --git a/tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 b/tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7
new file mode 100644
index 0000000..93a16f1
Binary files /dev/null and b/tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 differ
diff --git a/tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd b/tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd
new file mode 100644
index 0000000..ba0bfb3
Binary files /dev/null and b/tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd differ
diff --git a/tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 b/tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
new file mode 100644
index 0000000..7ca4cee
Binary files /dev/null and b/tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 differ
diff --git a/tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 b/tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
new file mode 100644
index 0000000..8953b6c
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
@@ -0,0 +1,2 @@
+xQ
+0D)6ͦ "xO-FbEo0Ǥ,ske[Pn8R,EpD?g}^3<GhYK8ЖDA);gݧjp4-r;sGA4ۺ=(in7IKFE
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 b/tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
new file mode 100644
index 0000000..c1f22c5
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
@@ -0,0 +1,2 @@
+x	1ENi@k2 "X$YW0YcÅszMD08!sXgd::@X0Pw"F/RUzmZZV}|/o5I!1z:vUim}/>
+F-
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a b/tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a
new file mode 100644
index 0000000..2ef4faa
Binary files /dev/null and b/tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a differ
diff --git a/tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980 b/tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980
new file mode 100644
index 0000000..23c462f
Binary files /dev/null and b/tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980 differ
diff --git a/tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d b/tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d
new file mode 100644
index 0000000..2f9b6b6
Binary files /dev/null and b/tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d differ
diff --git a/tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 b/tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479
new file mode 100644
index 0000000..5df58dd
Binary files /dev/null and b/tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 differ
diff --git a/tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a b/tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
new file mode 100644
index 0000000..a796124
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
@@ -0,0 +1,3 @@
+x[
+0E*fդ "W0-Ft݁pS[Yx^
+Db	CLhut}8X*4ZsYUA
X3RM) s6輢Mរ&Jm;}<\@ޏpĀv?jۺL?H
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f b/tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
new file mode 100644
index 0000000..f858869
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
@@ -0,0 +1,2 @@
+x;j1Dmdǎ|M3`V{>QvL0I?!4Z=!צ8F!rsQy9]$D&l6A>jFWҵIKNiZ%S
+	U~̽>'	w
[DGڡQ-M>dO}\8g_ШoYr
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd b/tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
new file mode 100644
index 0000000..d0d7e73
Binary files /dev/null and b/tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd differ
diff --git a/tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 b/tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
new file mode 100644
index 0000000..18a7f61
Binary files /dev/null and b/tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 differ
diff --git a/tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 b/tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1
new file mode 100644
index 0000000..f460f25
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1
@@ -0,0 +1,2 @@
+xA
+0a9I	p'1Ѷv\x{cVpvWgǎ0x[]"g#{rD
Cot N U$?9-p+1^Qx9O\C	m'D
{mV(+l,
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 b/tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
new file mode 100644
index 0000000..0817229
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
@@ -0,0 +1,3 @@
+xKj1D)zUB-0uV9<#+W<J&8/seȕKJS
+Rv{QrYQN$H\E=6X5K Fr)(dCΆjs}9c-w8o\rI:
+l}FW$DsǣٚOWe]V8-Ý"U
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd b/tests/resources/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
new file mode 100644
index 0000000..75f541f
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
@@ -0,0 +1,3 @@
+xQ
+0D)ʦI<'lR+FjEo0<xha ]șXUlPF)z4y,\r	'S-mI4
+Xh&F}n+\Y-p|鷜oUz;-alt{?I,:oRcHK
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests/resources/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644
index 0000000..7112238
Binary files /dev/null and b/tests/resources/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 differ
diff --git a/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 b/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
new file mode 100644
index 0000000..0377096
Binary files /dev/null and b/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 differ
diff --git a/tests/resources/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 b/tests/resources/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92
new file mode 100644
index 0000000..112998d
Binary files /dev/null and b/tests/resources/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 differ
diff --git a/tests/resources/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 b/tests/resources/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765
new file mode 100644
index 0000000..12bf5f3
Binary files /dev/null and b/tests/resources/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 differ
diff --git a/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx b/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx
new file mode 100644
index 0000000..5068f28
Binary files /dev/null and b/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx differ
diff --git a/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack b/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack
new file mode 100644
index 0000000..a6a1f30
Binary files /dev/null and b/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack differ
diff --git a/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx b/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx
new file mode 100644
index 0000000..94c3c71
Binary files /dev/null and b/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx differ
diff --git a/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack b/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack
new file mode 100644
index 0000000..74c7fe4
Binary files /dev/null and b/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack differ
diff --git a/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx b/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx
new file mode 100644
index 0000000..555cfa9
Binary files /dev/null and b/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx differ
diff --git a/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack b/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack
new file mode 100644
index 0000000..4d539ed
Binary files /dev/null and b/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack differ
diff --git a/tests/t0204-readpack.c b/tests/t0204-readpack.c
index 8310ea3..4469454 100644
--- a/tests/t0204-readpack.c
+++ b/tests/t0204-readpack.c
@@ -2,8 +2,6 @@
 #include "test_helpers.h"
 #include <git/odb.h>
 
-#define ODB_FOLDER "../resources/pack-odb"
-
 static const char *packed_objects[] = {
 	"0266163a49e280c4f5ed1e08facd36a2bd716bcf",
 	"53fc32d17276939fc79ed05badaef2db09990016",
diff --git a/tests/t0205-readheader.c b/tests/t0205-readheader.c
index f1fc0e7..626c5a5 100644
--- a/tests/t0205-readheader.c
+++ b/tests/t0205-readheader.c
@@ -2,9 +2,6 @@
 #include "test_helpers.h"
 #include <git/odb.h>
 
-#define PACK_ODB_FOLDER "../resources/pack-odb"
-#define LOOSE_ODB_FOLDER "../resources/sample-odb"
-
 static const char *packed_objects[] = {
 	"0266163a49e280c4f5ed1e08facd36a2bd716bcf",
 	"53fc32d17276939fc79ed05badaef2db09990016",
@@ -161,7 +158,7 @@ BEGIN_TEST(readheader_packed_test)
 	unsigned int i;
     git_odb *db;
 
-    must_pass(git_odb_open(&db, PACK_ODB_FOLDER));
+    must_pass(git_odb_open(&db, ODB_FOLDER));
 
 	for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) {
 		git_oid id;
@@ -186,7 +183,7 @@ BEGIN_TEST(readheader_loose_test)
 	unsigned int i;
     git_odb *db;
 
-    must_pass(git_odb_open(&db, LOOSE_ODB_FOLDER));
+    must_pass(git_odb_open(&db, ODB_FOLDER));
 
 	for (i = 0; i < ARRAY_SIZE(loose_objects); ++i) {
 		git_oid id;
diff --git a/tests/t0401-parse.c b/tests/t0401-parse.c
index 06427a1..1a2806b 100644
--- a/tests/t0401-parse.c
+++ b/tests/t0401-parse.c
@@ -6,8 +6,6 @@
 #include <git/commit.h>
 #include <git/revwalk.h>
 
-static const char *odb_dir = "../resources/pack-odb";
-
 static char *test_commits_broken[] = {
 
 /* empty commit */
@@ -225,11 +223,8 @@ BEGIN_TEST(parse_buffer_test)
 
 	int i;
 	git_repository *repo;
-	git_odb *db;
-
-	must_pass(git_odb_open(&db, odb_dir));
 
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	for (i = 0; i < broken_commit_count; ++i) {
@@ -265,6 +260,4 @@ BEGIN_TEST(parse_buffer_test)
 	}
 
 	git_repository_free(repo);
-	git_odb_close(db);
-
 END_TEST
diff --git a/tests/t0402-details.c b/tests/t0402-details.c
index 1e00294..d60b648 100644
--- a/tests/t0402-details.c
+++ b/tests/t0402-details.c
@@ -7,7 +7,6 @@
 #include <git/commit.h>
 #include <git/revwalk.h>
 
-static const char *odb_dir = "../resources/sample-odb";
 static const char *commit_ids[] = {
 	"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
 	"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
@@ -21,14 +20,10 @@ BEGIN_TEST(query_details_test)
 	const size_t commit_count = sizeof(commit_ids) / sizeof(const char *);
 
 	unsigned int i;
-	git_odb *db;
 	git_repository *repo;
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
-
 	
 	for (i = 0; i < commit_count; ++i) {
 		git_oid id;
@@ -59,5 +54,4 @@ BEGIN_TEST(query_details_test)
 	}
 
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
diff --git a/tests/t0403-write.c b/tests/t0403-write.c
index d4669e0..60133c4 100644
--- a/tests/t0403-write.c
+++ b/tests/t0403-write.c
@@ -6,7 +6,6 @@
 #include <git/commit.h>
 #include <git/revwalk.h>
 
-static const char *odb_dir = "../resources/sample-odb";
 static const char *commit_ids[] = {
 	"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
 	"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
@@ -21,16 +20,13 @@ static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
 #define COMMITTER_EMAIL "vicent@github.com"
 
 BEGIN_TEST(writenew_test)
-	git_odb *db;
 	git_repository *repo;
 	git_commit *commit, *parent;
 	git_tree *tree;
 	git_oid id;
 	/* char hex_oid[41]; */
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	/* Create commit in memory */
@@ -71,27 +67,22 @@ This is a commit created in memory and it will be written back to disk\n");
 	printf("Written new commit, SHA1: %s\n", hex_oid);
 */
 
-	must_pass(remove_loose_object(odb_dir, (git_object *)commit));
+	must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
 
 	//git_person_free(&author);
 	//git_person_free(&committer);
 
 	git_repository_free(repo);
-	git_odb_close(db);
-
 END_TEST
 
 BEGIN_TEST(writeback_test)
-	git_odb *db;
 	git_repository *repo;
 	git_oid id;
 	git_commit *commit, *parent;
 	const char *message;
 	/* char hex_oid[41]; */
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	git_oid_mkstr(&id, commit_ids[0]);
@@ -123,8 +114,7 @@ BEGIN_TEST(writeback_test)
 	printf("New SHA1: %s\n", hex_oid);
 */
 
-	must_pass(remove_loose_object(odb_dir, (git_object *)commit));
+	must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
 
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
diff --git a/tests/t0501-walk.c b/tests/t0501-walk.c
index 9aa7261..55ae936 100644
--- a/tests/t0501-walk.c
+++ b/tests/t0501-walk.c
@@ -6,7 +6,6 @@
 #include <git/commit.h>
 #include <git/revwalk.h>
 
-static const char *odb_dir = "../resources/sample-odb";
 /*
 	$ git log --oneline --graph --decorate
 	*   a4a7dce (HEAD, br2) Merge branch 'master' into br2
@@ -91,15 +90,12 @@ static int test_walk(git_revwalk *walk, git_commit *start_from,
 }
 
 BEGIN_TEST(simple_walk_test)
-	git_odb *db;
 	git_oid id;
 	git_repository *repo;
 	git_revwalk *walk;
 	git_commit *head = NULL;
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	walk = git_revwalk_alloc(repo);
@@ -130,5 +126,4 @@ BEGIN_TEST(simple_walk_test)
 
 	git_revwalk_free(walk);
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
diff --git a/tests/t0601-read.c b/tests/t0601-read.c
index 4c31be9..345e5b5 100644
--- a/tests/t0601-read.c
+++ b/tests/t0601-read.c
@@ -5,7 +5,7 @@
 #include <git/odb.h>
 #include <git/index.h>
 
-#define TEST_INDEX_PATH "../resources/index"
+#define TEST_INDEX_PATH "../resources/testrepo.git/index"
 #define TEST_INDEX2_PATH "../resources/gitgit.index"
 
 #define TEST_INDEX_ENTRY_COUNT 109
@@ -29,7 +29,7 @@ struct test_entry TEST_ENTRIES[] = {
 BEGIN_TEST(index_loadempty_test)
 	git_index *index;
 
-	index = git_index_alloc("in-memory-index");
+	index = git_index_alloc("in-memory-index", NULL);
 	must_be_true(index != NULL);
 	must_be_true(index->on_disk == 0);
 
@@ -46,7 +46,7 @@ BEGIN_TEST(index_load_test)
 	git_index *index;
 	unsigned int i;
 
-	index = git_index_alloc(TEST_INDEX_PATH);
+	index = git_index_alloc(TEST_INDEX_PATH, NULL);
 	must_be_true(index != NULL);
 	must_be_true(index->on_disk);
 
@@ -70,7 +70,7 @@ END_TEST
 BEGIN_TEST(index2_load_test)
 	git_index *index;
 
-	index = git_index_alloc(TEST_INDEX2_PATH);
+	index = git_index_alloc(TEST_INDEX2_PATH, NULL);
 	must_be_true(index != NULL);
 	must_be_true(index->on_disk);
 
@@ -88,7 +88,7 @@ BEGIN_TEST(index_find_test)
 	git_index *index;
 	unsigned int i;
 
-	index = git_index_alloc(TEST_INDEX_PATH);
+	index = git_index_alloc(TEST_INDEX_PATH, NULL);
 	must_be_true(index != NULL);
 	must_pass(git_index_read(index));
 
@@ -104,7 +104,7 @@ BEGIN_TEST(index_findempty_test)
 	git_index *index;
 	unsigned int i;
 
-	index = git_index_alloc("fake-index");
+	index = git_index_alloc("fake-index", NULL);
 	must_be_true(index != NULL);
 
 	for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) {
diff --git a/tests/t0602-write.c b/tests/t0602-write.c
index c5e5c7d..d232193 100644
--- a/tests/t0602-write.c
+++ b/tests/t0602-write.c
@@ -5,7 +5,7 @@
 #include <git/odb.h>
 #include <git/index.h>
 
-#define TEST_INDEX_PATH "../resources/index"
+#define TEST_INDEX_PATH "../resources/testrepo.git/index"
 
 int filecmp(const char *filename1, const char *filename2)
 {
@@ -35,7 +35,7 @@ BEGIN_TEST(index_load_test)
 	git_index *index;
 	git_filelock out_file;
 
-	index = git_index_alloc(TEST_INDEX_PATH);
+	index = git_index_alloc(TEST_INDEX_PATH, NULL);
 	must_be_true(index != NULL);
 	must_pass(git_index_read(index));
 	must_be_true(index->on_disk);
diff --git a/tests/t0603-sort.c b/tests/t0603-sort.c
index 2829237..dfbb6e1 100644
--- a/tests/t0603-sort.c
+++ b/tests/t0603-sort.c
@@ -36,7 +36,7 @@ BEGIN_TEST(index_sort_test)
 	git_index *index;
 	unsigned int i;
 
-	index = git_index_alloc(TEST_INDEX_PATH);
+	index = git_index_alloc(TEST_INDEX_PATH, NULL);
 	must_be_true(index != NULL);
 	must_pass(git_index_read(index));
 
@@ -54,7 +54,7 @@ END_TEST
 
 BEGIN_TEST(index_sort_empty_test)
 	git_index *index;
-	index = git_index_alloc("fake-index");
+	index = git_index_alloc("fake-index", NULL);
 	must_be_true(index != NULL);
 
 	git_index__sort(index);
diff --git a/tests/t0801-readtag.c b/tests/t0801-readtag.c
index 9e675e8..798fa8f 100644
--- a/tests/t0801-readtag.c
+++ b/tests/t0801-readtag.c
@@ -6,21 +6,17 @@
 #include <git/commit.h>
 #include <git/tag.h>
 
-static const char *odb_dir = "../resources/pack-odb";
 static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
 static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
 static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
 
 BEGIN_TEST(readtag)
-	git_odb *db;
 	git_repository *repo;
 	git_tag *tag1, *tag2;
 	git_commit *commit;
 	git_oid id1, id2, id_commit;
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	git_oid_mkstr(&id1, tag1_id);
@@ -44,5 +40,4 @@ BEGIN_TEST(readtag)
 	must_be_true(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
 
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
diff --git a/tests/t0802-write.c b/tests/t0802-write.c
index 4fc2621..20c1eab 100644
--- a/tests/t0802-write.c
+++ b/tests/t0802-write.c
@@ -6,19 +6,15 @@
 #include <git/tag.h>
 #include <git/revwalk.h>
 
-static const char *odb_dir = "../resources/pack-odb";
 static const char *tag_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
 
 BEGIN_TEST(tag_writeback_test)
-	git_odb *db;
 	git_oid id;
 	git_repository *repo;
 	git_tag *tag;
 	/* char hex_oid[41]; */
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	git_oid_mkstr(&id, tag_id);
@@ -36,8 +32,7 @@ BEGIN_TEST(tag_writeback_test)
 	printf("TAG New SHA1: %s\n", hex_oid);
 */
 
-	must_pass(remove_loose_object(odb_dir, (git_object *)tag));
+	must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag));
 
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
diff --git a/tests/t0901-readtree.c b/tests/t0901-readtree.c
index eba6ecf..e3a85c5 100644
--- a/tests/t0901-readtree.c
+++ b/tests/t0901-readtree.c
@@ -6,18 +6,14 @@
 #include <git/commit.h>
 #include <git/revwalk.h>
 
-static const char *odb_dir = "../resources/sample-odb";
 static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
 
 BEGIN_TEST(tree_entry_access_test)
-	git_odb *db;
 	git_oid id;
 	git_repository *repo;
 	git_tree *tree;
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	git_oid_mkstr(&id, tree_oid);
@@ -34,19 +30,15 @@ BEGIN_TEST(tree_entry_access_test)
 	must_be_true(git_tree_entry_byindex(tree, -1) == NULL);
 
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
 
 BEGIN_TEST(tree_read_test)
-	git_odb *db;
 	git_oid id;
 	git_repository *repo;
 	git_tree *tree;
 	git_tree_entry *entry;
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	git_oid_mkstr(&id, tree_oid);
@@ -61,9 +53,7 @@ BEGIN_TEST(tree_read_test)
 
 	must_be_true(strcmp(git_tree_entry_name(entry), "README") == 0);
 
-
 	must_be_true(git_tree_entry_2object(entry) != NULL);
 
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
diff --git a/tests/t0902-modify.c b/tests/t0902-modify.c
index 67ae1fa..23fc03c 100644
--- a/tests/t0902-modify.c
+++ b/tests/t0902-modify.c
@@ -6,22 +6,17 @@
 #include <git/commit.h>
 #include <git/revwalk.h>
 
-static const char *odb_dir = "../resources/sample-odb";
 static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
 
 BEGIN_TEST(tree_in_memory_add_test)
 	const unsigned int entry_count = 128;
 
-
-	git_odb *db;
 	git_repository *repo;
 	git_tree *tree;
 	unsigned int i;
 	git_oid entry_id;
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	tree = git_tree_new(repo);
@@ -36,16 +31,14 @@ BEGIN_TEST(tree_in_memory_add_test)
 
 	must_be_true(git_tree_entrycount(tree) == entry_count);
 	must_pass(git_object_write((git_object *)tree));
-	must_pass(remove_loose_object(odb_dir, (git_object *)tree));
+	must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tree));
 
 	git_object_free((git_object *)tree);
 
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
 
 BEGIN_TEST(tree_add_entry_test)
-	git_odb *db;
 	git_oid id;
 	git_repository *repo;
 	git_tree *tree;
@@ -53,9 +46,7 @@ BEGIN_TEST(tree_add_entry_test)
 	unsigned int i;
 	/* char hex_oid[41]; */
 
-	must_pass(git_odb_open(&db, odb_dir));
-
-	repo = git_repository_alloc(db);
+	repo = git_repository_open(REPOSITORY_FOLDER);
 	must_be_true(repo != NULL);
 
 	git_oid_mkstr(&id, tree_oid);
@@ -92,10 +83,7 @@ BEGIN_TEST(tree_add_entry_test)
 	printf("TREE New SHA1: %s\n", hex_oid);
 */
 
-	must_pass(remove_loose_object(odb_dir, (git_object *)tree));
-	
+	must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tree));
 	git_object_free((git_object *)tree);
-
 	git_repository_free(repo);
-	git_odb_close(db);
 END_TEST
diff --git a/tests/test_helpers.c b/tests/test_helpers.c
index 08434b8..8619223 100644
--- a/tests/test_helpers.c
+++ b/tests/test_helpers.c
@@ -84,18 +84,23 @@ int remove_object_files(const char *odb_dir, object_data *d)
 	return 0;
 }
 
-int remove_loose_object(const char *odb_dir, git_object *object)
+int remove_loose_object(const char *repository_folder, git_object *object)
 {
+	static const char *objects_folder = "objects/";
+
 	char *ptr, *full_path, *top_folder;
-	int path_length;
+	int path_length, objects_length;
+
+	assert(repository_folder && object);
 
-	assert(odb_dir && object);
+	objects_length = strlen(objects_folder);
+	path_length = strlen(repository_folder);
+	ptr = full_path = git__malloc(path_length + objects_length + GIT_OID_HEXSZ + 3);
 
-	path_length = strlen(odb_dir);
-	ptr = full_path = git__malloc(path_length + GIT_OID_HEXSZ + 3);
+	strcpy(ptr, repository_folder);
+	strcpy(ptr + path_length, objects_folder);
 
-	strcpy(ptr, odb_dir);
-	ptr = top_folder = ptr + path_length;
+	ptr = top_folder = ptr + path_length + objects_length;
 	*ptr++ = '/';
 	git_oid_pathfmt(ptr, git_object_id(object));
 	ptr += GIT_OID_HEXSZ + 1;
diff --git a/tests/test_helpers.h b/tests/test_helpers.h
index 0d79d43..7085c64 100644
--- a/tests/test_helpers.h
+++ b/tests/test_helpers.h
@@ -29,6 +29,8 @@
 #include "test_lib.h"
 #include <git/odb.h>
 
+#define ODB_FOLDER "../resources/testrepo.git/objects/"
+#define REPOSITORY_FOLDER "../resources/testrepo.git/"
 
 typedef struct object_data {
     unsigned char *bytes;  /* (compressed) bytes stored in object store */