diff options
author | Vicent Martà <vicent@github.com> | 2012-07-12 09:42:54 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-07-12 09:42:54 -0700 |
commit | dd4345b4247f067e282ccbcde0f0b36d3d571470 (patch) | |
tree | 7db054c78dd6335c3308fb7ea02e82cf6c178720 /src/pack.c | |
parent | 0cf6b2f29ebf9d6342bd205197938e881ccc246f (diff) | |
parent | 521aedad307c6f72d6f6d660943508b2b015f6dd (diff) | |
download | libgit2-dd4345b4247f067e282ccbcde0f0b36d3d571470.tar.gz |
Merge pull request #789 from carlosmn/odb-foreach
odb: add git_odb_foreach()
Diffstat (limited to 'src/pack.c')
-rw-r--r-- | src/pack.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/pack.c b/src/pack.c index 808ceb70c..1d88eaa7d 100644 --- a/src/pack.c +++ b/src/pack.c @@ -686,6 +686,49 @@ static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_ } } +int git_pack_foreach_entry( + struct git_pack_file *p, + int (*cb)(git_oid *oid, void *data), + void *data) + +{ + const unsigned char *index = p->index_map.data, *current; + unsigned stride; + uint32_t i; + + if (index == NULL) { + int error; + + if ((error = pack_index_open(p)) < 0) + return error; + + assert(p->index_map.data); + + index = p->index_map.data; + } + + if (p->index_version > 1) { + index += 8; + } + + index += 4 * 256; + + if (p->index_version > 1) { + stride = 20; + } else { + stride = 24; + index += 4; + } + + current = index; + for (i = 0; i < p->num_objects; i++) { + cb((git_oid *)current, data); + current += stride; + } + + return 0; +} + static int pack_entry_find_offset( git_off_t *offset_out, git_oid *found_oid, |