odb: Try to lookup headers in all backends before passthrough
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/src/odb.c b/src/odb.c
index 17f9b37..890e6e2 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -855,8 +855,9 @@ static int odb_read_header_1(
const git_oid *id, bool only_refreshed)
{
size_t i;
- int error = GIT_PASSTHROUGH;
git_otype ht;
+ bool passthrough = false;
+ int error;
if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJ_BAD) {
*type_p = ht;
@@ -864,18 +865,32 @@ static int odb_read_header_1(
return 0;
}
- for (i = 0; i < db->backends.length && error < 0; ++i) {
+ for (i = 0; i < db->backends.length; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);
git_odb_backend *b = internal->backend;
if (only_refreshed && !b->refresh)
continue;
- if (b->read_header != NULL)
- error = b->read_header(len_p, type_p, b, id);
+ if (!b->read_header) {
+ passthrough = true;
+ continue;
+ }
+
+ error = b->read_header(len_p, type_p, b, id);
+
+ switch (error) {
+ case GIT_PASSTHROUGH:
+ passthrough = true;
+ break;
+ case GIT_ENOTFOUND:
+ break;
+ default:
+ return error;
+ }
}
- return error;
+ return passthrough ? GIT_PASSTHROUGH : GIT_ENOTFOUND;
}
int git_odb__read_header_or_object(