Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- external-odb.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/external-odb.c b/external-odb.c index 8c2570b2e7..c39f207dd3 100644 --- a/external-odb.c +++ b/external-odb.c @@ -95,32 +95,11 @@ const char *external_odb_root(void) return root; } -int external_odb_has_object(const unsigned char *sha1) -{ - struct odb_helper *o; - - if (!use_external_odb) - return 0; - - external_odb_init(); - - 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; -} - -int external_odb_fetch_object(const unsigned char *sha1) +static int external_odb_do_fetch_object(const unsigned char *sha1) { struct odb_helper *o; const char *path; - if (!external_odb_has_object(sha1)) - return -1; - path = sha1_file_name_alt(external_odb_root(), sha1); safe_create_leading_directories_const(path); prepare_external_alt_odb(); @@ -175,6 +154,35 @@ int external_odb_fault_in_object(const unsigned char *sha1) return -1; } +int external_odb_has_object(const unsigned char *sha1) +{ + struct odb_helper *o; + + if (!use_external_odb) + return 0; + + external_odb_init(); + + for (o = helpers; o; o = o->next) { + if (!(o->supported_capabilities & ODB_HELPER_CAP_HAVE)) { + if (o->fetch_kind == ODB_FETCH_KIND_FAULT_IN) + return 1; + return !external_odb_do_fetch_object(sha1); + } + if (odb_helper_has_object(o, sha1)) + return 1; + } + return 0; +} + +int external_odb_fetch_object(const unsigned char *sha1) +{ + if (!external_odb_has_object(sha1)) + return -1; + + return external_odb_do_fetch_object(sha1); +} + int external_odb_for_each_object(each_external_object_fn fn, void *data) { struct odb_helper *o; -- 2.13.1.565.gbfcd7a9048