odb/source-packed: store pointer to "files" instead of generic source

The `struct odb_source_packed` holds a pointer to its owning parent source. The way that Git is currently structured, this parent is always the "files" source. In subsequent commits we're going to detangle that so that the "packed" source doesn't have any owning parent source at all, which makes it usable as a completely standalone source. Detangling this mess is somewhat intricate though, and is made even more intricate because it's not always clear which kind of source one is holding at a specific point in time -- either the parent "files" source, or the child "packed" source. Make this relationship more explicit by storing a pointer to the "files" source instead of storing a pointer to a generic `struct odb_source`. This will help make subsequent steps a bit clearer by making it more obvious whether we're using the generic "base" source or the owning "files" source. Note that this is a temporary step, only. At the end of this series we will have dropped the "files" pointer completely. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 17, 2026 at 08:39 UTC 3ac21e6d825a642dcab826772b495f492148299c
4 files changed +11 -11
odb/source-files.c
+1 -1
@@ -269,7 +269,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
269 CALLOC_ARRAY(files, 1);
270 odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
271 files->loose = odb_source_loose_new(odb, path, local);
272 - files->packed = odb_source_packed_new(&files->base);
272 + files->packed = odb_source_packed_new(files);
273
274 files->base.free = odb_source_files_free;
275 files->base.close = odb_source_files_close;
odb/source-packed.c
+2 -2
@@ -1,11 +1,11 @@
1 #include "git-compat-util.h"
2 #include "odb/source-packed.h"
3
4 -struct odb_source_packed *odb_source_packed_new(struct odb_source *source)
4 +struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
5 {
6 struct odb_source_packed *store;
7 CALLOC_ARRAY(store, 1);
8 - store->source = source;
8 + store->files = parent;
9 strmap_init(&store->packs_by_path);
10 return store;
11 }
odb/source-packed.h
+2 -2
@@ -9,7 +9,7 @@
9 * A store that manages packfiles for a given object database.
10 */
11 struct odb_source_packed {
12 - struct odb_source *source;
12 + struct odb_source_files *files;
13
14 /*
15 * The list of packfiles in the order in which they have been most
@@ -67,6 +67,6 @@ struct odb_source_packed {
67 * Allocate and initialize a new empty packfile store for the given object
68 * database source.
69 */
70 -struct odb_source_packed *odb_source_packed_new(struct odb_source *source);
70 +struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent);
71
72 #endif
packfile.c
+6 -6
@@ -802,7 +802,7 @@ struct packed_git *packfile_store_load_pack(struct odb_source_packed *store,
802
803 p = strmap_get(&store->packs_by_path, key.buf);
804 if (!p) {
805 - p = add_packed_git(store->source->odb->repo, idx_path,
805 + p = add_packed_git(store->files->base.odb->repo, idx_path,
806 strlen(idx_path), local);
807 if (p)
808 packfile_store_add_pack(store, p);
@@ -990,8 +990,8 @@ void packfile_store_prepare(struct odb_source_packed *store)
990 if (store->initialized)
991 return;
992
993 - prepare_multi_pack_index_one(store->source);
994 - prepare_packed_git_one(store->source);
993 + prepare_multi_pack_index_one(&store->files->base);
994 + prepare_packed_git_one(&store->files->base);
995
996 sort_packs(&store->packs.head, sort_pack);
997 for (struct packfile_list_entry *e = store->packs.head; e; e = e->next)
@@ -1029,7 +1029,7 @@ int packfile_store_count_objects(struct odb_source_packed *store,
1029 unsigned long count = 0;
1030 int ret;
1031
1032 - m = get_multi_pack_index(store->source);
1032 + m = get_multi_pack_index(&store->files->base);
1033 if (m)
1034 count += m->num_objects + m->num_objects_in_base;
1035
@@ -2450,7 +2450,7 @@ static int packfile_store_for_each_prefixed_object(
2450
2451 store->skip_mru_updates = true;
2452
2453 - m = get_multi_pack_index(store->source);
2453 + m = get_multi_pack_index(&store->files->base);
2454 if (m) {
2455 ret = for_each_prefixed_object_in_midx(store, m, opts, data);
2456 if (ret)
@@ -2632,7 +2632,7 @@ int packfile_store_find_abbrev_len(struct odb_source_packed *store,
2632 struct packfile_list_entry *e;
2633 struct multi_pack_index *m;
2634
2635 - m = get_multi_pack_index(store->source);
2635 + m = get_multi_pack_index(&store->files->base);
2636 if (m)
2637 find_abbrev_len_for_midx(m, oid, min_len, &min_len);
2638