]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-packed: store pointer to "files" instead of generic source
authorPatrick Steinhardt <ps@pks.im>
Wed, 17 Jun 2026 06:39:47 +0000 (08:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Jun 2026 12:00:00 +0000 (05:00 -0700)
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>
odb/source-files.c
odb/source-packed.c
odb/source-packed.h
packfile.c

index 191562f316743efbaa6631c3e67980b26b6a4d5e..e04525fb08be97bd9e11c8d5479b986eaf943b61 100644 (file)
@@ -269,7 +269,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(odb, path, local);
-       files->packed = odb_source_packed_new(&files->base);
+       files->packed = odb_source_packed_new(files);
 
        files->base.free = odb_source_files_free;
        files->base.close = odb_source_files_close;
index 1e94b47ea0bf2c7bea63843f444e0fffa8644bbd..12e785be48498a4fb51ca25bb9c9d7b09019ca80 100644 (file)
@@ -1,11 +1,11 @@
 #include "git-compat-util.h"
 #include "odb/source-packed.h"
 
-struct odb_source_packed *odb_source_packed_new(struct odb_source *source)
+struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
 {
        struct odb_source_packed *store;
        CALLOC_ARRAY(store, 1);
-       store->source = source;
+       store->files = parent;
        strmap_init(&store->packs_by_path);
        return store;
 }
index 327be4ad659b54f1fa41d040ccedda991c9fe129..3c2d229a174749ce91c6bab09254dddde53e9203 100644 (file)
@@ -9,7 +9,7 @@
  * A store that manages packfiles for a given object database.
  */
 struct odb_source_packed {
-       struct odb_source *source;
+       struct odb_source_files *files;
 
        /*
         * The list of packfiles in the order in which they have been most
@@ -67,6 +67,6 @@ struct odb_source_packed {
  * Allocate and initialize a new empty packfile store for the given object
  * database source.
  */
-struct odb_source_packed *odb_source_packed_new(struct odb_source *source);
+struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent);
 
 #endif
index 99be5789efbad4ce5433abb78f6fcfc954c6b872..862a24ad49bd784e56005b2d84f7d7ce369e8302 100644 (file)
@@ -802,7 +802,7 @@ struct packed_git *packfile_store_load_pack(struct odb_source_packed *store,
 
        p = strmap_get(&store->packs_by_path, key.buf);
        if (!p) {
-               p = add_packed_git(store->source->odb->repo, idx_path,
+               p = add_packed_git(store->files->base.odb->repo, idx_path,
                                   strlen(idx_path), local);
                if (p)
                        packfile_store_add_pack(store, p);
@@ -990,8 +990,8 @@ void packfile_store_prepare(struct odb_source_packed *store)
        if (store->initialized)
                return;
 
-       prepare_multi_pack_index_one(store->source);
-       prepare_packed_git_one(store->source);
+       prepare_multi_pack_index_one(&store->files->base);
+       prepare_packed_git_one(&store->files->base);
 
        sort_packs(&store->packs.head, sort_pack);
        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,
        unsigned long count = 0;
        int ret;
 
-       m = get_multi_pack_index(store->source);
+       m = get_multi_pack_index(&store->files->base);
        if (m)
                count += m->num_objects + m->num_objects_in_base;
 
@@ -2450,7 +2450,7 @@ static int packfile_store_for_each_prefixed_object(
 
        store->skip_mru_updates = true;
 
-       m = get_multi_pack_index(store->source);
+       m = get_multi_pack_index(&store->files->base);
        if (m) {
                ret = for_each_prefixed_object_in_midx(store, m, opts, data);
                if (ret)
@@ -2632,7 +2632,7 @@ int packfile_store_find_abbrev_len(struct odb_source_packed *store,
        struct packfile_list_entry *e;
        struct multi_pack_index *m;
 
-       m = get_multi_pack_index(store->source);
+       m = get_multi_pack_index(&store->files->base);
        if (m)
                find_abbrev_len_for_midx(m, oid, min_len, &min_len);