]>
Commit | Line | Data |
---|---|---|
64413630 | 1 | #include "builtin.h" |
bad50dc8 | 2 | #include "cache.h" |
74536958 | 3 | #include "object.h" |
8ee378a0 | 4 | #include "delta.h" |
a733cb60 | 5 | #include "pack.h" |
8e440259 PE |
6 | #include "blob.h" |
7 | #include "commit.h" | |
8 | #include "tag.h" | |
9 | #include "tree.h" | |
b41860bf | 10 | #include "tree-walk.h" |
96a02f8f | 11 | #include "progress.h" |
2add1e6d | 12 | #include "decorate.h" |
b41860bf | 13 | #include "fsck.h" |
bad50dc8 | 14 | |
b41860bf | 15 | static int dry_run, quiet, recover, has_errors, strict; |
f18d244a | 16 | static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict] < pack-file"; |
bad50dc8 | 17 | |
67e5a5ec LT |
18 | /* We always read in 4kB chunks. */ |
19 | static unsigned char buffer[4096]; | |
d7dd0223 NP |
20 | static unsigned int offset, len; |
21 | static off_t consumed_bytes; | |
9126f009 | 22 | static git_SHA_CTX ctx; |
bad50dc8 | 23 | |
f2898cfa JH |
24 | /* |
25 | * When running under --strict mode, objects whose reachability are | |
26 | * suspect are kept in core without getting written in the object | |
27 | * store. | |
28 | */ | |
2add1e6d MK |
29 | struct obj_buffer { |
30 | char *buffer; | |
31 | unsigned long size; | |
32 | }; | |
33 | ||
34 | static struct decoration obj_decorate; | |
35 | ||
36 | static struct obj_buffer *lookup_object_buffer(struct object *base) | |
37 | { | |
38 | return lookup_decoration(&obj_decorate, base); | |
39 | } | |
40 | ||
b41860bf MK |
41 | static void add_object_buffer(struct object *object, char *buffer, unsigned long size) |
42 | { | |
43 | struct obj_buffer *obj; | |
44 | obj = xcalloc(1, sizeof(struct obj_buffer)); | |
45 | obj->buffer = buffer; | |
46 | obj->size = size; | |
47 | if (add_decoration(&obj_decorate, object, obj)) | |
48 | die("object %s tried to add buffer twice!", sha1_to_hex(object->sha1)); | |
49 | } | |
50 | ||
67e5a5ec LT |
51 | /* |
52 | * Make sure at least "min" bytes are available in the buffer, and | |
53 | * return the pointer to the buffer. | |
54 | */ | |
79a65697 | 55 | static void *fill(int min) |
67e5a5ec LT |
56 | { |
57 | if (min <= len) | |
58 | return buffer + offset; | |
67e5a5ec LT |
59 | if (min > sizeof(buffer)) |
60 | die("cannot fill %d bytes", min); | |
61 | if (offset) { | |
9126f009 | 62 | git_SHA1_Update(&ctx, buffer, offset); |
79a65697 | 63 | memmove(buffer, buffer + offset, len); |
67e5a5ec LT |
64 | offset = 0; |
65 | } | |
66 | do { | |
8a912bcb | 67 | ssize_t ret = xread(0, buffer + len, sizeof(buffer) - len); |
67e5a5ec LT |
68 | if (ret <= 0) { |
69 | if (!ret) | |
70 | die("early EOF"); | |
67e5a5ec LT |
71 | die("read error on input: %s", strerror(errno)); |
72 | } | |
73 | len += ret; | |
74 | } while (len < min); | |
75 | return buffer; | |
76 | } | |
74536958 | 77 | |
67e5a5ec LT |
78 | static void use(int bytes) |
79 | { | |
80 | if (bytes > len) | |
81 | die("used more bytes than were available"); | |
82 | len -= bytes; | |
83 | offset += bytes; | |
d7dd0223 NP |
84 | |
85 | /* make sure off_t is sufficiently large not to wrap */ | |
86 | if (consumed_bytes > consumed_bytes + bytes) | |
87 | die("pack too large for current definition of off_t"); | |
209c554a | 88 | consumed_bytes += bytes; |
67e5a5ec | 89 | } |
bad50dc8 | 90 | |
67e5a5ec | 91 | static void *get_data(unsigned long size) |
bad50dc8 | 92 | { |
67e5a5ec LT |
93 | z_stream stream; |
94 | void *buf = xmalloc(size); | |
95 | ||
67e5a5ec LT |
96 | memset(&stream, 0, sizeof(stream)); |
97 | ||
98 | stream.next_out = buf; | |
99 | stream.avail_out = size; | |
100 | stream.next_in = fill(1); | |
101 | stream.avail_in = len; | |
39c68542 | 102 | git_inflate_init(&stream); |
67e5a5ec LT |
103 | |
104 | for (;;) { | |
39c68542 | 105 | int ret = git_inflate(&stream, 0); |
67e5a5ec LT |
106 | use(len - stream.avail_in); |
107 | if (stream.total_out == size && ret == Z_STREAM_END) | |
108 | break; | |
f986f2c8 JH |
109 | if (ret != Z_OK) { |
110 | error("inflate returned %d\n", ret); | |
111 | free(buf); | |
112 | buf = NULL; | |
3b67d291 | 113 | if (!recover) |
f986f2c8 JH |
114 | exit(1); |
115 | has_errors = 1; | |
116 | break; | |
117 | } | |
67e5a5ec LT |
118 | stream.next_in = fill(1); |
119 | stream.avail_in = len; | |
120 | } | |
39c68542 | 121 | git_inflate_end(&stream); |
67e5a5ec | 122 | return buf; |
bad50dc8 LT |
123 | } |
124 | ||
67e5a5ec LT |
125 | struct delta_info { |
126 | unsigned char base_sha1[20]; | |
d7dd0223 NP |
127 | unsigned nr; |
128 | off_t base_offset; | |
67e5a5ec LT |
129 | unsigned long size; |
130 | void *delta; | |
131 | struct delta_info *next; | |
132 | }; | |
133 | ||
134 | static struct delta_info *delta_list; | |
135 | ||
209c554a | 136 | static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1, |
d7dd0223 | 137 | off_t base_offset, |
209c554a | 138 | void *delta, unsigned long size) |
bad50dc8 | 139 | { |
67e5a5ec | 140 | struct delta_info *info = xmalloc(sizeof(*info)); |
bad50dc8 | 141 | |
e702496e | 142 | hashcpy(info->base_sha1, base_sha1); |
209c554a | 143 | info->base_offset = base_offset; |
67e5a5ec LT |
144 | info->size = size; |
145 | info->delta = delta; | |
209c554a | 146 | info->nr = nr; |
67e5a5ec LT |
147 | info->next = delta_list; |
148 | delta_list = info; | |
bad50dc8 LT |
149 | } |
150 | ||
209c554a | 151 | struct obj_info { |
d7dd0223 | 152 | off_t offset; |
209c554a | 153 | unsigned char sha1[20]; |
b41860bf | 154 | struct object *obj; |
209c554a NP |
155 | }; |
156 | ||
b41860bf MK |
157 | #define FLAG_OPEN (1u<<20) |
158 | #define FLAG_WRITTEN (1u<<21) | |
159 | ||
209c554a | 160 | static struct obj_info *obj_list; |
b41860bf MK |
161 | unsigned nr_objects; |
162 | ||
f2898cfa JH |
163 | /* |
164 | * Called only from check_object() after it verified this object | |
165 | * is Ok. | |
166 | */ | |
b41860bf MK |
167 | static void write_cached_object(struct object *obj) |
168 | { | |
169 | unsigned char sha1[20]; | |
170 | struct obj_buffer *obj_buf = lookup_object_buffer(obj); | |
171 | if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0) | |
172 | die("failed to write object %s", sha1_to_hex(obj->sha1)); | |
173 | obj->flags |= FLAG_WRITTEN; | |
174 | } | |
175 | ||
f2898cfa JH |
176 | /* |
177 | * At the very end of the processing, write_rest() scans the objects | |
178 | * that have reachability requirements and calls this function. | |
179 | * Verify its reachability and validity recursively and write it out. | |
180 | */ | |
b41860bf MK |
181 | static int check_object(struct object *obj, int type, void *data) |
182 | { | |
183 | if (!obj) | |
184 | return 0; | |
185 | ||
186 | if (obj->flags & FLAG_WRITTEN) | |
187 | return 1; | |
188 | ||
189 | if (type != OBJ_ANY && obj->type != type) | |
190 | die("object type mismatch"); | |
191 | ||
192 | if (!(obj->flags & FLAG_OPEN)) { | |
193 | unsigned long size; | |
194 | int type = sha1_object_info(obj->sha1, &size); | |
195 | if (type != obj->type || type <= 0) | |
196 | die("object of unexpected type"); | |
197 | obj->flags |= FLAG_WRITTEN; | |
198 | return 1; | |
199 | } | |
200 | ||
201 | if (fsck_object(obj, 1, fsck_error_function)) | |
202 | die("Error in object"); | |
203 | if (!fsck_walk(obj, check_object, 0)) | |
204 | die("Error on reachable objects of %s", sha1_to_hex(obj->sha1)); | |
205 | write_cached_object(obj); | |
206 | return 1; | |
207 | } | |
208 | ||
209 | static void write_rest(void) | |
210 | { | |
211 | unsigned i; | |
212 | for (i = 0; i < nr_objects; i++) | |
213 | check_object(obj_list[i].obj, OBJ_ANY, 0); | |
214 | } | |
67e5a5ec | 215 | |
21666f1a NP |
216 | static void added_object(unsigned nr, enum object_type type, |
217 | void *data, unsigned long size); | |
209c554a | 218 | |
f2898cfa JH |
219 | /* |
220 | * Write out nr-th object from the list, now we know the contents | |
221 | * of it. Under --strict, this buffers structured objects in-core, | |
222 | * to be checked at the end. | |
223 | */ | |
21666f1a NP |
224 | static void write_object(unsigned nr, enum object_type type, |
225 | void *buf, unsigned long size) | |
cca7081a | 226 | { |
b41860bf MK |
227 | if (!strict) { |
228 | if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0) | |
229 | die("failed to write object"); | |
f2898cfa | 230 | added_object(nr, type, buf, size); |
b41860bf | 231 | free(buf); |
f2898cfa | 232 | obj_list[nr].obj = NULL; |
b41860bf MK |
233 | } else if (type == OBJ_BLOB) { |
234 | struct blob *blob; | |
235 | if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0) | |
236 | die("failed to write object"); | |
f2898cfa | 237 | added_object(nr, type, buf, size); |
b41860bf MK |
238 | free(buf); |
239 | ||
240 | blob = lookup_blob(obj_list[nr].sha1); | |
241 | if (blob) | |
242 | blob->object.flags |= FLAG_WRITTEN; | |
243 | else | |
244 | die("invalid blob object"); | |
f2898cfa | 245 | obj_list[nr].obj = NULL; |
b41860bf MK |
246 | } else { |
247 | struct object *obj; | |
248 | int eaten; | |
249 | hash_sha1_file(buf, size, typename(type), obj_list[nr].sha1); | |
f2898cfa | 250 | added_object(nr, type, buf, size); |
b41860bf MK |
251 | obj = parse_object_buffer(obj_list[nr].sha1, type, size, buf, &eaten); |
252 | if (!obj) | |
253 | die("invalid %s", typename(type)); | |
b41860bf MK |
254 | add_object_buffer(obj, buf, size); |
255 | obj->flags |= FLAG_OPEN; | |
256 | obj_list[nr].obj = obj; | |
257 | } | |
cca7081a LT |
258 | } |
259 | ||
21666f1a | 260 | static void resolve_delta(unsigned nr, enum object_type type, |
f986f2c8 JH |
261 | void *base, unsigned long base_size, |
262 | void *delta, unsigned long delta_size) | |
bad50dc8 | 263 | { |
67e5a5ec LT |
264 | void *result; |
265 | unsigned long result_size; | |
bad50dc8 | 266 | |
67e5a5ec LT |
267 | result = patch_delta(base, base_size, |
268 | delta, delta_size, | |
269 | &result_size); | |
270 | if (!result) | |
271 | die("failed to apply delta"); | |
272 | free(delta); | |
21666f1a | 273 | write_object(nr, type, result, result_size); |
bad50dc8 LT |
274 | } |
275 | ||
f2898cfa JH |
276 | /* |
277 | * We now know the contents of an object (which is nr-th in the pack); | |
278 | * resolve all the deltified objects that are based on it. | |
279 | */ | |
21666f1a NP |
280 | static void added_object(unsigned nr, enum object_type type, |
281 | void *data, unsigned long size) | |
74536958 | 282 | { |
67e5a5ec LT |
283 | struct delta_info **p = &delta_list; |
284 | struct delta_info *info; | |
285 | ||
286 | while ((info = *p) != NULL) { | |
209c554a NP |
287 | if (!hashcmp(info->base_sha1, obj_list[nr].sha1) || |
288 | info->base_offset == obj_list[nr].offset) { | |
67e5a5ec LT |
289 | *p = info->next; |
290 | p = &delta_list; | |
209c554a NP |
291 | resolve_delta(info->nr, type, data, size, |
292 | info->delta, info->size); | |
67e5a5ec LT |
293 | free(info); |
294 | continue; | |
295 | } | |
296 | p = &info->next; | |
297 | } | |
298 | } | |
299 | ||
21666f1a | 300 | static void unpack_non_delta_entry(enum object_type type, unsigned long size, |
209c554a | 301 | unsigned nr) |
67e5a5ec LT |
302 | { |
303 | void *buf = get_data(size); | |
8ee378a0 | 304 | |
f986f2c8 | 305 | if (!dry_run && buf) |
21666f1a | 306 | write_object(nr, type, buf, size); |
b41860bf MK |
307 | else |
308 | free(buf); | |
8ee378a0 JH |
309 | } |
310 | ||
f2898cfa JH |
311 | static int resolve_against_held(unsigned nr, const unsigned char *base, |
312 | void *delta_data, unsigned long delta_size) | |
313 | { | |
314 | struct object *obj; | |
315 | struct obj_buffer *obj_buffer; | |
316 | obj = lookup_object(base); | |
317 | if (!obj) | |
318 | return 0; | |
319 | obj_buffer = lookup_object_buffer(obj); | |
320 | if (!obj_buffer) | |
321 | return 0; | |
322 | resolve_delta(nr, obj->type, obj_buffer->buffer, | |
323 | obj_buffer->size, delta_data, delta_size); | |
324 | return 1; | |
325 | } | |
326 | ||
21666f1a | 327 | static void unpack_delta_entry(enum object_type type, unsigned long delta_size, |
209c554a | 328 | unsigned nr) |
8ee378a0 | 329 | { |
67e5a5ec LT |
330 | void *delta_data, *base; |
331 | unsigned long base_size; | |
67e5a5ec | 332 | unsigned char base_sha1[20]; |
8ee378a0 | 333 | |
21666f1a | 334 | if (type == OBJ_REF_DELTA) { |
209c554a NP |
335 | hashcpy(base_sha1, fill(20)); |
336 | use(20); | |
337 | delta_data = get_data(delta_size); | |
338 | if (dry_run || !delta_data) { | |
339 | free(delta_data); | |
340 | return; | |
341 | } | |
f2898cfa JH |
342 | if (has_sha1_file(base_sha1)) |
343 | ; /* Ok we have this one */ | |
344 | else if (resolve_against_held(nr, base_sha1, | |
345 | delta_data, delta_size)) | |
346 | return; /* we are done */ | |
347 | else { | |
348 | /* cannot resolve yet --- queue it */ | |
209c554a NP |
349 | hashcpy(obj_list[nr].sha1, null_sha1); |
350 | add_delta_to_list(nr, base_sha1, 0, delta_data, delta_size); | |
351 | return; | |
352 | } | |
353 | } else { | |
354 | unsigned base_found = 0; | |
355 | unsigned char *pack, c; | |
d7dd0223 | 356 | off_t base_offset; |
209c554a | 357 | unsigned lo, mid, hi; |
c4fb06c0 | 358 | |
209c554a NP |
359 | pack = fill(1); |
360 | c = *pack; | |
361 | use(1); | |
362 | base_offset = c & 127; | |
363 | while (c & 128) { | |
364 | base_offset += 1; | |
8723f216 | 365 | if (!base_offset || MSB(base_offset, 7)) |
209c554a NP |
366 | die("offset value overflow for delta base object"); |
367 | pack = fill(1); | |
368 | c = *pack; | |
369 | use(1); | |
370 | base_offset = (base_offset << 7) + (c & 127); | |
371 | } | |
372 | base_offset = obj_list[nr].offset - base_offset; | |
d8f32556 NP |
373 | if (base_offset <= 0 || base_offset >= obj_list[nr].offset) |
374 | die("offset value out of bound for delta base object"); | |
8ee378a0 | 375 | |
209c554a NP |
376 | delta_data = get_data(delta_size); |
377 | if (dry_run || !delta_data) { | |
378 | free(delta_data); | |
379 | return; | |
380 | } | |
381 | lo = 0; | |
382 | hi = nr; | |
383 | while (lo < hi) { | |
384 | mid = (lo + hi)/2; | |
385 | if (base_offset < obj_list[mid].offset) { | |
386 | hi = mid; | |
387 | } else if (base_offset > obj_list[mid].offset) { | |
388 | lo = mid + 1; | |
389 | } else { | |
390 | hashcpy(base_sha1, obj_list[mid].sha1); | |
391 | base_found = !is_null_sha1(base_sha1); | |
392 | break; | |
393 | } | |
394 | } | |
395 | if (!base_found) { | |
f2898cfa JH |
396 | /* |
397 | * The delta base object is itself a delta that | |
398 | * has not been resolved yet. | |
399 | */ | |
209c554a NP |
400 | hashcpy(obj_list[nr].sha1, null_sha1); |
401 | add_delta_to_list(nr, null_sha1, base_offset, delta_data, delta_size); | |
402 | return; | |
2add1e6d MK |
403 | } |
404 | } | |
405 | ||
f2898cfa JH |
406 | if (resolve_against_held(nr, base_sha1, delta_data, delta_size)) |
407 | return; | |
209c554a | 408 | |
21666f1a | 409 | base = read_sha1_file(base_sha1, &type, &base_size); |
f986f2c8 JH |
410 | if (!base) { |
411 | error("failed to read delta-pack base object %s", | |
412 | sha1_to_hex(base_sha1)); | |
3b67d291 | 413 | if (!recover) |
f986f2c8 JH |
414 | exit(1); |
415 | has_errors = 1; | |
416 | return; | |
417 | } | |
209c554a | 418 | resolve_delta(nr, type, base, base_size, delta_data, delta_size); |
ee639140 | 419 | free(base); |
8ee378a0 JH |
420 | } |
421 | ||
96a02f8f | 422 | static void unpack_one(unsigned nr) |
8ee378a0 | 423 | { |
01247d87 | 424 | unsigned shift; |
a733cb60 | 425 | unsigned char *pack, c; |
67e5a5ec LT |
426 | unsigned long size; |
427 | enum object_type type; | |
74536958 | 428 | |
209c554a NP |
429 | obj_list[nr].offset = consumed_bytes; |
430 | ||
67e5a5ec LT |
431 | pack = fill(1); |
432 | c = *pack; | |
433 | use(1); | |
a733cb60 LT |
434 | type = (c >> 4) & 7; |
435 | size = (c & 15); | |
01247d87 | 436 | shift = 4; |
a733cb60 | 437 | while (c & 0x80) { |
67e5a5ec | 438 | pack = fill(1); |
209c554a | 439 | c = *pack; |
67e5a5ec | 440 | use(1); |
01247d87 LT |
441 | size += (c & 0x7f) << shift; |
442 | shift += 7; | |
a733cb60 | 443 | } |
96a02f8f | 444 | |
a733cb60 LT |
445 | switch (type) { |
446 | case OBJ_COMMIT: | |
447 | case OBJ_TREE: | |
448 | case OBJ_BLOB: | |
449 | case OBJ_TAG: | |
209c554a | 450 | unpack_non_delta_entry(type, size, nr); |
a733cb60 | 451 | return; |
eb32d236 | 452 | case OBJ_REF_DELTA: |
209c554a NP |
453 | case OBJ_OFS_DELTA: |
454 | unpack_delta_entry(type, size, nr); | |
a733cb60 | 455 | return; |
67e5a5ec | 456 | default: |
f986f2c8 JH |
457 | error("bad object type %d", type); |
458 | has_errors = 1; | |
3b67d291 | 459 | if (recover) |
f986f2c8 JH |
460 | return; |
461 | exit(1); | |
74536958 LT |
462 | } |
463 | } | |
464 | ||
74536958 LT |
465 | static void unpack_all(void) |
466 | { | |
67e5a5ec | 467 | int i; |
dc6a0757 | 468 | struct progress *progress = NULL; |
67e5a5ec | 469 | struct pack_header *hdr = fill(sizeof(struct pack_header)); |
b41860bf MK |
470 | |
471 | nr_objects = ntohl(hdr->hdr_entries); | |
67e5a5ec LT |
472 | |
473 | if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE) | |
474 | die("bad pack file"); | |
d60fc1c8 | 475 | if (!pack_version_ok(hdr->hdr_version)) |
6e1c2344 RJ |
476 | die("unknown pack file version %"PRIu32, |
477 | ntohl(hdr->hdr_version)); | |
96a02f8f | 478 | use(sizeof(struct pack_header)); |
67e5a5ec | 479 | |
13aaf148 | 480 | if (!quiet) |
dc6a0757 | 481 | progress = start_progress("Unpacking objects", nr_objects); |
19d4b416 | 482 | obj_list = xcalloc(nr_objects, sizeof(*obj_list)); |
96a02f8f NP |
483 | for (i = 0; i < nr_objects; i++) { |
484 | unpack_one(i); | |
4d4fcc54 | 485 | display_progress(progress, i + 1); |
96a02f8f | 486 | } |
4d4fcc54 | 487 | stop_progress(&progress); |
96a02f8f | 488 | |
67e5a5ec LT |
489 | if (delta_list) |
490 | die("unresolved deltas left after unpacking"); | |
74536958 LT |
491 | } |
492 | ||
64413630 | 493 | int cmd_unpack_objects(int argc, const char **argv, const char *prefix) |
bad50dc8 LT |
494 | { |
495 | int i; | |
67e5a5ec | 496 | unsigned char sha1[20]; |
bad50dc8 | 497 | |
ef90d6d4 | 498 | git_config(git_default_config, NULL); |
53228a5f | 499 | |
476e8011 JH |
500 | quiet = !isatty(2); |
501 | ||
bad50dc8 LT |
502 | for (i = 1 ; i < argc; i++) { |
503 | const char *arg = argv[i]; | |
504 | ||
505 | if (*arg == '-') { | |
74536958 LT |
506 | if (!strcmp(arg, "-n")) { |
507 | dry_run = 1; | |
508 | continue; | |
509 | } | |
d36f7b80 LT |
510 | if (!strcmp(arg, "-q")) { |
511 | quiet = 1; | |
512 | continue; | |
513 | } | |
f986f2c8 | 514 | if (!strcmp(arg, "-r")) { |
3b67d291 | 515 | recover = 1; |
f986f2c8 JH |
516 | continue; |
517 | } | |
b41860bf MK |
518 | if (!strcmp(arg, "--strict")) { |
519 | strict = 1; | |
520 | continue; | |
521 | } | |
cc44c765 | 522 | if (!prefixcmp(arg, "--pack_header=")) { |
bed006fb NP |
523 | struct pack_header *hdr; |
524 | char *c; | |
525 | ||
526 | hdr = (struct pack_header *)buffer; | |
527 | hdr->hdr_signature = htonl(PACK_SIGNATURE); | |
528 | hdr->hdr_version = htonl(strtoul(arg + 14, &c, 10)); | |
529 | if (*c != ',') | |
530 | die("bad %s", arg); | |
531 | hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10)); | |
532 | if (*c) | |
533 | die("bad %s", arg); | |
534 | len = sizeof(*hdr); | |
535 | continue; | |
536 | } | |
bad50dc8 LT |
537 | usage(unpack_usage); |
538 | } | |
67e5a5ec LT |
539 | |
540 | /* We don't take any non-flag arguments now.. Maybe some day */ | |
bad50dc8 | 541 | usage(unpack_usage); |
67e5a5ec | 542 | } |
9126f009 | 543 | git_SHA1_Init(&ctx); |
74536958 | 544 | unpack_all(); |
9126f009 NP |
545 | git_SHA1_Update(&ctx, buffer, offset); |
546 | git_SHA1_Final(sha1, &ctx); | |
b41860bf MK |
547 | if (strict) |
548 | write_rest(); | |
a89fccd2 | 549 | if (hashcmp(fill(20), sha1)) |
67e5a5ec LT |
550 | die("final sha1 did not match"); |
551 | use(20); | |
552 | ||
553 | /* Write the last part of the buffer to stdout */ | |
554 | while (len) { | |
1c15afb9 JH |
555 | int ret = xwrite(1, buffer + offset, len); |
556 | if (ret <= 0) | |
67e5a5ec | 557 | break; |
67e5a5ec LT |
558 | len -= ret; |
559 | offset += ret; | |
560 | } | |
561 | ||
562 | /* All done */ | |
f986f2c8 | 563 | return has_errors; |
bad50dc8 | 564 | } |