packfile: create store via its owning source
In subsequent patches we're about to move the packfile store from the object database layer into the object database source layer. Once done, we'll have one packfile store per source, where the source is owning the store. Prepare for this future and refactor `packfile_store_new()` to be initialized via an object database source instead of via the object database itself. This refactoring leads to a weird in-between state where the store is owned by the object database but created via the source. But this makes subsequent refactorings easier because we can now start to access the owning source of a given store. 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
480336a9cec8701103a815289304ea626416043a
3 files changed
+14
-14
odb.c
+1
-1
@@ -1056,7 +1056,6 @@ struct object_database *odb_new(struct repository *repo,
1056
1057
memset(o, 0, sizeof(*o));
1058
o->repo = repo;
1059
- o->packfiles = packfile_store_new(o);
1059
pthread_mutex_init(&o->replace_mutex, NULL);
1060
string_list_init_dup(&o->submodule_source_paths);
1061
@@ -1065,6 +1064,7 @@ struct object_database *odb_new(struct repository *repo,
1064
o->sources = odb_source_new(o, primary_source, true);
1065
o->sources_tail = &o->sources->next;
1066
o->alternate_db = xstrdup_or_null(secondary_sources);
1067
+ o->packfiles = packfile_store_new(o->sources);
1068
1069
free(to_free);
1070
packfile.c
+10
-10
@@ -876,7 +876,7 @@ struct packed_git *packfile_store_load_pack(struct packfile_store *store,
876
877
p = strmap_get(&store->packs_by_path, key.buf);
878
if (!p) {
879
- p = add_packed_git(store->odb->repo, idx_path,
879
+ p = add_packed_git(store->source->odb->repo, idx_path,
880
strlen(idx_path), local);
881
if (p)
882
packfile_store_add_pack(store, p);
@@ -1068,8 +1068,8 @@ void packfile_store_prepare(struct packfile_store *store)
1068
if (store->initialized)
1069
return;
1070
1071
- odb_prepare_alternates(store->odb);
1072
- for (source = store->odb->sources; source; source = source->next) {
1071
+ odb_prepare_alternates(store->source->odb);
1072
+ for (source = store->source->odb->sources; source; source = source->next) {
1073
prepare_multi_pack_index_one(source);
1074
prepare_packed_git_one(source);
1075
}
@@ -1092,7 +1092,7 @@ struct packfile_list_entry *packfile_store_get_packs(struct packfile_store *stor
1092
{
1093
packfile_store_prepare(store);
1094
1095
- for (struct odb_source *source = store->odb->sources; source; source = source->next) {
1095
+ for (struct odb_source *source = store->source->odb->sources; source; source = source->next) {
1096
struct multi_pack_index *m = source->midx;
1097
if (!m)
1098
continue;
@@ -2121,7 +2121,7 @@ int packfile_store_freshen_object(struct packfile_store *store,
2121
const struct object_id *oid)
2122
{
2123
struct pack_entry e;
2124
- if (!find_pack_entry(store->odb->repo, oid, &e))
2124
+ if (!find_pack_entry(store->source->odb->repo, oid, &e))
2125
return 0;
2126
if (e.p->is_cruft)
2127
return 0;
@@ -2142,7 +2142,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
2142
struct pack_entry e;
2143
int rtype;
2144
2145
- if (!find_pack_entry(store->odb->repo, oid, &e))
2145
+ if (!find_pack_entry(store->source->odb->repo, oid, &e))
2146
return 1;
2147
2148
/*
@@ -2152,7 +2152,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
2152
if (oi == &blank_oi)
2153
return 0;
2154
2155
- rtype = packed_object_info(store->odb->repo, e.p, e.offset, oi);
2155
+ rtype = packed_object_info(store->source->odb->repo, e.p, e.offset, oi);
2156
if (rtype < 0) {
2157
mark_bad_packed_object(e.p, oid);
2158
return -1;
@@ -2411,11 +2411,11 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
2411
return 0;
2412
}
2413
2414
-struct packfile_store *packfile_store_new(struct object_database *odb)
2414
+struct packfile_store *packfile_store_new(struct odb_source *source)
2415
{
2416
struct packfile_store *store;
2417
CALLOC_ARRAY(store, 1);
2418
- store->odb = odb;
2418
+ store->source = source;
2419
strmap_init(&store->packs_by_path);
2420
return store;
2421
}
@@ -2534,7 +2534,7 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
2534
2535
if (packfile_store_read_object_info(store, oid, &oi, 0) ||
2536
oi.u.packed.is_delta ||
2537
- repo_settings_get_big_file_threshold(store->odb->repo) >= size)
2537
+ repo_settings_get_big_file_threshold(store->source->odb->repo) >= size)
2538
return -1;
2539
2540
in_pack_type = unpack_object_header(oi.u.packed.pack,
packfile.h
+3
-3
@@ -77,7 +77,7 @@ struct packed_git *packfile_list_find_oid(struct packfile_list_entry *packs,
77
* A store that manages packfiles for a given object database.
78
*/
79
struct packfile_store {
80
- struct object_database *odb;
80
+ struct odb_source *source;
81
82
/*
83
* The list of packfiles in the order in which they have been most
@@ -129,9 +129,9 @@ struct packfile_store {
129
130
/*
131
* Allocate and initialize a new empty packfile store for the given object
132
- * database.
132
+ * database source.
133
*/
134
-struct packfile_store *packfile_store_new(struct object_database *odb);
134
+struct packfile_store *packfile_store_new(struct odb_source *source);
135
136
/*
137
* Free the packfile store and all its associated state. All packfiles