From: Jeff King <peff@xxxxxxxx> --- external-odb.c | 14 ++++++++++++++ external-odb.h | 6 ++++++ odb-helper.c | 15 +++++++++++++++ odb-helper.h | 4 ++++ 4 files changed, 39 insertions(+) diff --git a/external-odb.c b/external-odb.c index 1ccfa99a01..42978a3298 100644 --- a/external-odb.c +++ b/external-odb.c @@ -113,3 +113,17 @@ int external_odb_fetch_object(const unsigned char *sha1) return -1; } + +int external_odb_for_each_object(each_external_object_fn fn, void *data) +{ + struct odb_helper *o; + + external_odb_init(); + + for (o = helpers; o; o = o->next) { + int r = odb_helper_for_each_object(o, fn, data); + if (r) + return r; + } + return 0; +} diff --git a/external-odb.h b/external-odb.h index 2397477684..cea8570a49 100644 --- a/external-odb.h +++ b/external-odb.h @@ -5,4 +5,10 @@ const char *external_odb_root(void); int external_odb_has_object(const unsigned char *sha1); int external_odb_fetch_object(const unsigned char *sha1); +typedef int (*each_external_object_fn)(const unsigned char *sha1, + enum object_type type, + unsigned long size, + void *data); +int external_odb_for_each_object(each_external_object_fn, void *); + #endif /* EXTERNAL_ODB_H */ diff --git a/odb-helper.c b/odb-helper.c index de5562da9c..d8ef5cbf4b 100644 --- a/odb-helper.c +++ b/odb-helper.c @@ -243,3 +243,18 @@ int odb_helper_fetch_object(struct odb_helper *o, const unsigned char *sha1, return 0; } + +int odb_helper_for_each_object(struct odb_helper *o, + each_external_object_fn fn, + void *data) +{ + int i; + for (i = 0; i < o->have_nr; i++) { + struct odb_helper_object *obj = &o->have[i]; + int r = fn(obj->sha1, obj->type, obj->size, data); + if (r) + return r; + } + + return 0; +} diff --git a/odb-helper.h b/odb-helper.h index 0f704f9452..8c3916d215 100644 --- a/odb-helper.h +++ b/odb-helper.h @@ -1,6 +1,8 @@ #ifndef ODB_HELPER_H #define ODB_HELPER_H +#include "external-odb.h" + struct odb_helper { const char *name; const char *cmd; @@ -21,5 +23,7 @@ struct odb_helper *odb_helper_new(const char *name, int namelen); int odb_helper_has_object(struct odb_helper *o, const unsigned char *sha1); int odb_helper_fetch_object(struct odb_helper *o, const unsigned char *sha1, int fd); +int odb_helper_for_each_object(struct odb_helper *o, + each_external_object_fn, void *); #endif /* ODB_HELPER_H */ -- 2.13.1.565.gbfcd7a9048