]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: introduce a new `struct packfile_store`
authorPatrick Steinhardt <ps@pks.im>
Tue, 23 Sep 2025 10:17:00 +0000 (12:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Sep 2025 18:53:48 +0000 (11:53 -0700)
Information about an object database's packfiles is currently
distributed across two different structures:

  - `struct packed_git` contains the `next` pointer as well as the
    `mru_head`, both of which serve to store the list of packfiles.

  - `struct object_database` contains several fields that relate to the
    packfiles.

So we don't really have a central data structure that tracks our
packfiles, and consequently responsibilities aren't always clear cut.
A consequence for the upcoming pluggable object databases is that this
makes it very hard to move management of packfiles from the object
database level down into the object database source.

Introduce a new `struct packfile_store` which is about to become the
single source of truth for managing packfiles. Right now this data
structure doesn't yet contain anything, but in subsequent patches we
will move all data structures that relate to packfiles and that are
currently contained in `struct object_database` into this new home.

Note that this is only a first step: most importantly, we won't (yet)
move the `struct packed_git::next` pointer around. This will happen in a
subsequent patch series though so that `struct packed_git` will really
only host information about the specific packfile it represents.

Further note that the new structure still sits at the wrong level at the
end of this patch series: as mentioned, it should eventually sit at the
level of the object database source, not at the object database level.
But introducing the packfile store now already makes it way easier to
eventually push down the now-selfcontained data structure by one level.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
odb.c
odb.h
packfile.c
packfile.h

diff --git a/odb.c b/odb.c
index 75c443fe665be5ba3c857e420d61fa80b83421b9..a2289ea97df39b6673a43289cd8a8b7f95e1a7a8 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -996,6 +996,7 @@ struct object_database *odb_new(struct repository *repo)
 
        memset(o, 0, sizeof(*o));
        o->repo = repo;
+       o->packfiles = packfile_store_new(o);
        INIT_LIST_HEAD(&o->packed_git_mru);
        hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
        pthread_mutex_init(&o->replace_mutex, NULL);
diff --git a/odb.h b/odb.h
index 51fe8a5a929f16dc3e1845a8293455f5b49c751e..33034eaf2fea8a88d15a7111ce60c26863501652 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -91,6 +91,7 @@ struct odb_source {
 };
 
 struct packed_git;
+struct packfile_store;
 struct cached_object_entry;
 
 /*
@@ -136,7 +137,7 @@ struct object_database {
         *
         * should only be accessed directly by packfile.c
         */
-
+       struct packfile_store *packfiles;
        struct packed_git *packed_git;
        /* A most-recently-used ordered version of the packed_git list. */
        struct list_head packed_git_mru;
index acb680966dacf913b172873c6f9dfbd1a8f4157e..130d3e25073118a45a2e90dafa7d88371f709944 100644 (file)
@@ -2332,3 +2332,16 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
        *len = hdr - out;
        return 0;
 }
+
+struct packfile_store *packfile_store_new(struct object_database *odb)
+{
+       struct packfile_store *store;
+       CALLOC_ARRAY(store, 1);
+       store->odb = odb;
+       return store;
+}
+
+void packfile_store_free(struct packfile_store *store)
+{
+       free(store);
+}
index f16753f2a9bb4c18e832041a9145a3a5c79f492c..8d31fd619ad249e0899aeec81c21ff3db94a4ef2 100644 (file)
@@ -52,6 +52,24 @@ struct packed_git {
        char pack_name[FLEX_ARRAY]; /* more */
 };
 
+/*
+ * A store that manages packfiles for a given object database.
+ */
+struct packfile_store {
+       struct object_database *odb;
+};
+
+/*
+ * Allocate and initialize a new empty packfile store for the given object
+ * database.
+ */
+struct packfile_store *packfile_store_new(struct object_database *odb);
+
+/*
+ * Free the packfile store and all its associated state.
+ */
+void packfile_store_free(struct packfile_store *store);
+
 static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
                                     const struct hashmap_entry *entry,
                                     const struct hashmap_entry *entry2,