X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=index-pack.c;h=58c4a9c41dd7a05b86d40e6eeee33ba0a3fb6c4f;hb=cfabd6eee1745cfec58cfcb794ce8847e43b888a;hp=824004f9a2a53dcef1db3c083a4a94ce0eff9028;hpb=07c785dbb799ce7fa74686e776cd07d69c3ce01e;p=git.git diff --git a/index-pack.c b/index-pack.c index 824004f9a..58c4a9c41 100644 --- a/index-pack.c +++ b/index-pack.c @@ -82,7 +82,7 @@ static void *fill(int min) die("cannot fill %d bytes", min); flush(); do { - int ret = xread(input_fd, input_buffer + input_len, + ssize_t ret = xread(input_fd, input_buffer + input_len, sizeof(input_buffer) - input_len); if (ret <= 0) { if (!ret) @@ -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",