summaryrefslogtreecommitdiff
path: root/pack-check.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-04-19 14:23:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-04-20 00:56:13 (GMT)
commit9b0aa728705439ca4b4e7ec845f79f8487059320 (patch)
tree519fe764ab29f4ab7f87c9baccff601a5e2a9313 /pack-check.c
parentfa5fc15d6ecfb9452c578bb4c80e98ccca12750c (diff)
downloadgit-9b0aa728705439ca4b4e7ec845f79f8487059320.zip
git-9b0aa728705439ca4b4e7ec845f79f8487059320.tar.gz
git-9b0aa728705439ca4b4e7ec845f79f8487059320.tar.bz2
Extract verify_pack_index for reuse from verify_pack
The dumb HTTP transport should verify an index is completely valid before trying to use it. That requires checking the header/footer but also checking the complete content SHA-1. All of this logic is already in the front half of verify_pack, so pull it out into a new function that can be reused. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-check.c')
-rw-r--r--pack-check.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/pack-check.c b/pack-check.c
index 166ca70..395fb95 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -133,14 +133,13 @@ static int verify_packfile(struct packed_git *p,
return err;
}
-int verify_pack(struct packed_git *p)
+int verify_pack_index(struct packed_git *p)
{
off_t index_size;
const unsigned char *index_base;
git_SHA_CTX ctx;
unsigned char sha1[20];
int err = 0;
- struct pack_window *w_curs = NULL;
if (open_pack_index(p))
return error("packfile %s index not opened", p->pack_name);
@@ -154,8 +153,18 @@ int verify_pack(struct packed_git *p)
if (hashcmp(sha1, index_base + index_size - 20))
err = error("Packfile index for %s SHA1 mismatch",
p->pack_name);
+ return err;
+}
+
+int verify_pack(struct packed_git *p)
+{
+ int err = 0;
+ struct pack_window *w_curs = NULL;
+
+ err |= verify_pack_index(p);
+ if (!p->index_data)
+ return -1;
- /* Verify pack file */
err |= verify_packfile(p, &w_curs);
unuse_pack(&w_curs);