Skip to content

Commit 4277c67

Browse files
glandiumgitster
authored andcommitted
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 1c23d79 (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>
1 parent 1b1b7b2 commit 4277c67

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

pack-check.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int verify_packfile(struct packed_git *p,
4949
const unsigned char *index_base = p->index_data;
5050
git_SHA_CTX ctx;
5151
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;
5353
uint32_t nr_objects, i;
5454
int err = 0;
5555
struct idx_entry *entries;
@@ -61,14 +61,16 @@ static int verify_packfile(struct packed_git *p,
6161
*/
6262

6363
git_SHA1_Init(&ctx);
64-
while (offset < pack_sig_ofs) {
64+
do {
6565
unsigned int remaining;
6666
unsigned char *in = use_pack(p, w_curs, offset, &remaining);
6767
offset += remaining;
68+
if (!pack_sig_ofs)
69+
pack_sig_ofs = p->pack_size - 20;
6870
if (offset > pack_sig_ofs)
6971
remaining -= (unsigned int)(offset - pack_sig_ofs);
7072
git_SHA1_Update(&ctx, in, remaining);
71-
}
73+
} while (offset < pack_sig_ofs);
7274
git_SHA1_Final(sha1, &ctx);
7375
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
7476
if (hashcmp(sha1, pack_sig))

0 commit comments

Comments
 (0)