Skip to content

Commit

Permalink
Extract verify_pack_index for reuse from verify_pack
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
spearce authored and gitster committed Apr 20, 2010
1 parent fa5fc15 commit 9b0aa72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pack-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct pack_idx_entry {

extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
extern int verify_pack_index(struct packed_git *);
extern int verify_pack(struct packed_git *);
extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
extern char *index_pack_lockfile(int fd);
Expand Down

0 comments on commit 9b0aa72

Please sign in to comment.