packfile: only prepare owning store in `packfile_store_prepare()`

When calling `packfile_store_prepare()` we prepare not only the provided packfile store, but also all those of all other sources part of the same object database. This was required when the store was still sitting on the object database level. But now that it sits on the source level it's not anymore. Refactor the code so that we only prepare the single packfile store passed by the caller. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 9, 2026 at 09:33 UTC 8384cbcb4c737c6d1c6becb40e439c398e3624b4
2 files changed +13 -20
builtin/grep.c
+8 -6
@@ -1213,12 +1213,14 @@ int cmd_grep(int argc,
1213 */
1214 if (recurse_submodules)
1215 repo_read_gitmodules(the_repository, 1);
1216 - /*
1217 - * Note: `packfile_store_prepare()` prepares stores from all
1218 - * sources. This will be fixed in a subsequent commit.
1219 - */
1220 - if (startup_info->have_repository)
1221 - packfile_store_prepare(the_repository->objects->sources->packfiles);
1216 +
1217 + if (startup_info->have_repository) {
1218 + struct odb_source *source;
1219 +
1220 + odb_prepare_alternates(the_repository->objects);
1221 + for (source = the_repository->objects->sources; source; source = source->next)
1222 + packfile_store_prepare(source->packfiles);
1223 + }
1224
1225 start_threads(&opt);
1226 } else {
packfile.c
+5 -14
@@ -1063,16 +1063,11 @@ static int sort_pack(const struct packfile_list_entry *a,
1063
1064 void packfile_store_prepare(struct packfile_store *store)
1065 {
1066 - struct odb_source *source;
1067 -
1066 if (store->initialized)
1067 return;
1068
1071 - odb_prepare_alternates(store->source->odb);
1072 - for (source = store->source->odb->sources; source; source = source->next) {
1073 - prepare_multi_pack_index_one(source);
1074 - prepare_packed_git_one(source);
1075 - }
1069 + prepare_multi_pack_index_one(store->source);
1070 + prepare_packed_git_one(store->source);
1071
1072 sort_packs(&store->packs.head, sort_pack);
1073 for (struct packfile_list_entry *e = store->packs.head; e; e = e->next)
@@ -2098,15 +2093,11 @@ static int find_pack_entry(struct repository *r,
2093 {
2094 struct odb_source *source;
2095
2101 - /*
2102 - * Note: `packfile_store_prepare()` prepares stores from all sources.
2103 - * This will be fixed in a subsequent commit.
2104 - */
2105 - packfile_store_prepare(r->objects->sources->packfiles);
2106 -
2107 - for (source = r->objects->sources; source; source = source->next)
2096 + for (source = r->objects->sources; source; source = source->next) {
2097 + packfile_store_prepare(r->objects->sources->packfiles);
2098 if (source->midx && fill_midx_entry(source->midx, oid, e))
2099 return 1;
2100 + }
2101
2102 for (source = r->objects->sources; source; source = source->next) {
2103 struct packfile_list_entry *l;