From: Patrick Steinhardt Date: Tue, 13 Oct 2026 07:36:28 GMT Subject: [PATCH 4/5] odb: remove read loop for found objects Message-ID: <20261013-pks-odb-files-alternates-cleanups-v1-4-b7030ff2b26f@pks.im> In-Reply-To: <20261013-pks-odb-files-alternates-cleanups-v1-0-b7030ff2b26f@pks.im> Before moving alternates into the "files" backend we had to handle alternates in `do_oid_object_info_extended()`. This made the retry logic somewhat complex, as we had to juggle reloading of the sources, the second read and fetching missing objects. And to handle the potential retries we loop around that logic multiple times. Nowadays though, the reload and retry logic are located in the "files" backend itself. Consequently, using a loop is a bit on the heavy side and makes the code harder to reason about. Simplify the logic by removing the loop. Instead, we explicitly re-read exactly once after having fetched objects from a promisor remote. Signed-off-by: Patrick Steinhardt --- odb.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/odb.c b/odb.c index 69a4c203bc..095183aec0 100644 --- a/odb.c +++ b/odb.c @@ -265,7 +265,6 @@ static enum odb_read_status do_oid_object_info_extended(struct object_database * struct strbuf corrupt_err = STRBUF_INIT; const struct object_id *real = oid; enum odb_read_status ret; - int already_retried = 0; bool corrupt = false; if (flags & OBJECT_INFO_LOOKUP_REPLACE) @@ -277,38 +276,39 @@ static enum odb_read_status do_oid_object_info_extended(struct object_database * if (!odb_source_read_object_info(odb->inmemory_objects, oid, oi, flags, NULL)) return 0; - while (1) { + ret = odb_source_read_object_info(odb->source, real, oi, flags, + &corrupt_err); + if (!ret) + goto out; + if (ret != ODB_READ_NOT_FOUND) + corrupt = true; + + /* Try to fetch the missing object from a promisor remote. */ + if (odb->repo->fetch_if_missing && repo_has_promisor_remote(odb->repo) && + !(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) { + promisor_remote_get_direct(odb->repo, real, 1); + ret = odb_source_read_object_info(odb->source, real, oi, flags, corrupt_err.len ? NULL : &corrupt_err); if (!ret) goto out; if (ret != ODB_READ_NOT_FOUND) corrupt = true; + } - /* Check if it is a missing object */ - if (odb->repo->fetch_if_missing && repo_has_promisor_remote(odb->repo) && - !already_retried && - !(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) { - promisor_remote_get_direct(odb->repo, real, 1); - already_retried = 1; - continue; - } - - if (flags & OBJECT_INFO_DIE_IF_CORRUPT) { - if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid)) - die(_("replacement %s not found for %s"), - oid_to_hex(real), oid_to_hex(oid)); - if (corrupt) { - if (corrupt_err.len) - die("%s", corrupt_err.buf); - die(_("object %s is corrupt"), oid_to_hex(real)); - } + if (flags & OBJECT_INFO_DIE_IF_CORRUPT) { + if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid)) + die(_("replacement %s not found for %s"), + oid_to_hex(real), oid_to_hex(oid)); + if (corrupt) { + if (corrupt_err.len) + die("%s", corrupt_err.buf); + die(_("object %s is corrupt"), oid_to_hex(real)); } - - ret = corrupt ? ODB_READ_ERROR : ODB_READ_NOT_FOUND; - goto out; } + ret = corrupt ? ODB_READ_ERROR : ODB_READ_NOT_FOUND; + out: strbuf_release(&corrupt_err); return ret; -- 2.56.0.212.g129ede20d9.dirty