{"thread":{"id":"19474","subject":"[PATCH 06/18] Don't expect verify_pack() callers to set pack_size","startedAt":"2009-05-24T14:19:47Z","lastAt":"2009-05-24T20:43:39Z","messageCount":2,"participants":["Tay Ray Chuan","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":18},"messages":[{"id":"114565","messageId":"20090524221947.c83d6aba.rctay89@gmail.com","threadId":"19474","inReplyTo":null,"subject":"[PATCH 06/18] Don't expect verify_pack() callers to set pack_size","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-05-24T14:19:47Z","receivedAt":"2009-05-24T14:19:47Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Since 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"},{"id":"114590","messageId":"7vzld2teo4.fsf@alter.siamese.dyndns.org","threadId":"19474","inReplyTo":"20090524221947.c83d6aba.rctay89@gmail.com","subject":"Re: [PATCH 06/18] Don't expect verify_pack() callers to set pack_size","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-24T20:43:39Z","receivedAt":"2009-05-24T20:43:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tay Ray Chuan <rctay89@gmail.com> writes:\n\n> Since use_pack() will end up populating pack_size if it is not already set,\n> we can just adapt the code in verify_packfile() such that it doesn't require\n> pack_size to be set beforehand.\n>\n> This allows callers not to have to set pack_size themselves, and we can thus\n> revert changes from 1c23d794 (Don't die in git-http-fetch when fetching packs).\n>\n> Signed-off-by: Mike Hommey <mh@glandium.org>\n> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>\n\nWhen you forward somebody else's patch, please be careful not to lose the\nattribution, by having\n\n\tFrom: Mike Hommey <mh@glandium.org>\n        Date: <<<the original author date from Mike>>>\n\nand an empty line before you start the commit log message.\n"}]}