]>
git.ipfire.org Git - thirdparty/git.git/blob - index-pack.c
12 static const char index_pack_usage
[] =
13 "git-index-pack [-v] [-o <index-file>] { <pack-file> | --stdin [--fix-thin] [<pack-file>] }";
19 unsigned int hdr_size
;
20 enum object_type type
;
21 enum object_type real_type
;
22 unsigned char sha1
[20];
26 unsigned char sha1
[20];
31 * Even if sizeof(union delta_base) == 24 on 64-bit archs, we really want
32 * to memcmp() only the first 20 bytes.
34 #define UNION_BASE_SZ 20
38 union delta_base base
;
42 static struct object_entry
*objects
;
43 static struct delta_entry
*deltas
;
44 static int nr_objects
;
46 static int nr_resolved_deltas
;
48 static int from_stdin
;
51 static volatile sig_atomic_t progress_update
;
53 static void progress_interval(int signum
)
58 static void setup_progress_signal(void)
63 memset(&sa
, 0, sizeof(sa
));
64 sa
.sa_handler
= progress_interval
;
65 sigemptyset(&sa
.sa_mask
);
66 sa
.sa_flags
= SA_RESTART
;
67 sigaction(SIGALRM
, &sa
, NULL
);
69 v
.it_interval
.tv_sec
= 1;
70 v
.it_interval
.tv_usec
= 0;
71 v
.it_value
= v
.it_interval
;
72 setitimer(ITIMER_REAL
, &v
, NULL
);
76 static unsigned display_progress(unsigned n
, unsigned total
, unsigned last_pc
)
78 unsigned percent
= n
* 100 / total
;
79 if (percent
!= last_pc
|| progress_update
) {
80 fprintf(stderr
, "%4u%% (%u/%u) done\r", percent
, n
, total
);
86 /* We always read in 4kB chunks. */
87 static unsigned char input_buffer
[4096];
88 static unsigned long input_offset
, input_len
, consumed_bytes
;
89 static SHA_CTX input_ctx
;
90 static int input_fd
, output_fd
, mmap_fd
;
92 /* Discard current buffer used content. */
97 write_or_die(output_fd
, input_buffer
, input_offset
);
98 SHA1_Update(&input_ctx
, input_buffer
, input_offset
);
99 memcpy(input_buffer
, input_buffer
+ input_offset
, input_len
);
105 * Make sure at least "min" bytes are available in the buffer, and
106 * return the pointer to the buffer.
108 static void * fill(int min
)
110 if (min
<= input_len
)
111 return input_buffer
+ input_offset
;
112 if (min
> sizeof(input_buffer
))
113 die("cannot fill %d bytes", min
);
116 int ret
= xread(input_fd
, input_buffer
+ input_len
,
117 sizeof(input_buffer
) - input_len
);
121 die("read error on input: %s", strerror(errno
));
124 } while (input_len
< min
);
128 static void use(int bytes
)
130 if (bytes
> input_len
)
131 die("used more bytes than were available");
133 input_offset
+= bytes
;
134 consumed_bytes
+= bytes
;
137 static const char * open_pack_file(const char *pack_name
)
142 static char tmpfile
[PATH_MAX
];
143 snprintf(tmpfile
, sizeof(tmpfile
),
144 "%s/pack_XXXXXX", get_object_directory());
145 output_fd
= mkstemp(tmpfile
);
146 pack_name
= xstrdup(tmpfile
);
148 output_fd
= open(pack_name
, O_CREAT
|O_EXCL
|O_RDWR
, 0600);
150 die("unable to create %s: %s\n", pack_name
, strerror(errno
));
153 input_fd
= open(pack_name
, O_RDONLY
);
155 die("cannot open packfile '%s': %s",
156 pack_name
, strerror(errno
));
160 SHA1_Init(&input_ctx
);
164 static void parse_pack_header(void)
166 struct pack_header
*hdr
= fill(sizeof(struct pack_header
));
168 /* Header consistency check */
169 if (hdr
->hdr_signature
!= htonl(PACK_SIGNATURE
))
170 die("pack signature mismatch");
171 if (!pack_version_ok(hdr
->hdr_version
))
172 die("pack version %d unsupported", ntohl(hdr
->hdr_version
));
174 nr_objects
= ntohl(hdr
->hdr_entries
);
175 use(sizeof(struct pack_header
));
178 static void bad_object(unsigned long offset
, const char *format
,
179 ...) NORETURN
__attribute__((format (printf
, 2, 3)));
181 static void bad_object(unsigned long offset
, const char *format
, ...)
186 va_start(params
, format
);
187 vsnprintf(buf
, sizeof(buf
), format
, params
);
189 die("pack has bad object at offset %lu: %s", offset
, buf
);
192 static void *unpack_entry_data(unsigned long offset
, unsigned long size
)
195 void *buf
= xmalloc(size
);
197 memset(&stream
, 0, sizeof(stream
));
198 stream
.next_out
= buf
;
199 stream
.avail_out
= size
;
200 stream
.next_in
= fill(1);
201 stream
.avail_in
= input_len
;
202 inflateInit(&stream
);
205 int ret
= inflate(&stream
, 0);
206 use(input_len
- stream
.avail_in
);
207 if (stream
.total_out
== size
&& ret
== Z_STREAM_END
)
210 bad_object(offset
, "inflate returned %d", ret
);
211 stream
.next_in
= fill(1);
212 stream
.avail_in
= input_len
;
218 static void *unpack_raw_entry(struct object_entry
*obj
, union delta_base
*delta_base
)
221 unsigned long size
, base_offset
;
224 obj
->offset
= consumed_bytes
;
229 obj
->type
= (c
>> 4) & 7;
236 size
+= (c
& 0x7fUL
) << shift
;
243 hashcpy(delta_base
->sha1
, fill(20));
247 memset(delta_base
, 0, sizeof(*delta_base
));
251 base_offset
= c
& 127;
254 if (!base_offset
|| base_offset
& ~(~0UL >> 7))
255 bad_object(obj
->offset
, "offset value overflow for delta base object");
259 base_offset
= (base_offset
<< 7) + (c
& 127);
261 delta_base
->offset
= obj
->offset
- base_offset
;
262 if (delta_base
->offset
>= obj
->offset
)
263 bad_object(obj
->offset
, "delta base offset is out of bound");
271 bad_object(obj
->offset
, "bad object type %d", obj
->type
);
273 obj
->hdr_size
= consumed_bytes
- obj
->offset
;
275 return unpack_entry_data(obj
->offset
, obj
->size
);
278 static void * get_data_from_pack(struct object_entry
*obj
)
280 unsigned long from
= obj
[0].offset
+ obj
[0].hdr_size
;
281 unsigned long len
= obj
[1].offset
- from
;
282 unsigned pg_offset
= from
% getpagesize();
283 unsigned char *map
, *data
;
287 map
= mmap(NULL
, len
+ pg_offset
, PROT_READ
, MAP_PRIVATE
,
288 mmap_fd
, from
- pg_offset
);
289 if (map
== MAP_FAILED
)
290 die("cannot mmap pack file: %s", strerror(errno
));
291 data
= xmalloc(obj
->size
);
292 memset(&stream
, 0, sizeof(stream
));
293 stream
.next_out
= data
;
294 stream
.avail_out
= obj
->size
;
295 stream
.next_in
= map
+ pg_offset
;
296 stream
.avail_in
= len
;
297 inflateInit(&stream
);
298 while ((st
= inflate(&stream
, Z_FINISH
)) == Z_OK
);
300 if (st
!= Z_STREAM_END
|| stream
.total_out
!= obj
->size
)
301 die("serious inflate inconsistency");
302 munmap(map
, len
+ pg_offset
);
306 static int find_delta(const union delta_base
*base
)
308 int first
= 0, last
= nr_deltas
;
310 while (first
< last
) {
311 int next
= (first
+ last
) / 2;
312 struct delta_entry
*delta
= &deltas
[next
];
315 cmp
= memcmp(base
, &delta
->base
, UNION_BASE_SZ
);
327 static int find_delta_childs(const union delta_base
*base
,
328 int *first_index
, int *last_index
)
330 int first
= find_delta(base
);
332 int end
= nr_deltas
- 1;
336 while (first
> 0 && !memcmp(&deltas
[first
- 1].base
, base
, UNION_BASE_SZ
))
338 while (last
< end
&& !memcmp(&deltas
[last
+ 1].base
, base
, UNION_BASE_SZ
))
340 *first_index
= first
;
345 static void sha1_object(const void *data
, unsigned long size
,
346 enum object_type type
, unsigned char *sha1
)
351 const char *type_str
;
354 case OBJ_COMMIT
: type_str
= commit_type
; break;
355 case OBJ_TREE
: type_str
= tree_type
; break;
356 case OBJ_BLOB
: type_str
= blob_type
; break;
357 case OBJ_TAG
: type_str
= tag_type
; break;
359 die("bad type %d", type
);
362 header_size
= sprintf(header
, "%s %lu", type_str
, size
) + 1;
365 SHA1_Update(&ctx
, header
, header_size
);
366 SHA1_Update(&ctx
, data
, size
);
367 SHA1_Final(sha1
, &ctx
);
370 static void resolve_delta(struct object_entry
*delta_obj
, void *base_data
,
371 unsigned long base_size
, enum object_type type
)
374 unsigned long delta_size
;
376 unsigned long result_size
;
377 union delta_base delta_base
;
380 delta_obj
->real_type
= type
;
381 delta_data
= get_data_from_pack(delta_obj
);
382 delta_size
= delta_obj
->size
;
383 result
= patch_delta(base_data
, base_size
, delta_data
, delta_size
,
387 bad_object(delta_obj
->offset
, "failed to apply delta");
388 sha1_object(result
, result_size
, type
, delta_obj
->sha1
);
389 nr_resolved_deltas
++;
391 hashcpy(delta_base
.sha1
, delta_obj
->sha1
);
392 if (!find_delta_childs(&delta_base
, &first
, &last
)) {
393 for (j
= first
; j
<= last
; j
++) {
394 struct object_entry
*child
= objects
+ deltas
[j
].obj_no
;
395 if (child
->real_type
== OBJ_REF_DELTA
)
396 resolve_delta(child
, result
, result_size
, type
);
400 memset(&delta_base
, 0, sizeof(delta_base
));
401 delta_base
.offset
= delta_obj
->offset
;
402 if (!find_delta_childs(&delta_base
, &first
, &last
)) {
403 for (j
= first
; j
<= last
; j
++) {
404 struct object_entry
*child
= objects
+ deltas
[j
].obj_no
;
405 if (child
->real_type
== OBJ_OFS_DELTA
)
406 resolve_delta(child
, result
, result_size
, type
);
413 static int compare_delta_entry(const void *a
, const void *b
)
415 const struct delta_entry
*delta_a
= a
;
416 const struct delta_entry
*delta_b
= b
;
417 return memcmp(&delta_a
->base
, &delta_b
->base
, UNION_BASE_SZ
);
420 /* Parse all objects and return the pack content SHA1 hash */
421 static void parse_pack_objects(unsigned char *sha1
)
424 struct delta_entry
*delta
= deltas
;
430 * - find locations of all objects;
431 * - calculate SHA1 of all non-delta objects;
432 * - remember base SHA1 for all deltas.
435 fprintf(stderr
, "Indexing %d objects.\n", nr_objects
);
436 for (i
= 0; i
< nr_objects
; i
++) {
437 struct object_entry
*obj
= &objects
[i
];
438 data
= unpack_raw_entry(obj
, &delta
->base
);
439 obj
->real_type
= obj
->type
;
440 if (obj
->type
== OBJ_REF_DELTA
|| obj
->type
== OBJ_OFS_DELTA
) {
445 sha1_object(data
, obj
->size
, obj
->type
, obj
->sha1
);
448 percent
= display_progress(i
+1, nr_objects
, percent
);
450 objects
[i
].offset
= consumed_bytes
;
454 /* Check pack integrity */
456 SHA1_Final(sha1
, &input_ctx
);
457 if (hashcmp(fill(20), sha1
))
458 die("pack is corrupted (SHA1 mismatch)");
460 /* If input_fd is a file, we should have reached its end now. */
461 if (fstat(input_fd
, &st
))
462 die("cannot fstat packfile: %s", strerror(errno
));
463 if (S_ISREG(st
.st_mode
) && st
.st_size
!= consumed_bytes
+ 20)
464 die("pack has junk at the end");
469 /* Sort deltas by base SHA1/offset for fast searching */
470 qsort(deltas
, nr_deltas
, sizeof(struct delta_entry
),
471 compare_delta_entry
);
475 * - for all non-delta objects, look if it is used as a base for
477 * - if used as a base, uncompress the object and apply all deltas,
478 * recursively checking if the resulting object is used as a base
479 * for some more deltas.
482 fprintf(stderr
, "Resolving %d deltas.\n", nr_deltas
);
483 for (i
= 0; i
< nr_objects
; i
++) {
484 struct object_entry
*obj
= &objects
[i
];
485 union delta_base base
;
486 int j
, ref
, ref_first
, ref_last
, ofs
, ofs_first
, ofs_last
;
488 if (obj
->type
== OBJ_REF_DELTA
|| obj
->type
== OBJ_OFS_DELTA
)
490 hashcpy(base
.sha1
, obj
->sha1
);
491 ref
= !find_delta_childs(&base
, &ref_first
, &ref_last
);
492 memset(&base
, 0, sizeof(base
));
493 base
.offset
= obj
->offset
;
494 ofs
= !find_delta_childs(&base
, &ofs_first
, &ofs_last
);
497 data
= get_data_from_pack(obj
);
499 for (j
= ref_first
; j
<= ref_last
; j
++) {
500 struct object_entry
*child
= objects
+ deltas
[j
].obj_no
;
501 if (child
->real_type
== OBJ_REF_DELTA
)
502 resolve_delta(child
, data
,
503 obj
->size
, obj
->type
);
506 for (j
= ofs_first
; j
<= ofs_last
; j
++) {
507 struct object_entry
*child
= objects
+ deltas
[j
].obj_no
;
508 if (child
->real_type
== OBJ_OFS_DELTA
)
509 resolve_delta(child
, data
,
510 obj
->size
, obj
->type
);
514 percent
= display_progress(nr_resolved_deltas
,
517 if (verbose
&& nr_resolved_deltas
== nr_deltas
)
521 static int write_compressed(int fd
, void *in
, unsigned int size
)
524 unsigned long maxsize
;
527 memset(&stream
, 0, sizeof(stream
));
528 deflateInit(&stream
, zlib_compression_level
);
529 maxsize
= deflateBound(&stream
, size
);
530 out
= xmalloc(maxsize
);
534 stream
.avail_in
= size
;
535 stream
.next_out
= out
;
536 stream
.avail_out
= maxsize
;
537 while (deflate(&stream
, Z_FINISH
) == Z_OK
);
540 size
= stream
.total_out
;
541 write_or_die(fd
, out
, size
);
546 static void append_obj_to_pack(void *buf
,
547 unsigned long size
, enum object_type type
)
549 struct object_entry
*obj
= &objects
[nr_objects
++];
550 unsigned char header
[10];
551 unsigned long s
= size
;
553 unsigned char c
= (type
<< 4) | (s
& 15);
556 header
[n
++] = c
| 0x80;
561 write_or_die(output_fd
, header
, n
);
562 obj
[1].offset
= obj
[0].offset
+ n
;
563 obj
[1].offset
+= write_compressed(output_fd
, buf
, size
);
564 sha1_object(buf
, size
, type
, obj
->sha1
);
567 static int delta_pos_compare(const void *_a
, const void *_b
)
569 struct delta_entry
*a
= *(struct delta_entry
**)_a
;
570 struct delta_entry
*b
= *(struct delta_entry
**)_b
;
571 return a
->obj_no
- b
->obj_no
;
574 static void fix_unresolved_deltas(int nr_unresolved
)
576 struct delta_entry
**sorted_by_pos
;
577 int i
, n
= 0, percent
= -1;
580 * Since many unresolved deltas may well be themselves base objects
581 * for more unresolved deltas, we really want to include the
582 * smallest number of base objects that would cover as much delta
583 * as possible by picking the
584 * trunc deltas first, allowing for other deltas to resolve without
585 * additional base objects. Since most base objects are to be found
586 * before deltas depending on them, a good heuristic is to start
587 * resolving deltas in the same order as their position in the pack.
589 sorted_by_pos
= xmalloc(nr_unresolved
* sizeof(*sorted_by_pos
));
590 for (i
= 0; i
< nr_deltas
; i
++) {
591 if (objects
[deltas
[i
].obj_no
].real_type
!= OBJ_REF_DELTA
)
593 sorted_by_pos
[n
++] = &deltas
[i
];
595 qsort(sorted_by_pos
, n
, sizeof(*sorted_by_pos
), delta_pos_compare
);
597 for (i
= 0; i
< n
; i
++) {
598 struct delta_entry
*d
= sorted_by_pos
[i
];
602 enum object_type obj_type
;
605 if (objects
[d
->obj_no
].real_type
!= OBJ_REF_DELTA
)
607 data
= read_sha1_file(d
->base
.sha1
, type
, &size
);
610 if (!strcmp(type
, blob_type
)) obj_type
= OBJ_BLOB
;
611 else if (!strcmp(type
, tree_type
)) obj_type
= OBJ_TREE
;
612 else if (!strcmp(type
, commit_type
)) obj_type
= OBJ_COMMIT
;
613 else if (!strcmp(type
, tag_type
)) obj_type
= OBJ_TAG
;
614 else die("base object %s is of type '%s'",
615 sha1_to_hex(d
->base
.sha1
), type
);
617 find_delta_childs(&d
->base
, &first
, &last
);
618 for (j
= first
; j
<= last
; j
++) {
619 struct object_entry
*child
= objects
+ deltas
[j
].obj_no
;
620 if (child
->real_type
== OBJ_REF_DELTA
)
621 resolve_delta(child
, data
, size
, obj_type
);
624 append_obj_to_pack(data
, size
, obj_type
);
627 percent
= display_progress(nr_resolved_deltas
,
635 static void readjust_pack_header_and_sha1(unsigned char *sha1
)
637 struct pack_header hdr
;
641 /* Rewrite pack header with updated object number */
642 if (lseek(output_fd
, 0, SEEK_SET
) != 0)
643 die("cannot seek back: %s", strerror(errno
));
644 if (xread(output_fd
, &hdr
, sizeof(hdr
)) != sizeof(hdr
))
645 die("cannot read pack header back: %s", strerror(errno
));
646 hdr
.hdr_entries
= htonl(nr_objects
);
647 if (lseek(output_fd
, 0, SEEK_SET
) != 0)
648 die("cannot seek back: %s", strerror(errno
));
649 write_or_die(output_fd
, &hdr
, sizeof(hdr
));
650 if (lseek(output_fd
, 0, SEEK_SET
) != 0)
651 die("cannot seek back: %s", strerror(errno
));
653 /* Recompute and store the new pack's SHA1 */
656 unsigned char *buf
[4096];
657 size
= xread(output_fd
, buf
, sizeof(buf
));
659 die("cannot read pack data back: %s", strerror(errno
));
660 SHA1_Update(&ctx
, buf
, size
);
662 SHA1_Final(sha1
, &ctx
);
663 write_or_die(output_fd
, sha1
, 20);
666 static int sha1_compare(const void *_a
, const void *_b
)
668 struct object_entry
*a
= *(struct object_entry
**)_a
;
669 struct object_entry
*b
= *(struct object_entry
**)_b
;
670 return hashcmp(a
->sha1
, b
->sha1
);
674 * On entry *sha1 contains the pack content SHA1 hash, on exit it is
675 * the SHA1 hash of sorted object names.
677 static const char * write_index_file(const char *index_name
, unsigned char *sha1
)
680 struct object_entry
**sorted_by_sha
, **list
, **last
;
681 unsigned int array
[256];
687 xcalloc(nr_objects
, sizeof(struct object_entry
*));
688 list
= sorted_by_sha
;
689 last
= sorted_by_sha
+ nr_objects
;
690 for (i
= 0; i
< nr_objects
; ++i
)
691 sorted_by_sha
[i
] = &objects
[i
];
692 qsort(sorted_by_sha
, nr_objects
, sizeof(sorted_by_sha
[0]),
697 sorted_by_sha
= list
= last
= NULL
;
700 static char tmpfile
[PATH_MAX
];
701 snprintf(tmpfile
, sizeof(tmpfile
),
702 "%s/index_XXXXXX", get_object_directory());
703 fd
= mkstemp(tmpfile
);
704 index_name
= xstrdup(tmpfile
);
707 fd
= open(index_name
, O_CREAT
|O_EXCL
|O_WRONLY
, 0600);
710 die("unable to create %s: %s", index_name
, strerror(errno
));
711 f
= sha1fd(fd
, index_name
);
714 * Write the first-level table (the list is sorted,
715 * but we use a 256-entry lookup to be able to avoid
716 * having to do eight extra binary search iterations).
718 for (i
= 0; i
< 256; i
++) {
719 struct object_entry
**next
= list
;
720 while (next
< last
) {
721 struct object_entry
*obj
= *next
;
722 if (obj
->sha1
[0] != i
)
726 array
[i
] = htonl(next
- sorted_by_sha
);
729 sha1write(f
, array
, 256 * sizeof(int));
731 /* recompute the SHA1 hash of sorted object names.
732 * currently pack-objects does not do this, but that
737 * Write the actual SHA1 entries..
739 list
= sorted_by_sha
;
740 for (i
= 0; i
< nr_objects
; i
++) {
741 struct object_entry
*obj
= *list
++;
742 unsigned int offset
= htonl(obj
->offset
);
743 sha1write(f
, &offset
, 4);
744 sha1write(f
, obj
->sha1
, 20);
745 SHA1_Update(&ctx
, obj
->sha1
, 20);
747 sha1write(f
, sha1
, 20);
748 sha1close(f
, NULL
, 1);
750 SHA1_Final(sha1
, &ctx
);
754 static void final(const char *final_pack_name
, const char *curr_pack_name
,
755 const char *final_index_name
, const char *curr_index_name
,
764 err
= close(output_fd
);
766 die("error while closing pack file: %s", strerror(errno
));
767 chmod(curr_pack_name
, 0444);
770 if (final_pack_name
!= curr_pack_name
) {
771 if (!final_pack_name
) {
772 snprintf(name
, sizeof(name
), "%s/pack/pack-%s.pack",
773 get_object_directory(), sha1_to_hex(sha1
));
774 final_pack_name
= name
;
776 if (move_temp_to_file(curr_pack_name
, final_pack_name
))
777 die("cannot store pack file");
780 chmod(curr_index_name
, 0444);
781 if (final_index_name
!= curr_index_name
) {
782 if (!final_index_name
) {
783 snprintf(name
, sizeof(name
), "%s/pack/pack-%s.idx",
784 get_object_directory(), sha1_to_hex(sha1
));
785 final_index_name
= name
;
787 if (move_temp_to_file(curr_index_name
, final_index_name
))
788 die("cannot store index file");
792 int main(int argc
, char **argv
)
794 int i
, fix_thin_pack
= 0;
795 const char *curr_pack
, *pack_name
= NULL
;
796 const char *curr_index
, *index_name
= NULL
;
797 char *index_name_buf
= NULL
;
798 unsigned char sha1
[20];
800 for (i
= 1; i
< argc
; i
++) {
801 const char *arg
= argv
[i
];
804 if (!strcmp(arg
, "--stdin")) {
806 } else if (!strcmp(arg
, "--fix-thin")) {
808 } else if (!strcmp(arg
, "-v")) {
810 } else if (!strcmp(arg
, "-o")) {
811 if (index_name
|| (i
+1) >= argc
)
812 usage(index_pack_usage
);
813 index_name
= argv
[++i
];
815 usage(index_pack_usage
);
820 usage(index_pack_usage
);
824 if (!pack_name
&& !from_stdin
)
825 usage(index_pack_usage
);
826 if (fix_thin_pack
&& !from_stdin
)
827 die("--fix-thin cannot be used without --stdin");
828 if (!index_name
&& pack_name
) {
829 int len
= strlen(pack_name
);
830 if (!has_extension(pack_name
, ".pack"))
831 die("packfile name '%s' does not end with '.pack'",
833 index_name_buf
= xmalloc(len
);
834 memcpy(index_name_buf
, pack_name
, len
- 5);
835 strcpy(index_name_buf
+ len
- 5, ".idx");
836 index_name
= index_name_buf
;
839 curr_pack
= open_pack_file(pack_name
);
841 objects
= xmalloc((nr_objects
+ 1) * sizeof(struct object_entry
));
842 deltas
= xmalloc(nr_objects
* sizeof(struct delta_entry
));
844 setup_progress_signal();
845 parse_pack_objects(sha1
);
846 if (nr_deltas
!= nr_resolved_deltas
) {
848 int nr_unresolved
= nr_deltas
- nr_resolved_deltas
;
849 int nr_objects_initial
= nr_objects
;
850 if (nr_unresolved
<= 0)
851 die("confusion beyond insanity");
852 objects
= xrealloc(objects
,
853 (nr_objects
+ nr_unresolved
+ 1)
855 fix_unresolved_deltas(nr_unresolved
);
857 fprintf(stderr
, "%d objects were added to complete this thin pack.\n",
858 nr_objects
- nr_objects_initial
);
859 readjust_pack_header_and_sha1(sha1
);
861 if (nr_deltas
!= nr_resolved_deltas
)
862 die("pack has %d unresolved deltas",
863 nr_deltas
- nr_resolved_deltas
);
865 /* Flush remaining pack final 20-byte SHA1. */
870 curr_index
= write_index_file(index_name
, sha1
);
871 final(pack_name
, curr_pack
, index_name
, curr_index
, sha1
);
873 free(index_name_buf
);
875 printf("%s\n", sha1_to_hex(sha1
));