@matheusbsbs / matheus-bagliano / commits / 4277c6709d
Fork 0

Don't expect verify_pack() callers to set pack_size

Since use_pack() will end up populating pack_size if it is not already set, we can just adapt the code in verify_packfile() such that it doesn't require pack_size to be set beforehand. This allows callers not to have to set pack_size themselves, and we can thus revert changes from 1c23d794 (Don't die in git-http-fetch when fetching packs). Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mike Hommey committed Jan 18, 2009 at 09:04 UTC 4277c6709d1976ee5cef33b7e415ae0dded87090
1 file changed +5 -3
pack-check.c
+5 -3
@@ -49,7 +49,7 @@ static int verify_packfile(struct packed_git *p,
49 const unsigned char *index_base = p->index_data;
50 git_SHA_CTX ctx;
51 unsigned char sha1[20], *pack_sig;
52 - off_t offset = 0, pack_sig_ofs = p->pack_size - 20;
52 + off_t offset = 0, pack_sig_ofs = 0;
53 uint32_t nr_objects, i;
54 int err = 0;
55 struct idx_entry *entries;
@@ -61,14 +61,16 @@ static int verify_packfile(struct packed_git *p,
61 */
62
63 git_SHA1_Init(&ctx);
64 - while (offset < pack_sig_ofs) {
64 + do {
65 unsigned int remaining;
66 unsigned char *in = use_pack(p, w_curs, offset, &remaining);
67 offset += remaining;
68 + if (!pack_sig_ofs)
69 + pack_sig_ofs = p->pack_size - 20;
70 if (offset > pack_sig_ofs)
71 remaining -= (unsigned int)(offset - pack_sig_ofs);
72 git_SHA1_Update(&ctx, in, remaining);
71 - }
73 + } while (offset < pack_sig_ofs);
74 git_SHA1_Final(sha1, &ctx);
75 pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
76 if (hashcmp(sha1, pack_sig))