Skip to content

Commit 4d8be89

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c29998d commit 4d8be89

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

midx.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,28 +724,29 @@ int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id)
724724
return 0;
725725
}
726726

727-
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local)
727+
int prepare_multi_pack_index_one(struct odb_source *source, int local)
728728
{
729+
struct repository *r = source->odb->repo;
729730
struct multi_pack_index *m;
730-
struct multi_pack_index *m_search;
731731

732732
prepare_repo_settings(r);
733733
if (!r->settings.core_multi_pack_index)
734734
return 0;
735735

736-
for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next)
737-
if (!strcmp(object_dir, m_search->object_dir))
738-
return 1;
739-
740-
m = load_multi_pack_index(r, object_dir, local);
736+
if (source->midx)
737+
return 1;
741738

739+
m = load_multi_pack_index(r, source->path, local);
742740
if (m) {
743741
struct multi_pack_index *mp = r->objects->multi_pack_index;
744742
if (mp) {
745743
m->next = mp->next;
746744
mp->next = m;
747-
} else
745+
} else {
748746
r->objects->multi_pack_index = m;
747+
}
748+
source->midx = m;
749+
749750
return 1;
750751
}
751752

@@ -837,6 +838,8 @@ void clear_midx_file(struct repository *r)
837838
if (r->objects && r->objects->multi_pack_index) {
838839
close_midx(r->objects->multi_pack_index);
839840
r->objects->multi_pack_index = NULL;
841+
for (struct odb_source *source = r->objects->sources; source; source = source->next)
842+
source->midx = NULL;
840843
}
841844

842845
if (remove_path(midx.buf))

midx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct pack_entry;
88
struct repository;
99
struct bitmapped_pack;
1010
struct git_hash_algo;
11+
struct odb_source;
1112

1213
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
1314
#define MIDX_VERSION 1
@@ -123,7 +124,7 @@ int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pa
123124
int midx_contains_pack(struct multi_pack_index *m,
124125
const char *idx_or_pack_name);
125126
int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
126-
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
127+
int prepare_multi_pack_index_one(struct odb_source *source, int local);
127128

128129
/*
129130
* Variant of write_midx_file which writes a MIDX containing only the packs

odb.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct oidmap;
1313
struct oidtree;
1414
struct strbuf;
1515
struct repository;
16+
struct multi_pack_index;
1617

1718
/*
1819
* Compute the exact path an alternate is at and returns it. In case of
@@ -55,6 +56,13 @@ struct odb_source {
5556
/* Map between object IDs for loose objects. */
5657
struct loose_object_map *loose_map;
5758

59+
/*
60+
* private data
61+
*
62+
* should only be accessed directly by packfile.c and midx.c
63+
*/
64+
struct multi_pack_index *midx;
65+
5866
/*
5967
* This is a temporary object store created by the tmp_objdir
6068
* facility. Disable ref updates since the objects in the store
@@ -75,7 +83,6 @@ struct odb_source {
7583
};
7684

7785
struct packed_git;
78-
struct multi_pack_index;
7986
struct cached_object_entry;
8087

8188
/*

packfile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ void close_object_store(struct object_database *o)
372372
if (o->multi_pack_index) {
373373
close_midx(o->multi_pack_index);
374374
o->multi_pack_index = NULL;
375+
for (struct odb_source *source = o->sources; source; source = source->next)
376+
source->midx = NULL;
375377
}
376378

377379
close_commit_graph(o);
@@ -1037,7 +1039,7 @@ static void prepare_packed_git(struct repository *r)
10371039
odb_prepare_alternates(r->objects);
10381040
for (source = r->objects->sources; source; source = source->next) {
10391041
int local = (source == r->objects->sources);
1040-
prepare_multi_pack_index_one(r, source->path, local);
1042+
prepare_multi_pack_index_one(source, local);
10411043
prepare_packed_git_one(r, source->path, local);
10421044
}
10431045
rearrange_packed_git(r);

0 commit comments

Comments
 (0)