From 4d8be89d973b69a826911385c5cf3d40d347394b Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 15 Jul 2025 13:29:18 +0200 Subject: midx: start tracking per object database source Multi-pack indices are tracked via `struct multi_pack_index`. This data structure is stored as a linked list inside `struct object_database`, which is the global database that spans across all of the object sources. This layout causes two problems: - Object databases consist of multiple object sources (e.g. one source per alternate object directory), where each multi-pack index is specific to one of those sources. Regardless of that though, the MIDX is not tracked per source, but tracked globally for the whole object database. This creates a mismatch between the on-disk layout and how things are organized in the object database subsystems and makes some parts, like figuring out whether a source has an MIDX, quite awkward. - Multi-pack indices are an implementation detail of how efficient access for packfiles work. As such, they are neither relevant in the context of loose objects, nor in a potential future where we have pluggable backends. Refactor `prepare_multi_pack_index_one()` so that it works on a specific source, which allows us to easily store a pointer to the multi-pack index inside of it. For now, this pointer exists next to the existing linked list we have in the object database. Users will be adjusted in subsequent patches to instead use the per-source pointers. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- odb.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'odb.h') diff --git a/odb.h b/odb.h index e922f25680..f09dba1fe1 100644 --- a/odb.h +++ b/odb.h @@ -13,6 +13,7 @@ struct oidmap; struct oidtree; struct strbuf; struct repository; +struct multi_pack_index; /* * Compute the exact path an alternate is at and returns it. In case of @@ -55,6 +56,13 @@ struct odb_source { /* Map between object IDs for loose objects. */ struct loose_object_map *loose_map; + /* + * private data + * + * should only be accessed directly by packfile.c and midx.c + */ + struct multi_pack_index *midx; + /* * This is a temporary object store created by the tmp_objdir * facility. Disable ref updates since the objects in the store @@ -75,7 +83,6 @@ struct odb_source { }; struct packed_git; -struct multi_pack_index; struct cached_object_entry; /* -- cgit v1.2.3 From ec865d94d4615c00fbf9ac50f4274b1d3fbf73a6 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 15 Jul 2025 13:29:24 +0200 Subject: midx: remove now-unused linked list of multi-pack indices In the preceding commits we have migrated all users of the linked list of multi-pack indices to instead use those stored in the object database sources. Remove those now-unused pointers. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- midx.c | 18 ++---------------- midx.h | 2 -- odb.h | 7 ------- packfile.c | 1 - 4 files changed, 2 insertions(+), 26 deletions(-) (limited to 'odb.h') diff --git a/midx.c b/midx.c index 472d6bf17a..7d407682e6 100644 --- a/midx.c +++ b/midx.c @@ -726,7 +726,6 @@ int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id) int prepare_multi_pack_index_one(struct odb_source *source, int local) { struct repository *r = source->odb->repo; - struct multi_pack_index *m; prepare_repo_settings(r); if (!r->settings.core_multi_pack_index) @@ -735,21 +734,9 @@ int prepare_multi_pack_index_one(struct odb_source *source, int local) if (source->midx) return 1; - m = load_multi_pack_index(r, source->path, local); - if (m) { - struct multi_pack_index *mp = r->objects->multi_pack_index; - if (mp) { - m->next = mp->next; - mp->next = m; - } else { - r->objects->multi_pack_index = m; - } - source->midx = m; + source->midx = load_multi_pack_index(r, source->path, local); - return 1; - } - - return 0; + return !!source->midx; } int midx_checksum_valid(struct multi_pack_index *m) @@ -842,7 +829,6 @@ void clear_midx_file(struct repository *r) close_midx(source->midx); source->midx = NULL; } - r->objects->multi_pack_index = NULL; } if (remove_path(midx.buf)) diff --git a/midx.h b/midx.h index 639a6f50e4..076382de8a 100644 --- a/midx.h +++ b/midx.h @@ -35,8 +35,6 @@ struct odb_source; "GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL" struct multi_pack_index { - struct multi_pack_index *next; - const unsigned char *data; size_t data_len; diff --git a/odb.h b/odb.h index f09dba1fe1..09177bf430 100644 --- a/odb.h +++ b/odb.h @@ -123,13 +123,6 @@ struct object_database { struct commit_graph *commit_graph; unsigned commit_graph_attempted : 1; /* if loading has been attempted */ - /* - * private data - * - * should only be accessed directly by packfile.c and midx.c - */ - struct multi_pack_index *multi_pack_index; - /* * private data * diff --git a/packfile.c b/packfile.c index ff33692f4b..5d73932f50 100644 --- a/packfile.c +++ b/packfile.c @@ -375,7 +375,6 @@ void close_object_store(struct object_database *o) close_midx(source->midx); source->midx = NULL; } - o->multi_pack_index = NULL; close_commit_graph(o); } -- cgit v1.2.3