diff options
author | Carlos Martín Nieto <cmn@elego.de> | 2012-06-05 14:48:51 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-07-03 12:50:51 +0200 |
commit | 521aedad307c6f72d6f6d660943508b2b015f6dd (patch) | |
tree | aef33032b13ca170a3d7a016e7e8522a7635ce6f /src/odb_pack.c | |
parent | e560aa8ffa7cf143fbd34a5aec44741ae4c77271 (diff) | |
download | libgit2-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/odb_pack.c')
-rw-r--r-- | src/odb_pack.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c index 458f288d9..4b860e864 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -420,6 +420,25 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid) return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0; } +static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data) +{ + struct git_pack_file *p; + struct pack_backend *backend; + unsigned int i; + + assert(_backend && cb); + backend = (struct pack_backend *)_backend; + + /* Make sure we know about the packfiles */ + if (packfile_refresh_all(backend) < 0) + return -1; + + git_vector_foreach(&backend->packs, i, p) { + git_pack_foreach_entry(p, cb, &data); + } + return 0; +} + static void pack_backend__free(git_odb_backend *_backend) { struct pack_backend *backend; @@ -463,6 +482,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir) backend->parent.read_prefix = &pack_backend__read_prefix; backend->parent.read_header = NULL; backend->parent.exists = &pack_backend__exists; + backend->parent.foreach = &pack_backend__foreach; backend->parent.free = &pack_backend__free; *backend_out = (git_odb_backend *)backend; |