]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: move kept cache into `struct packfile_store`
authorPatrick Steinhardt <ps@pks.im>
Tue, 23 Sep 2025 10:17:05 +0000 (12:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Sep 2025 18:53:49 +0000 (11:53 -0700)
The object database tracks a cache of "kept" packfiles, which is used by
git-pack-objects(1) to handle cruft objects. With the introduction of
the `struct packfile_store` we have a better place to host this cache
though.

Move the cache accordingly.

This moves the last bit of packfile-related state from the object
database into the packfile store. Adapt the comment for the `packfiles`
pointer in `struct object_database` to reflect this.

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

diff --git a/odb.h b/odb.h
index 3044b6a661369e0c1e3516ccdf86273be51a11cd..9dd7bb6bc3e5f897e68a35543c26ce4d25a1452c 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -131,16 +131,8 @@ struct object_database {
        struct commit_graph *commit_graph;
        unsigned commit_graph_attempted : 1; /* if loading has been attempted */
 
-       /*
-        * private data
-        *
-        * Should only be accessed directly by packfile.c and midx.c.
-        */
+       /* Should only be accessed directly by packfile.c and midx.c. */
        struct packfile_store *packfiles;
-       struct {
-               struct packed_git **packs;
-               unsigned flags;
-       } kept_pack_cache;
 
        /*
         * This is meant to hold a *small* number of objects that you would
index 861d7ffd6fa9db5095d6ec3d6cd0c329a894793c..95a78f267f1f304d6563bb3466774a3650d2defc 100644 (file)
@@ -2091,19 +2091,19 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
 static void maybe_invalidate_kept_pack_cache(struct repository *r,
                                             unsigned flags)
 {
-       if (!r->objects->kept_pack_cache.packs)
+       if (!r->objects->packfiles->kept_cache.packs)
                return;
-       if (r->objects->kept_pack_cache.flags == flags)
+       if (r->objects->packfiles->kept_cache.flags == flags)
                return;
-       FREE_AND_NULL(r->objects->kept_pack_cache.packs);
-       r->objects->kept_pack_cache.flags = 0;
+       FREE_AND_NULL(r->objects->packfiles->kept_cache.packs);
+       r->objects->packfiles->kept_cache.flags = 0;
 }
 
 struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
 {
        maybe_invalidate_kept_pack_cache(r, flags);
 
-       if (!r->objects->kept_pack_cache.packs) {
+       if (!r->objects->packfiles->kept_cache.packs) {
                struct packed_git **packs = NULL;
                size_t nr = 0, alloc = 0;
                struct packed_git *p;
@@ -2126,11 +2126,11 @@ struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
                ALLOC_GROW(packs, nr + 1, alloc);
                packs[nr] = NULL;
 
-               r->objects->kept_pack_cache.packs = packs;
-               r->objects->kept_pack_cache.flags = flags;
+               r->objects->packfiles->kept_cache.packs = packs;
+               r->objects->packfiles->kept_cache.flags = flags;
        }
 
-       return r->objects->kept_pack_cache.packs;
+       return r->objects->packfiles->kept_cache.packs;
 }
 
 int find_kept_pack_entry(struct repository *r,
index d48d46cc1bdce7e188121c349c8cad8df35329e4..bf66211986e436f417f52d9be7b8549d42ffc2dc 100644 (file)
@@ -64,6 +64,20 @@ struct packfile_store {
         */
        struct packed_git *packs;
 
+       /*
+        * Cache of packfiles which are marked as "kept", either because there
+        * is an on-disk ".keep" file or because they are marked as "kept" in
+        * memory.
+        *
+        * Should not be accessed directly, but via `kept_pack_cache()`. The
+        * list of packs gets invalidated when the stored flags and the flags
+        * passed to `kept_pack_cache()` mismatch.
+        */
+       struct {
+               struct packed_git **packs;
+               unsigned flags;
+       } kept_cache;
+
        /* A most-recently-used ordered version of the packs list. */
        struct list_head mru;