6 static char *odb_dir
= "test-objects";
8 typedef struct object_data
{
9 char *id
; /* object id (sha1) */
10 char *dir
; /* object store (fan-out) directory name */
11 char *file
; /* object store filename */
14 static object_data commit
= {
15 "3d7f8a6af076c8c3f20071a8935cdbe8228594d1",
17 "test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1",
20 static unsigned char commit_data
[] = {
21 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66,
22 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35,
23 0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38,
24 0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32,
25 0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33,
26 0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75,
27 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55,
28 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61,
29 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78,
30 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
31 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38,
32 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30,
33 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d,
34 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20,
35 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
36 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
37 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
38 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
39 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
40 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
41 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65,
42 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f,
43 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d,
44 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68,
45 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f,
46 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
47 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73,
48 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f,
49 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67,
50 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72,
51 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61,
52 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20,
53 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70,
54 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74,
55 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67,
56 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f,
57 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79,
58 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d,
59 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69,
60 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d,
61 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20,
62 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75,
63 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61,
64 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
68 static git_obj commit_obj
= {
74 static object_data tree
= {
75 "dff2da90b254e1beb889d1f1f1288be1803782df",
77 "test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df",
80 static unsigned char tree_data
[] = {
81 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f,
82 0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79,
83 0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b,
84 0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31,
85 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f,
86 0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86,
87 0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8,
88 0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31,
89 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77,
90 0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b,
91 0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd,
92 0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30,
93 0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72,
94 0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1,
95 0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a,
96 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91,
99 static git_obj tree_obj
= {
105 static object_data tag
= {
106 "09d373e1dfdc16b129ceec6dd649739911541e05",
108 "test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05",
111 static unsigned char tag_data
[] = {
112 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33,
113 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66,
114 0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66,
115 0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39,
116 0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32,
117 0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a,
118 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d,
119 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20,
120 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74,
121 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20,
122 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
123 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
124 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
125 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
126 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
127 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
128 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20,
129 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
130 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63,
131 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65,
132 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30,
133 0x2e, 0x30, 0x2e, 0x31, 0x0a,
136 static git_obj tag_obj
= {
142 static object_data zero
= {
143 "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
145 "test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391",
148 static unsigned char zero_data
[] = {
149 0x00 /* dummy data */
152 static git_obj zero_obj
= {
158 static object_data one
= {
159 "8b137891791fe96927ad78e64b0aad7bded08bdc",
161 "test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc",
164 static unsigned char one_data
[] = {
168 static git_obj one_obj
= {
174 static object_data two
= {
175 "78981922613b2afb6025042ff6bd878ac1994e85",
177 "test-objects/78/981922613b2afb6025042ff6bd878ac1994e85",
180 static unsigned char two_data
[] = {
184 static git_obj two_obj
= {
190 static object_data some
= {
191 "fd8430bc864cfcd5f10e5590f8a447e01b942bfe",
193 "test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe",
196 static unsigned char some_data
[] = {
197 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68,
198 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20,
199 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20,
200 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
201 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61,
202 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74,
203 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69,
204 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72,
205 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a,
206 0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e,
207 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20,
208 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66,
209 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
210 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
211 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
212 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c,
213 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
214 0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61,
215 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73,
216 0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74,
217 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
218 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
219 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
220 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a,
221 0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64,
222 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74,
223 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65,
224 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e,
225 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65,
226 0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e,
227 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62,
228 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65,
229 0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20,
230 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68,
231 0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65,
232 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c,
233 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70,
234 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f,
235 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e,
236 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
237 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20,
238 0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
239 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69,
240 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69,
241 0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62,
242 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73,
243 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74,
244 0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67,
245 0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a,
246 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20,
247 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75,
248 0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65,
249 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61,
250 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69,
251 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e,
252 0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69,
253 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a,
254 0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20,
255 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65,
256 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20,
257 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
258 0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65,
259 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
260 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
261 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
262 0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72,
263 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20,
264 0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79,
265 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65,
266 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63,
267 0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20,
268 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c,
269 0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f,
270 0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d,
271 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
272 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74,
273 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c,
274 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73,
275 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f,
276 0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e,
277 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65,
278 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20,
279 0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62,
280 0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65,
281 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e,
282 0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20,
283 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
284 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73,
285 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64,
286 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20,
287 0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61,
288 0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c,
289 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65,
290 0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74,
291 0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48,
292 0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20,
293 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59,
294 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75,
295 0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74,
296 0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69,
297 0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61,
298 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20,
299 0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41,
300 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54,
301 0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54,
302 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52,
303 0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49,
304 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55,
305 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20,
306 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20,
307 0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47,
308 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50,
309 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69,
310 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f,
311 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64,
312 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a,
313 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f,
314 0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64,
315 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65,
316 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61,
317 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66,
318 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
319 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
320 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
321 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
322 0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67,
323 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68,
324 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
325 0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20,
326 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65,
327 0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47,
328 0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f,
329 0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65,
330 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74,
331 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
332 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
333 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
334 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20,
335 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e,
336 0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c,
337 0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46,
338 0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a,
339 0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c,
340 0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31,
341 0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20,
342 0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f,
346 static git_obj some_obj
= {
352 static int make_odb_dir(void)
354 if (gitfo_mkdir(odb_dir
, 0755) < 0) {
355 if (errno
== EEXIST
) {
356 fprintf(stderr
, "odb directory \"%s\" already exists!\n", odb_dir
);
359 fprintf(stderr
, "can't make odb directory \"%s\"\n", odb_dir
);
366 static int remove_object_files(object_data
*d
)
368 if (gitfo_unlink(d
->file
) < 0) {
369 fprintf(stderr
, "can't delete object file \"%s\"\n", d
->file
);
372 if ((gitfo_rmdir(d
->dir
) < 0) && (errno
!= ENOTEMPTY
)) {
373 fprintf(stderr
, "can't remove object directory \"%s\"\n", d
->dir
);
377 if (gitfo_rmdir(odb_dir
) < 0) {
378 fprintf(stderr
, "can't remove odb directory \"%s\"\n", odb_dir
);
385 static int check_object_files(object_data
*d
)
387 if (gitfo_exists(d
->dir
) < 0)
389 if (gitfo_exists(d
->file
) < 0)
394 static int cmp_objects(git_obj
*o1
, git_obj
*o2
)
396 if (o1
->type
!= o2
->type
)
398 if (o1
->len
!= o2
->len
)
400 if ((o1
->len
> 0) && (memcmp(o1
->data
, o2
->data
, o1
->len
) != 0))
405 BEGIN_TEST(write_commit
)
410 must_pass(make_odb_dir());
411 must_pass(git_odb_open(&db
, odb_dir
));
412 must_pass(git_oid_mkstr(&id1
, commit
.id
));
414 must_pass(git_odb_write(&id2
, db
, &commit_obj
));
415 must_be_true(git_oid_cmp(&id1
, &id2
) == 0);
416 must_pass(check_object_files(&commit
));
418 must_pass(git_odb__read_loose(&obj
, db
, &id1
));
419 must_pass(cmp_objects(&obj
, &commit_obj
));
423 must_pass(remove_object_files(&commit
));
426 BEGIN_TEST(write_tree
)
431 must_pass(make_odb_dir());
432 must_pass(git_odb_open(&db
, odb_dir
));
433 must_pass(git_oid_mkstr(&id1
, tree
.id
));
435 must_pass(git_odb_write(&id2
, db
, &tree_obj
));
436 must_be_true(git_oid_cmp(&id1
, &id2
) == 0);
437 must_pass(check_object_files(&tree
));
439 must_pass(git_odb__read_loose(&obj
, db
, &id1
));
440 must_pass(cmp_objects(&obj
, &tree_obj
));
444 must_pass(remove_object_files(&tree
));
447 BEGIN_TEST(write_tag
)
452 must_pass(make_odb_dir());
453 must_pass(git_odb_open(&db
, odb_dir
));
454 must_pass(git_oid_mkstr(&id1
, tag
.id
));
456 must_pass(git_odb_write(&id2
, db
, &tag_obj
));
457 must_be_true(git_oid_cmp(&id1
, &id2
) == 0);
458 must_pass(check_object_files(&tag
));
460 must_pass(git_odb__read_loose(&obj
, db
, &id1
));
461 must_pass(cmp_objects(&obj
, &tag_obj
));
465 must_pass(remove_object_files(&tag
));
468 BEGIN_TEST(write_zero
)
473 must_pass(make_odb_dir());
474 must_pass(git_odb_open(&db
, odb_dir
));
475 must_pass(git_oid_mkstr(&id1
, zero
.id
));
477 must_pass(git_odb_write(&id2
, db
, &zero_obj
));
478 must_be_true(git_oid_cmp(&id1
, &id2
) == 0);
479 must_pass(check_object_files(&zero
));
481 must_pass(git_odb__read_loose(&obj
, db
, &id1
));
482 must_pass(cmp_objects(&obj
, &zero_obj
));
486 must_pass(remove_object_files(&zero
));
489 BEGIN_TEST(write_one
)
494 must_pass(make_odb_dir());
495 must_pass(git_odb_open(&db
, odb_dir
));
496 must_pass(git_oid_mkstr(&id1
, one
.id
));
498 must_pass(git_odb_write(&id2
, db
, &one_obj
));
499 must_be_true(git_oid_cmp(&id1
, &id2
) == 0);
500 must_pass(check_object_files(&one
));
502 must_pass(git_odb__read_loose(&obj
, db
, &id1
));
503 must_pass(cmp_objects(&obj
, &one_obj
));
507 must_pass(remove_object_files(&one
));
510 BEGIN_TEST(write_two
)
515 must_pass(make_odb_dir());
516 must_pass(git_odb_open(&db
, odb_dir
));
517 must_pass(git_oid_mkstr(&id1
, two
.id
));
519 must_pass(git_odb_write(&id2
, db
, &two_obj
));
520 must_be_true(git_oid_cmp(&id1
, &id2
) == 0);
521 must_pass(check_object_files(&two
));
523 must_pass(git_odb__read_loose(&obj
, db
, &id1
));
524 must_pass(cmp_objects(&obj
, &two_obj
));
528 must_pass(remove_object_files(&two
));
531 BEGIN_TEST(write_some
)
536 must_pass(make_odb_dir());
537 must_pass(git_odb_open(&db
, odb_dir
));
538 must_pass(git_oid_mkstr(&id1
, some
.id
));
540 must_pass(git_odb_write(&id2
, db
, &some_obj
));
541 must_be_true(git_oid_cmp(&id1
, &id2
) == 0);
542 must_pass(check_object_files(&some
));
544 must_pass(git_odb__read_loose(&obj
, db
, &id1
));
545 must_pass(cmp_objects(&obj
, &some_obj
));
549 must_pass(remove_object_files(&some
));