Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- external-odb.c | 15 ++++++++++++++- odb-helper.c | 23 +++++++++++++++++++++++ odb-helper.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/external-odb.c b/external-odb.c index 2efa805d12..8c2570b2e7 100644 --- a/external-odb.c +++ b/external-odb.c @@ -66,6 +66,14 @@ static int external_odb_config(const char *var, const char *value, void *data) return 0; } +static void external_odb_get_capabilities(void) +{ + struct odb_helper *o; + + for (o = helpers; o; o = o->next) + odb_helper_get_capabilities(o); +} + static void external_odb_init(void) { static int initialized; @@ -75,6 +83,8 @@ static void external_odb_init(void) initialized = 1; git_config(external_odb_config, NULL); + + external_odb_get_capabilities(); } const char *external_odb_root(void) @@ -94,9 +104,12 @@ int external_odb_has_object(const unsigned char *sha1) external_odb_init(); - for (o = helpers; o; o = o->next) + for (o = helpers; o; o = o->next) { + if (!(o->supported_capabilities & ODB_HELPER_CAP_HAVE)) + return 1; if (odb_helper_has_object(o, sha1)) return 1; + } return 0; } diff --git a/odb-helper.c b/odb-helper.c index 20e83cb55a..a6bf81af8d 100644 --- a/odb-helper.c +++ b/odb-helper.c @@ -260,6 +260,29 @@ static int odb_helper_finish(struct odb_helper *o, return 0; } +int odb_helper_get_capabilities(struct odb_helper *o) +{ + struct odb_helper_cmd cmd; + FILE *fh; + struct strbuf line = STRBUF_INIT; + + if (!o->script_mode) + return 0; + + if (odb_helper_start(o, &cmd, 0, "get_cap") < 0) + return -1; + + fh = xfdopen(cmd.child.out, "r"); + while (strbuf_getline(&line, fh) != EOF) + parse_capabilities(line.buf, &o->supported_capabilities, o->name); + + strbuf_release(&line); + fclose(fh); + odb_helper_finish(o, &cmd); + + return 0; +} + static int parse_object_line(struct odb_helper_object *o, const char *line) { char *end; diff --git a/odb-helper.h b/odb-helper.h index b23544aa4a..8e0b0fc781 100644 --- a/odb-helper.h +++ b/odb-helper.h @@ -33,6 +33,7 @@ struct odb_helper { }; struct odb_helper *odb_helper_new(const char *name, int namelen); +int odb_helper_get_capabilities(struct odb_helper *o); 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); -- 2.13.1.565.gbfcd7a9048