[PATCH v3 2/6] odb/source-files: always load alternates via primary object directory
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Oct 28, 2026, 07:11 UTC
- Message-ID
- <20261028-pks-odb-files-reload-alternates-v3-2-011ddb64b626@pks.im>
- In-Reply-To
- <20261028-pks-odb-files-reload-alternates-v3-0-011ddb64b626@pks.im>
The "files" source tracks a list of object directories. The head of the list is typically expected to be the primary object directory, whereas the tail is the list of alternates linked to it. This assumption does not always hold though, as transactions cause us to prepend another quarantine object directory to the list.
This is not much of a problem now, but in a subsequent commit we're about to re-read "objects/info/alternates" when we hit a missing object. So we may start calling `prepare_alternates()` in situations where the head of the list is _not_ the primary object directory, but if so we would now try to read alternates from the quarantine directory and not from the primary object directory.
Fix this issue by instead using the path of the "files" source both when reading alternates in `prepare_alternates()` and when deduplicating the primary object directory in `odb_files_dir_is_usable()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- odb/source-files.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/odb/source-files.c b/odb/source-files.c index d31da6e5d90..c0375e7cb70 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -228,7 +228,7 @@ static bool odb_files_dir_is_usable(struct odb_source_files *files, struct hashmap_entry key; bool usable = false; - strbuf_realpath(&normalized_objdir, files->dirs->abspath, 1); + strbuf_realpath(&normalized_objdir, files->base.path, 1); /* Detect cases where alternate disappeared */ if (!is_directory(path)) { @@ -390,7 +390,7 @@ static void prepare_alternates(struct odb_source_files *files, struct strvec alternates = STRVEC_INIT; parse_alternates(alternate_db, PATH_SEP, NULL, &alternates); - read_alternates(files->dirs->abspath, &alternates); + read_alternates(files->base.path, &alternates); for (size_t i = 0; i < alternates.nr; i++) add_alternate_recursively(files, alternates.v[i], 0);
-- 2.56.0.341.g393f52fd96.dirty