diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2007-05-02 12:14:15 -0400 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2007-05-02 13:24:21 -0400 |
commit | cbc6bdab08af239b5a6477e7e6db16a766ec4986 (patch) | |
tree | 2c2f7a482376e941f84ca01ec204a3fd1efe2e80 /index-pack.c | |
parent | 8b0eca7c7b73d0dc5d49f400a878d9b781ec4bec (diff) | |
download | git-cbc6bdab08af239b5a6477e7e6db16a766ec4986.tar.gz |
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>
Diffstat (limited to 'index-pack.c')
-rw-r--r-- | index-pack.c | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/index-pack.c b/index-pack.c index 824004f9a2..b9da19f55b 100644 --- a/index-pack.c +++ b/index-pack.c @@ -602,37 +602,6 @@ static void fix_unresolved_deltas(int nr_unresolved) free(sorted_by_pos); } -static void readjust_pack_header_and_sha1(unsigned char *sha1) -{ - struct pack_header hdr; - SHA_CTX ctx; - int size; - - /* Rewrite pack header with updated object number */ - if (lseek(output_fd, 0, SEEK_SET) != 0) - die("cannot seek back: %s", strerror(errno)); - if (read_in_full(output_fd, &hdr, sizeof(hdr)) != sizeof(hdr)) - die("cannot read pack header back: %s", strerror(errno)); - hdr.hdr_entries = htonl(nr_objects); - if (lseek(output_fd, 0, SEEK_SET) != 0) - die("cannot seek back: %s", strerror(errno)); - write_or_die(output_fd, &hdr, sizeof(hdr)); - if (lseek(output_fd, 0, SEEK_SET) != 0) - die("cannot seek back: %s", strerror(errno)); - - /* Recompute and store the new pack's SHA1 */ - SHA1_Init(&ctx); - do { - unsigned char *buf[4096]; - size = xread(output_fd, buf, sizeof(buf)); - if (size < 0) - die("cannot read pack data back: %s", strerror(errno)); - SHA1_Update(&ctx, buf, size); - } while (size > 0); - SHA1_Final(sha1, &ctx); - write_or_die(output_fd, sha1, 20); -} - static uint32_t index_default_version = 1; static uint32_t index_off32_limit = 0x7fffffff; @@ -963,7 +932,8 @@ int main(int argc, char **argv) fprintf(stderr, "%d objects were added to complete this thin pack.\n", nr_objects - nr_objects_initial); } - readjust_pack_header_and_sha1(sha1); + fixup_pack_header_footer(output_fd, sha1, + curr_pack, nr_objects); } if (nr_deltas != nr_resolved_deltas) die("pack has %d unresolved deltas", |