summaryrefslogtreecommitdiff
path: root/src/pack.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2012-06-05 14:48:51 +0200
committerCarlos Martín Nieto <carlos@cmartin.tk>2012-07-03 12:50:51 +0200
commit521aedad307c6f72d6f6d660943508b2b015f6dd (patch)
treeaef33032b13ca170a3d7a016e7e8522a7635ce6f /src/pack.c
parente560aa8ffa7cf143fbd34a5aec44741ae4c77271 (diff)
downloadlibgit2-521aedad307c6f72d6f6d660943508b2b015f6dd.tar.gz
odb: add git_odb_foreach()
Go through each backend and list every objects that exists in them. This allows fsck-like uses.
Diffstat (limited to 'src/pack.c')
-rw-r--r--src/pack.c43
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,