Skip to content

Commit 6354d4c

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 445952b commit 6354d4c

File tree

5 files changed

+19
-25
lines changed

5 files changed

+19
-25
lines changed

midx.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,
9696
struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
9797
{
9898
packfile_store_prepare(source->packfiles);
99-
return source->midx;
99+
return source->packfiles->midx;
100100
}
101101

102102
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)
709709
if (!r->settings.core_multi_pack_index)
710710
return 0;
711711

712-
if (source->midx)
712+
if (source->packfiles->midx)
713713
return 1;
714714

715-
source->midx = load_multi_pack_index(source);
715+
source->packfiles->midx = load_multi_pack_index(source);
716716

717-
return !!source->midx;
717+
return !!source->packfiles->midx;
718718
}
719719

720720
int midx_checksum_valid(struct multi_pack_index *m)
@@ -803,9 +803,9 @@ void clear_midx_file(struct repository *r)
803803
struct odb_source *source;
804804

805805
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;
809809
}
810810
}
811811

odb.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,14 +1078,8 @@ struct object_database *odb_new(struct repository *repo,
10781078
void odb_close(struct object_database *o)
10791079
{
10801080
struct odb_source *source;
1081-
1082-
for (source = o->sources; source; source = source->next) {
1081+
for (source = o->sources; source; source = source->next)
10831082
packfile_store_close(source->packfiles);
1084-
if (source->midx)
1085-
close_midx(source->midx);
1086-
source->midx = NULL;
1087-
}
1088-
10891083
close_commit_graph(o);
10901084
}
10911085

odb.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ struct odb_source {
5454
/* Should only be accessed directly by packfile.c and midx.c. */
5555
struct packfile_store *packfiles;
5656

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-
6457
/*
6558
* Figure out whether this is the local source of the owning
6659
* repository, which would typically be its ".git/objects" directory.

packfile.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
990990
size_t base_len = full_name_len;
991991

992992
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))) {
994995
char *trimmed_path = xstrndup(full_name, full_name_len);
995996
packfile_store_load_pack(data->source->packfiles,
996997
trimmed_path, data->source->local);
@@ -1087,8 +1088,8 @@ struct packfile_list_entry *packfile_store_get_packs(struct packfile_store *stor
10871088
{
10881089
packfile_store_prepare(store);
10891090

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;
10921093
for (uint32_t i = 0; i < m->num_packs + m->num_packs_in_base; i++)
10931094
prepare_midx_pack(m, i);
10941095
}
@@ -2094,7 +2095,7 @@ static int find_pack_entry(struct packfile_store *store,
20942095
struct packfile_list_entry *l;
20952096

20962097
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))
20982099
return 1;
20992100

21002101
for (l = store->packs.head; l; l = l->next) {
@@ -2454,6 +2455,9 @@ void packfile_store_close(struct packfile_store *store)
24542455
BUG("want to close pack marked 'do-not-close'");
24552456
close_pack(e->pack);
24562457
}
2458+
if (store->midx)
2459+
close_midx(store->midx);
2460+
store->midx = NULL;
24572461
}
24582462

24592463
struct odb_packed_read_stream {

packfile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ struct packfile_store {
100100
unsigned flags;
101101
} kept_cache;
102102

103+
/* The multi-pack index that belongs to this specific packfile store. */
104+
struct multi_pack_index *midx;
105+
103106
/*
104107
* A map of packfile names to packed_git structs for tracking which
105108
* packs have been loaded already.

0 commit comments

Comments
 (0)