We have two different functions to retrieve packfiles for a packfile store: - `get_packed_git()` returns the list of packfiles directly. - `get_all_packs()` does more work and also prepares packfiles that are being indexed by a multi-pack-index. The distinction is not immediately obvious. Furthermore, to make the situation even worse, `get_packed_git()` would return the same result as `get_all_packs()` once the latter has been called once as they both refer to the same list. As it turns out, the distinction isn't necessary. We only have a couple of callers of `get_packed_git()`, and all of those callers are prepared to call `get_all_packs()` instead: - "builtin/gc.c": We explicitly check how many packfiles aren't contained in the multi-pack-index, so loading extra packfiles that are indexed by it won't change the result. - "builtin/grep.c": We only care `get_packed_git()` to prepare eagerly load packfiles. In the preceding commit we have started to expose `packfile_store_prepare()`, which is a more direct way of achieving the same result. - "object-name.c": `find_abbrev_len_for_pack()` and `unique_in_pack()` exit early in case the multi-pack index is set, so both callsites of `get_packed_git()` know to handle packs loaded via the MIDX already. Convert all of these sites to use `get_all_packs()` instead and remove `get_packed_git()`. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- builtin/gc.c | 2 +- builtin/grep.c | 2 +- object-name.c | 4 ++-- packfile.c | 6 ------ packfile.h | 1 - 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 1d30d1af2c..565afda51f 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1422,7 +1422,7 @@ static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED) if (incremental_repack_auto_limit < 0) return 1; - for (p = get_packed_git(the_repository); + for (p = get_all_packs(the_repository); count < incremental_repack_auto_limit && p; p = p->next) { if (!p->multi_pack_index) diff --git a/builtin/grep.c b/builtin/grep.c index 5df6537333..8f0e21bd70 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1214,7 +1214,7 @@ int cmd_grep(int argc, if (recurse_submodules) repo_read_gitmodules(the_repository, 1); if (startup_info->have_repository) - (void)get_packed_git(the_repository); + packfile_store_prepare(the_repository->objects->packfiles); start_threads(&opt); } else { diff --git a/object-name.c b/object-name.c index 44b0d416ac..c87995cc1e 100644 --- a/object-name.c +++ b/object-name.c @@ -213,7 +213,7 @@ static void find_short_packed_object(struct disambiguate_state *ds) unique_in_midx(m, ds); } - for (p = get_packed_git(ds->repo); p && !ds->ambiguous; + for (p = get_all_packs(ds->repo); p && !ds->ambiguous; p = p->next) unique_in_pack(p, ds); } @@ -806,7 +806,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad) find_abbrev_len_for_midx(m, mad); } - for (p = get_packed_git(mad->repo); p; p = p->next) + for (p = get_all_packs(mad->repo); p; p = p->next) find_abbrev_len_for_pack(p, mad); } diff --git a/packfile.c b/packfile.c index bc32c45fe6..f1526e361c 100644 --- a/packfile.c +++ b/packfile.c @@ -1029,12 +1029,6 @@ void packfile_store_reprepare(struct packfile_store *store) packfile_store_prepare(store); } -struct packed_git *get_packed_git(struct repository *r) -{ - packfile_store_prepare(r->objects->packfiles); - return r->objects->packfiles->packs; -} - struct packed_git *get_all_packs(struct repository *r) { packfile_store_prepare(r->objects->packfiles); diff --git a/packfile.h b/packfile.h index 1522da96f8..dff0237092 100644 --- a/packfile.h +++ b/packfile.h @@ -212,7 +212,6 @@ int for_each_packed_object(struct repository *repo, each_packed_object_fn cb, #define PACKDIR_FILE_GARBAGE 4 extern void (*report_garbage)(unsigned seen_bits, const char *path); -struct packed_git *get_packed_git(struct repository *r); struct list_head *get_packed_git_mru(struct repository *r); struct packed_git *get_all_packs(struct repository *r); -- 2.51.0.261.g7ce5a0a67e.dirty