When calling `prepare_multi_pack_index_one()` we know to skip loading a multi-pack index that we have already loaded beforehand. While this works well in case there actually is a multi-pack index, it doesn't work when we already tried to load a nonexistent one. This doesn't cause problems with the current layout, where users typically iterate through MIDXs via the linked list stored in the object database. But that linked list is going away, and those users will instead have to call `get_multi_pack_index()` for each object source. So if one of those sources doesn't have an MIDX, we may end up trying to repeatedly load it even though we know it doesn't exist. Address this issue by introducing a new variable that tracks whether we have tried to load multi-pack index of a given source. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- midx.c | 12 ++++++------ odb.h | 1 + packfile.c | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/midx.c b/midx.c index 416b3e8b54f..6d3a166fa01 100644 --- a/midx.c +++ b/midx.c @@ -728,13 +728,13 @@ int prepare_multi_pack_index_one(struct odb_source *source, int local) struct repository *r = source->odb->repo; struct multi_pack_index *m; + if (source->multi_pack_index_loaded) + return !!source->multi_pack_index; + prepare_repo_settings(r); if (!r->settings.core_multi_pack_index) return 0; - if (source->multi_pack_index) - return 1; - m = load_multi_pack_index(r, source->path, local); if (m) { struct multi_pack_index *mp = r->objects->multi_pack_index; @@ -745,11 +745,10 @@ int prepare_multi_pack_index_one(struct odb_source *source, int local) r->objects->multi_pack_index = m; } source->multi_pack_index = m; - - return 1; } - return 0; + source->multi_pack_index_loaded = 1; + return !!source->multi_pack_index; } int midx_checksum_valid(struct multi_pack_index *m) @@ -839,6 +838,7 @@ void clear_midx_file(struct repository *r) if (source->multi_pack_index) close_midx(source->multi_pack_index); source->multi_pack_index = NULL; + source->multi_pack_index_loaded = 0; } r->objects->multi_pack_index = NULL; } diff --git a/odb.h b/odb.h index 8e79c7be520..b39534dd55b 100644 --- a/odb.h +++ b/odb.h @@ -62,6 +62,7 @@ struct odb_source { * should only be accessed directly by packfile.c and midx.c */ struct multi_pack_index *multi_pack_index; + int multi_pack_index_loaded; /* * This is a temporary object store created by the tmp_objdir diff --git a/packfile.c b/packfile.c index 546c161d0c1..e5d9d7ac8bc 100644 --- a/packfile.c +++ b/packfile.c @@ -373,6 +373,7 @@ void close_object_store(struct object_database *o) if (source->multi_pack_index) close_midx(source->multi_pack_index); source->multi_pack_index = NULL; + source->multi_pack_index_loaded = 0; } o->multi_pack_index = NULL; -- 2.50.1.327.g047016eb4a.dirty