]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-loose: store pointer to "files" instead of generic source
authorPatrick Steinhardt <ps@pks.im>
Thu, 21 May 2026 08:22:22 +0000 (10:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 May 2026 13:35:18 +0000 (22:35 +0900)
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>
object-file.c
odb/source-files.c
odb/source-loose.c
odb/source-loose.h

index 641bd9c0799dec10bd2e998112395f87d68ccb69..7a1908bfc05cb5fe63390a195c9814573e139a67 100644 (file)
@@ -178,7 +178,7 @@ static int open_loose_object(struct odb_source_loose *loose,
        static struct strbuf buf = STRBUF_INIT;
        int fd;
 
-       *path = odb_loose_path(loose->source, &buf, oid);
+       *path = odb_loose_path(&loose->files->base, &buf, oid);
        fd = git_open(*path);
        if (fd >= 0)
                return fd;
@@ -189,7 +189,7 @@ static int open_loose_object(struct odb_source_loose *loose,
 static int quick_has_loose(struct odb_source_loose *loose,
                           const struct object_id *oid)
 {
-       return !!oidtree_contains(odb_source_loose_cache(loose->source, oid), oid);
+       return !!oidtree_contains(odb_source_loose_cache(&loose->files->base, oid), oid);
 }
 
 /*
index b5abd20e971e78b49f8ae3dfec2130e238bb5b62..185cc6903e35f2beda29b8fda023f1eb72e59947 100644 (file)
@@ -264,7 +264,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
 
        CALLOC_ARRAY(files, 1);
        odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
-       files->loose = odb_source_loose_new(&files->base);
+       files->loose = odb_source_loose_new(files);
        files->packed = packfile_store_new(&files->base);
 
        files->base.free = odb_source_files_free;
index b944d2181324ce1e96f118606721980bdafb62d2..c9e7414814814d2b00e91eb10fd1b56cc596fdaf 100644 (file)
@@ -1,10 +1,10 @@
 #include "git-compat-util.h"
 #include "odb/source-loose.h"
 
-struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
+struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files)
 {
        struct odb_source_loose *loose;
        CALLOC_ARRAY(loose, 1);
-       loose->source = source;
+       loose->files = files;
        return loose;
 }
index 8b4bac77ea39e8692b822aee1c42e577e00aa74d..bf61e767c8aab47a7d926822608453edbe083b25 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "odb/source.h"
 
+struct odb_source_files;
 struct object_database;
 struct oidtree;
 
@@ -11,7 +12,7 @@ struct oidtree;
  * file per object. This source is part of the files source.
  */
 struct odb_source_loose {
-       struct odb_source *source;
+       struct odb_source_files *files;
 
        /*
         * Used to store the results of readdir(3) calls when we are OK
@@ -29,6 +30,6 @@ struct odb_source_loose {
        struct loose_object_map *map;
 };
 
-struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
+struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files);
 
 #endif