{"thread":{"id":"19585","subject":"[PATCH 05/17] Don't expect verify_pack() callers to set pack_size","startedAt":"2009-05-29T17:58:58Z","lastAt":"2009-05-29T17:58:58Z","messageCount":1,"participants":["Tay Ray Chuan"],"isPatch":true,"patchVersion":1,"patchTotal":17},"messages":[{"id":"115027","messageId":"20090530015858.a629892f.rctay89@gmail.com","threadId":"19585","inReplyTo":null,"subject":"[PATCH 05/17] Don't expect verify_pack() callers to set pack_size","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-05-29T17:58:58Z","receivedAt":"2009-05-29T17:58:58Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"From:\tMike Hommey <mh@glandium.org>\nDate:\tSun, 18 Jan 2009 09:04:26 +0100\n\nSince use_pack() will end up populating pack_size if it is not already set,\nwe can just adapt the code in verify_packfile() such that it doesn't require\npack_size to be set beforehand.\n\nThis allows callers not to have to set pack_size themselves, and we can thus\nrevert changes from 1c23d794 (Don't die in git-http-fetch when fetching packs).\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n pack-check.c |    8 +++++---\n 1 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/pack-check.c b/pack-check.c\nindex 90c33b1..166ca70 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -49,7 +49,7 @@ static int verify_packfile(struct packed_git *p,\n \tconst unsigned char *index_base = p->index_data;\n \tgit_SHA_CTX ctx;\n \tunsigned char sha1[20], *pack_sig;\n-\toff_t offset = 0, pack_sig_ofs = p->pack_size - 20;\n+\toff_t offset = 0, pack_sig_ofs = 0;\n \tuint32_t nr_objects, i;\n \tint err = 0;\n \tstruct idx_entry *entries;\n@@ -61,14 +61,16 @@ static int verify_packfile(struct packed_git *p,\n \t */\n\n \tgit_SHA1_Init(&ctx);\n-\twhile (offset < pack_sig_ofs) {\n+\tdo {\n \t\tunsigned int remaining;\n \t\tunsigned char *in = use_pack(p, w_curs, offset, &remaining);\n \t\toffset += remaining;\n+\t\tif (!pack_sig_ofs)\n+\t\t\tpack_sig_ofs = p->pack_size - 20;\n \t\tif (offset > pack_sig_ofs)\n \t\t\tremaining -= (unsigned int)(offset - pack_sig_ofs);\n \t\tgit_SHA1_Update(&ctx, in, remaining);\n-\t}\n+\t} while (offset < pack_sig_ofs);\n \tgit_SHA1_Final(sha1, &ctx);\n \tpack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);\n \tif (hashcmp(sha1, pack_sig))\n--\n1.6.3.1\n"}]}