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 1ccfa99..42978a3 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 2397477..cea8570 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 7029a59..045cf6f 100644 --- a/odb-helper.c +++ b/odb-helper.c @@ -235,5 +235,20 @@ int odb_helper_fetch_object(struct odb_helper *o, const unsigned char *sha1, return -1; } + 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 0f704f9..8c3916d 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.9.0.rc2.11.g990c140 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html