]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: move MIDX into packfile store
authorPatrick Steinhardt <ps@pks.im>
Thu, 18 Dec 2025 06:55:29 +0000 (07:55 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Dec 2025 11:34:38 +0000 (20:34 +0900)
The multi-pack index still is tracked as a member of the object database
source, but ultimately the MIDX is always tied to one specific packfile
store.

Move the structure into `struct packfile_store` accordingly. This
ensures that the packfile store now keeps track of all data related to
packfiles.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
odb.c
odb.h
packfile.c
packfile.h

diff --git a/midx.c b/midx.c
index dbb2aa68baa9a761f27dc2ee61931a7962cfb64e..fa7a7e5d13f90ede0805b60e31eb49bfff16fb7e 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -96,7 +96,7 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,
 struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
 {
        packfile_store_prepare(source->packfiles);
-       return source->midx;
+       return source->packfiles->midx;
 }
 
 static struct multi_pack_index *load_multi_pack_index_one(struct odb_source *source,
@@ -709,12 +709,12 @@ int prepare_multi_pack_index_one(struct odb_source *source)
        if (!r->settings.core_multi_pack_index)
                return 0;
 
-       if (source->midx)
+       if (source->packfiles->midx)
                return 1;
 
-       source->midx = load_multi_pack_index(source);
+       source->packfiles->midx = load_multi_pack_index(source);
 
-       return !!source->midx;
+       return !!source->packfiles->midx;
 }
 
 int midx_checksum_valid(struct multi_pack_index *m)
@@ -803,9 +803,9 @@ void clear_midx_file(struct repository *r)
                struct odb_source *source;
 
                for (source = r->objects->sources; source; source = source->next) {
-                       if (source->midx)
-                               close_midx(source->midx);
-                       source->midx = NULL;
+                       if (source->packfiles->midx)
+                               close_midx(source->packfiles->midx);
+                       source->packfiles->midx = NULL;
                }
        }
 
diff --git a/odb.c b/odb.c
index f159fbdd991bd10b14ca3dcd7d9e51f6ddc767c5..902251f9edb72a948439a5e24554100d1554f593 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -1078,14 +1078,8 @@ struct object_database *odb_new(struct repository *repo,
 void odb_close(struct object_database *o)
 {
        struct odb_source *source;
-
-       for (source = o->sources; source; source = source->next) {
+       for (source = o->sources; source; source = source->next)
                packfile_store_close(source->packfiles);
-               if (source->midx)
-                       close_midx(source->midx);
-               source->midx = NULL;
-       }
-
        close_commit_graph(o);
 }
 
diff --git a/odb.h b/odb.h
index c97b41c58cd44755696d6e857118d64a399298d7..300c3c0c46cb228c3b7819f0c4746755bca4d35b 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -54,13 +54,6 @@ struct odb_source {
        /* Should only be accessed directly by packfile.c and midx.c. */
        struct packfile_store *packfiles;
 
-       /*
-        * private data
-        *
-        * should only be accessed directly by packfile.c and midx.c
-        */
-       struct multi_pack_index *midx;
-
        /*
         * Figure out whether this is the local source of the owning
         * repository, which would typically be its ".git/objects" directory.
index 0e4c63e11d1d4d59847c640c87f4c8cf9a4e719f..097dd8d85d374ee65776f757c44389be4fa7490b 100644 (file)
@@ -990,7 +990,8 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
        size_t base_len = full_name_len;
 
        if (strip_suffix_mem(full_name, &base_len, ".idx") &&
-           !(data->source->midx && midx_contains_pack(data->source->midx, file_name))) {
+           !(data->source->packfiles->midx &&
+             midx_contains_pack(data->source->packfiles->midx, file_name))) {
                char *trimmed_path = xstrndup(full_name, full_name_len);
                packfile_store_load_pack(data->source->packfiles,
                                         trimmed_path, data->source->local);
@@ -1087,8 +1088,8 @@ struct packfile_list_entry *packfile_store_get_packs(struct packfile_store *stor
 {
        packfile_store_prepare(store);
 
-       if (store->source->midx) {
-               struct multi_pack_index *m = store->source->midx;
+       if (store->midx) {
+               struct multi_pack_index *m = store->midx;
                for (uint32_t i = 0; i < m->num_packs + m->num_packs_in_base; i++)
                        prepare_midx_pack(m, i);
        }
@@ -2094,7 +2095,7 @@ static int find_pack_entry(struct packfile_store *store,
        struct packfile_list_entry *l;
 
        packfile_store_prepare(store);
-       if (store->source->midx && fill_midx_entry(store->source->midx, oid, e))
+       if (store->midx && fill_midx_entry(store->midx, oid, e))
                return 1;
 
        for (l = store->packs.head; l; l = l->next) {
@@ -2454,6 +2455,9 @@ void packfile_store_close(struct packfile_store *store)
                        BUG("want to close pack marked 'do-not-close'");
                close_pack(e->pack);
        }
+       if (store->midx)
+               close_midx(store->midx);
+       store->midx = NULL;
 }
 
 struct odb_packed_read_stream {
index 08a666d538213ef5e500e345afe7377deb51c0d6..92baf8ee88ef88c2065b5afd1c87cecb4e351f5d 100644 (file)
@@ -101,6 +101,9 @@ struct packfile_store {
                unsigned flags;
        } kept_cache;
 
+       /* The multi-pack index that belongs to this specific packfile store. */
+       struct multi_pack_index *midx;
+
        /*
         * A map of packfile names to packed_git structs for tracking which
         * packs have been loaded already.