summaryrefslogtreecommitdiff
path: root/pack-check.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2009-01-18 08:04:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-06-06 17:56:27 (GMT)
commit4277c6709d1976ee5cef33b7e415ae0dded87090 (patch)
tree09c03adf122b45787e4011c4d7cf522f0e32452f /pack-check.c
parent1b1b7b235b040f27952d48ab8811c958a1f6d052 (diff)
downloadgit-4277c6709d1976ee5cef33b7e415ae0dded87090.zip
git-4277c6709d1976ee5cef33b7e415ae0dded87090.tar.gz
git-4277c6709d1976ee5cef33b7e415ae0dded87090.tar.bz2
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>
Diffstat (limited to 'pack-check.c')
-rw-r--r--pack-check.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/pack-check.c b/pack-check.c
index 90c33b1..166ca70 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -49,7 +49,7 @@ static int verify_packfile(struct packed_git *p,
const unsigned char *index_base = p->index_data;
git_SHA_CTX ctx;
unsigned char sha1[20], *pack_sig;
- off_t offset = 0, pack_sig_ofs = p->pack_size - 20;
+ off_t offset = 0, pack_sig_ofs = 0;
uint32_t nr_objects, i;
int err = 0;
struct idx_entry *entries;
@@ -61,14 +61,16 @@ static int verify_packfile(struct packed_git *p,
*/
git_SHA1_Init(&ctx);
- while (offset < pack_sig_ofs) {
+ do {
unsigned int remaining;
unsigned char *in = use_pack(p, w_curs, offset, &remaining);
offset += remaining;
+ if (!pack_sig_ofs)
+ pack_sig_ofs = p->pack_size - 20;
if (offset > pack_sig_ofs)
remaining -= (unsigned int)(offset - pack_sig_ofs);
git_SHA1_Update(&ctx, in, remaining);
- }
+ } while (offset < pack_sig_ofs);
git_SHA1_Final(sha1, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
if (hashcmp(sha1, pack_sig))