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

The `struct odb_source_loose` 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 "loose" source doesn't have any owning parent source at all so that it can be used 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 "loose" 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. Note that this is a temporary step, only. At the end of this series we will have dropped the parent pointer completely. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 1, 2026 at 10:20 UTC 1d451ba6fec076d357abf62607b97f585283030a
4 files changed +8 -7
object-file.c
+2 -2
@@ -178,7 +178,7 @@ static int open_loose_object(struct odb_source_loose *loose,
178 static struct strbuf buf = STRBUF_INIT;
179 int fd;
180
181 - *path = odb_loose_path(loose->source, &buf, oid);
181 + *path = odb_loose_path(&loose->files->base, &buf, oid);
182 fd = git_open(*path);
183 if (fd >= 0)
184 return fd;
@@ -189,7 +189,7 @@ static int open_loose_object(struct odb_source_loose *loose,
189 static int quick_has_loose(struct odb_source_loose *loose,
190 const struct object_id *oid)
191 {
192 - return !!oidtree_contains(odb_source_loose_cache(loose->source, oid), oid);
192 + return !!oidtree_contains(odb_source_loose_cache(&loose->files->base, oid), oid);
193 }
194
195 /*
odb/source-files.c
+1 -1
@@ -264,7 +264,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
264
265 CALLOC_ARRAY(files, 1);
266 odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
267 - files->loose = odb_source_loose_new(&files->base);
267 + files->loose = odb_source_loose_new(files);
268 files->packed = packfile_store_new(&files->base);
269
270 files->base.free = odb_source_files_free;
odb/source-loose.c
+2 -2
@@ -1,10 +1,10 @@
1 #include "git-compat-util.h"
2 #include "odb/source-loose.h"
3
4 -struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
4 +struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files)
5 {
6 struct odb_source_loose *loose;
7 CALLOC_ARRAY(loose, 1);
8 - loose->source = source;
8 + loose->files = files;
9 return loose;
10 }
odb/source-loose.h
+3 -2
@@ -3,6 +3,7 @@
3
4 #include "odb/source.h"
5
6 +struct odb_source_files;
7 struct object_database;
8 struct oidtree;
9
@@ -11,7 +12,7 @@ struct oidtree;
12 * file per object. This source is part of the files source.
13 */
14 struct odb_source_loose {
14 - struct odb_source *source;
15 + struct odb_source_files *files;
16
17 /*
18 * Used to store the results of readdir(3) calls when we are OK
@@ -29,6 +30,6 @@ struct odb_source_loose {
30 struct loose_object_map *map;
31 };
32
32 -struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
33 +struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files);
34
35 #endif