packfile: introduce macro to iterate through packs

We have a bunch of different sites that want to iterate through all
packs of a given `struct packfile_store`. This pattern is somewhat
verbose and repetitive, which makes it somewhat cumbersome.

Introduce a new macro `repo_for_each_pack()` that removes some of the
boilerplate.

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:39 +02:00
committed by Junio C Hamano
parent 5b410c8276
commit 86d8c62f48
20 changed files with 57 additions and 75 deletions

View File

@@ -213,9 +213,11 @@ static void find_short_packed_object(struct disambiguate_state *ds)
unique_in_midx(m, ds);
}
for (p = packfile_store_get_all_packs(ds->repo->objects->packfiles); p && !ds->ambiguous;
p = p->next)
repo_for_each_pack(ds->repo, p) {
if (ds->ambiguous)
break;
unique_in_pack(p, ds);
}
}
static int finish_object_disambiguation(struct disambiguate_state *ds,
@@ -805,7 +807,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
find_abbrev_len_for_midx(m, mad);
}
for (p = packfile_store_get_all_packs(mad->repo->objects->packfiles); p; p = p->next)
repo_for_each_pack(mad->repo, p)
find_abbrev_len_for_pack(p, mad);
}