packfile: move MIDX into packfile store

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>

Patrick Steinhardt committed Jan 9, 2026 at 09:33 UTC a282a8f163fa70f9eacc880e6188141cef917058
5 files changed +19 -25
midx.c
+7 -7
@@ -96,7 +96,7 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,
96 struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
97 {
98 packfile_store_prepare(source->packfiles);
99 - return source->midx;
99 + return source->packfiles->midx;
100 }
101
102 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)
709 if (!r->settings.core_multi_pack_index)
710 return 0;
711
712 - if (source->midx)
712 + if (source->packfiles->midx)
713 return 1;
714
715 - source->midx = load_multi_pack_index(source);
715 + source->packfiles->midx = load_multi_pack_index(source);
716
717 - return !!source->midx;
717 + return !!source->packfiles->midx;
718 }
719
720 int midx_checksum_valid(struct multi_pack_index *m)
@@ -803,9 +803,9 @@ void clear_midx_file(struct repository *r)
803 struct odb_source *source;
804
805 for (source = r->objects->sources; source; source = source->next) {
806 - if (source->midx)
807 - close_midx(source->midx);
808 - source->midx = NULL;
806 + if (source->packfiles->midx)
807 + close_midx(source->packfiles->midx);
808 + source->packfiles->midx = NULL;
809 }
810 }
811
odb.c
+1 -7
@@ -1078,14 +1078,8 @@ struct object_database *odb_new(struct repository *repo,
1078 void odb_close(struct object_database *o)
1079 {
1080 struct odb_source *source;
1081 -
1082 - for (source = o->sources; source; source = source->next) {
1081 + for (source = o->sources; source; source = source->next)
1082 packfile_store_close(source->packfiles);
1084 - if (source->midx)
1085 - close_midx(source->midx);
1086 - source->midx = NULL;
1087 - }
1088 -
1083 close_commit_graph(o);
1084 }
1085
odb.h
-7
@@ -54,13 +54,6 @@ struct odb_source {
54 /* Should only be accessed directly by packfile.c and midx.c. */
55 struct packfile_store *packfiles;
56
57 - /*
58 - * private data
59 - *
60 - * should only be accessed directly by packfile.c and midx.c
61 - */
62 - struct multi_pack_index *midx;
63 -
57 /*
58 * Figure out whether this is the local source of the owning
59 * repository, which would typically be its ".git/objects" directory.
packfile.c
+8 -4
@@ -990,7 +990,8 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
990 size_t base_len = full_name_len;
991
992 if (strip_suffix_mem(full_name, &base_len, ".idx") &&
993 - !(data->source->midx && midx_contains_pack(data->source->midx, file_name))) {
993 + !(data->source->packfiles->midx &&
994 + midx_contains_pack(data->source->packfiles->midx, file_name))) {
995 char *trimmed_path = xstrndup(full_name, full_name_len);
996 packfile_store_load_pack(data->source->packfiles,
997 trimmed_path, data->source->local);
@@ -1087,8 +1088,8 @@ struct packfile_list_entry *packfile_store_get_packs(struct packfile_store *stor
1088 {
1089 packfile_store_prepare(store);
1090
1090 - if (store->source->midx) {
1091 - struct multi_pack_index *m = store->source->midx;
1091 + if (store->midx) {
1092 + struct multi_pack_index *m = store->midx;
1093 for (uint32_t i = 0; i < m->num_packs + m->num_packs_in_base; i++)
1094 prepare_midx_pack(m, i);
1095 }
@@ -2094,7 +2095,7 @@ static int find_pack_entry(struct packfile_store *store,
2095 struct packfile_list_entry *l;
2096
2097 packfile_store_prepare(store);
2097 - if (store->source->midx && fill_midx_entry(store->source->midx, oid, e))
2098 + if (store->midx && fill_midx_entry(store->midx, oid, e))
2099 return 1;
2100
2101 for (l = store->packs.head; l; l = l->next) {
@@ -2454,6 +2455,9 @@ void packfile_store_close(struct packfile_store *store)
2455 BUG("want to close pack marked 'do-not-close'");
2456 close_pack(e->pack);
2457 }
2458 + if (store->midx)
2459 + close_midx(store->midx);
2460 + store->midx = NULL;
2461 }
2462
2463 struct odb_packed_read_stream {
packfile.h
+3
@@ -101,6 +101,9 @@ struct packfile_store {
101 unsigned flags;
102 } kept_cache;
103
104 + /* The multi-pack index that belongs to this specific packfile store. */
105 + struct multi_pack_index *midx;
106 +
107 /*
108 * A map of packfile names to packed_git structs for tracking which
109 * packs have been loaded already.