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>
This commit is contained in:
Patrick Steinhardt 2026-01-09 09:33:18 +01:00 committed by Junio C Hamano
parent a593373b09
commit a282a8f163
5 changed files with 19 additions and 25 deletions

14
midx.c
View File

@ -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;
}
}

8
odb.c
View File

@ -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);
}

7
odb.h
View File

@ -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.

View 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 {

View 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.