@matheusbsbs / matheus-bagliano / commits / cbc6bdab08
Fork 0

Reuse fixup_pack_header_footer in index-pack

Now that fast-import is using a "library function" to handle correcting its packfile's object count and trailing SHA-1 we should reuse the same function in index-pack, to reduce the size of the code we must maintain. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed May 2, 2007 at 12:14 UTC cbc6bdab08af239b5a6477e7e6db16a766ec4986
1 file changed +2 -32
index-pack.c
+2 -32
@@ -602,37 +602,6 @@ static void fix_unresolved_deltas(int nr_unresolved)
602 free(sorted_by_pos);
603 }
604
605 -static void readjust_pack_header_and_sha1(unsigned char *sha1)
606 -{
607 - struct pack_header hdr;
608 - SHA_CTX ctx;
609 - int size;
610 -
611 - /* Rewrite pack header with updated object number */
612 - if (lseek(output_fd, 0, SEEK_SET) != 0)
613 - die("cannot seek back: %s", strerror(errno));
614 - if (read_in_full(output_fd, &hdr, sizeof(hdr)) != sizeof(hdr))
615 - die("cannot read pack header back: %s", strerror(errno));
616 - hdr.hdr_entries = htonl(nr_objects);
617 - if (lseek(output_fd, 0, SEEK_SET) != 0)
618 - die("cannot seek back: %s", strerror(errno));
619 - write_or_die(output_fd, &hdr, sizeof(hdr));
620 - if (lseek(output_fd, 0, SEEK_SET) != 0)
621 - die("cannot seek back: %s", strerror(errno));
622 -
623 - /* Recompute and store the new pack's SHA1 */
624 - SHA1_Init(&ctx);
625 - do {
626 - unsigned char *buf[4096];
627 - size = xread(output_fd, buf, sizeof(buf));
628 - if (size < 0)
629 - die("cannot read pack data back: %s", strerror(errno));
630 - SHA1_Update(&ctx, buf, size);
631 - } while (size > 0);
632 - SHA1_Final(sha1, &ctx);
633 - write_or_die(output_fd, sha1, 20);
634 -}
635 -
605 static uint32_t index_default_version = 1;
606 static uint32_t index_off32_limit = 0x7fffffff;
607
@@ -963,7 +932,8 @@ int main(int argc, char **argv)
932 fprintf(stderr, "%d objects were added to complete this thin pack.\n",
933 nr_objects - nr_objects_initial);
934 }
966 - readjust_pack_header_and_sha1(sha1);
935 + fixup_pack_header_footer(output_fd, sha1,
936 + curr_pack, nr_objects);
937 }
938 if (nr_deltas != nr_resolved_deltas)
939 die("pack has %d unresolved deltas",