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

pack-objects: use fixup_pack_header_footer()'s validation mode

When limiting the pack size, a new header has to be written to the pack and a new SHA1 computed. Make sure that the SHA1 of what is being read back matches the SHA1 of what was written. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Aug 29, 2008 at 16:08 UTC ac0463ed44e859c84e354cd0ae47d9b5b124e112
2 files changed +5 -5
builtin-pack-objects.c
+2 -2
@@ -492,9 +492,9 @@ static void write_pack_file(void)
492 } else if (nr_written == nr_remaining) {
493 sha1close(f, sha1, CSUM_FSYNC);
494 } else {
495 - int fd = sha1close(f, NULL, 0);
495 + int fd = sha1close(f, sha1, 0);
496 fixup_pack_header_footer(fd, sha1, pack_tmp_name,
497 - nr_written, NULL, 0);
497 + nr_written, sha1, offset);
498 close(fd);
499 }
500
csum-file.c
+3 -3
@@ -42,11 +42,11 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
42 sha1flush(f, offset);
43 f->offset = 0;
44 }
45 + SHA1_Final(f->buffer, &f->ctx);
46 + if (result)
47 + hashcpy(result, f->buffer);
48 if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
49 /* write checksum and close fd */
47 - SHA1_Final(f->buffer, &f->ctx);
48 - if (result)
49 - hashcpy(result, f->buffer);
50 sha1flush(f, 20);
51 if (flags & CSUM_FSYNC)
52 fsync_or_die(f->fd, f->name);