object-name: convert to use packfile_store_get_all_packs()

When searching for abbreviated or when trying to disambiguate object IDs
we do this in two steps:

  1. We search through the multi-pack index.

  2. We search through all packfiles not part of any multi-pack index.

The second step uses `packfile_store_get_packs()`, which knows to skip
loading any packfiles that are indexed by an MIDX; this is exactly what
we want.

But that function is somewhat problematic, as its behaviour is stateful
and is influenced by `packfile_store_get_all_packs()`. This function
basically does the same as `packfile_store_get_packs()`, but in addition
it also loads all packfiles indexed by an MIDX. The problem here is that
both of these functions act on the same linked list of packfiles, and
thus depending on whether or not `get_all_packs()` was called the result
returned by `get_packs()` will be different. Consequently, all callers
of `get_packs()` need to be prepared to see MIDX'd packs even though
these should in theory be excluded.

This interface is confusing and thus potentially dangerous, which is why
we're converting all callers of `get_packs()` to use `get_all_packs()`
instead.

Do so for the above functions in "object-name.c". As explained, we
already know to skip any MIDX'd packs in both `find_abbrev_len_packed()`
and `find_short_packed_object()`, so it's fine to start loading MIDX'd
packfiles.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-10-09 10:01:35 +02:00
committed by Junio C Hamano
parent 057a94fbbb
commit 181acc5f7f

View File

@@ -213,7 +213,7 @@ static void find_short_packed_object(struct disambiguate_state *ds)
unique_in_midx(m, ds); unique_in_midx(m, ds);
} }
for (p = packfile_store_get_packs(ds->repo->objects->packfiles); p && !ds->ambiguous; for (p = packfile_store_get_all_packs(ds->repo->objects->packfiles); p && !ds->ambiguous;
p = p->next) p = p->next)
unique_in_pack(p, ds); unique_in_pack(p, ds);
} }
@@ -805,7 +805,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
find_abbrev_len_for_midx(m, mad); find_abbrev_len_for_midx(m, mad);
} }
for (p = packfile_store_get_packs(mad->repo->objects->packfiles); p; p = p->next) for (p = packfile_store_get_all_packs(mad->repo->objects->packfiles); p; p = p->next)
find_abbrev_len_for_pack(p, mad); find_abbrev_len_for_pack(p, mad);
} }