]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: only prepare owning store in `packfile_store_prepare()`
authorPatrick Steinhardt <ps@pks.im>
Thu, 18 Dec 2025 06:55:26 +0000 (07:55 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Jan 2026 00:37:43 +0000 (09:37 +0900)
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>
builtin/grep.c
packfile.c

index 4855b871ddf368a5608f96374def41c81d6cd810..5b8b87b1ac4d7aca7534e37fb4c3bee045e3cdd1 100644 (file)
@@ -1213,12 +1213,14 @@ int cmd_grep(int argc,
                 */
                if (recurse_submodules)
                        repo_read_gitmodules(the_repository, 1);
-               /*
-                * Note: `packfile_store_prepare()` prepares stores from all
-                * sources. This will be fixed in a subsequent commit.
-                */
-               if (startup_info->have_repository)
-                       packfile_store_prepare(the_repository->objects->sources->packfiles);
+
+               if (startup_info->have_repository) {
+                       struct odb_source *source;
+
+                       odb_prepare_alternates(the_repository->objects);
+                       for (source = the_repository->objects->sources; source; source = source->next)
+                               packfile_store_prepare(source->packfiles);
+               }
 
                start_threads(&opt);
        } else {
index c46d53b75dbea77209149cc65ad200c434a912c8..23d8f7cb938ccad34b458a07c37e2d76f2ddd88a 100644 (file)
@@ -1063,16 +1063,11 @@ static int sort_pack(const struct packfile_list_entry *a,
 
 void packfile_store_prepare(struct packfile_store *store)
 {
-       struct odb_source *source;
-
        if (store->initialized)
                return;
 
-       odb_prepare_alternates(store->source->odb);
-       for (source = store->source->odb->sources; source; source = source->next) {
-               prepare_multi_pack_index_one(source);
-               prepare_packed_git_one(source);
-       }
+       prepare_multi_pack_index_one(store->source);
+       prepare_packed_git_one(store->source);
 
        sort_packs(&store->packs.head, sort_pack);
        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,
 {
        struct odb_source *source;
 
-       /*
-        * Note: `packfile_store_prepare()` prepares stores from all sources.
-        * This will be fixed in a subsequent commit.
-        */
-       packfile_store_prepare(r->objects->sources->packfiles);
-
-       for (source = r->objects->sources; source; source = source->next)
+       for (source = r->objects->sources; source; source = source->next) {
+               packfile_store_prepare(r->objects->sources->packfiles);
                if (source->midx && fill_midx_entry(source->midx, oid, e))
                        return 1;
+       }
 
        for (source = r->objects->sources; source; source = source->next) {
                struct packfile_list_entry *l;