@matheusbsbs / matheus-bagliano / commits / 9b0aa72870
Fork 0

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>

Shawn O. Pearce committed Apr 19, 2010 at 07:23 UTC 9b0aa728705439ca4b4e7ec845f79f8487059320
2 files changed +13 -3
pack-check.c
+12 -3
@@ -133,14 +133,13 @@ static int verify_packfile(struct packed_git *p,
133 return err;
134 }
135
136 -int verify_pack(struct packed_git *p)
136 +int verify_pack_index(struct packed_git *p)
137 {
138 off_t index_size;
139 const unsigned char *index_base;
140 git_SHA_CTX ctx;
141 unsigned char sha1[20];
142 int err = 0;
143 - struct pack_window *w_curs = NULL;
143
144 if (open_pack_index(p))
145 return error("packfile %s index not opened", p->pack_name);
@@ -154,8 +153,18 @@ int verify_pack(struct packed_git *p)
153 if (hashcmp(sha1, index_base + index_size - 20))
154 err = error("Packfile index for %s SHA1 mismatch",
155 p->pack_name);
156 + return err;
157 +}
158 +
159 +int verify_pack(struct packed_git *p)
160 +{
161 + int err = 0;
162 + struct pack_window *w_curs = NULL;
163 +
164 + err |= verify_pack_index(p);
165 + if (!p->index_data)
166 + return -1;
167
158 - /* Verify pack file */
168 err |= verify_packfile(p, &w_curs);
169 unuse_pack(&w_curs);
170
pack.h
+1
@@ -57,6 +57,7 @@ struct pack_idx_entry {
57
58 extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
59 extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
60 +extern int verify_pack_index(struct packed_git *);
61 extern int verify_pack(struct packed_git *);
62 extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
63 extern char *index_pack_lockfile(int fd);