]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: move MRU list of packfiles into `struct packfile_store`
authorPatrick Steinhardt <ps@pks.im>
Tue, 23 Sep 2025 10:17:04 +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 the list of packfiles in most-recently-used
order, which is mostly used to favor reading from packfiles that contain
most of the objects that we're currently accessing. With the
introduction of the `struct packfile_store` we have a better place to
host this list though.

Move the list accordingly.

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

diff --git a/midx.c b/midx.c
index e96970efbfbb79fb72a13dbb50696c8d2552a228..91c7b3917d6b80e46013e2dea75bec499ff06fbf 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -468,7 +468,7 @@ int prepare_midx_pack(struct multi_pack_index *m,
                                   m->source->local);
                if (p) {
                        install_packed_git(r, p);
-                       list_add_tail(&p->mru, &r->objects->packed_git_mru);
+                       list_add_tail(&p->mru, &r->objects->packfiles->mru);
                }
        }
 
diff --git a/odb.c b/odb.c
index 737d98c91191af431458077ae882c81929da9dde..32e982bf0b98cb7eb36f5b4865deb554ccb03319 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -997,7 +997,6 @@ 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);
        pthread_mutex_init(&o->replace_mutex, NULL);
        string_list_init_dup(&o->submodule_source_paths);
        return o;
@@ -1035,7 +1034,6 @@ void odb_clear(struct object_database *o)
                free((char *) o->cached_objects[i].value.buf);
        FREE_AND_NULL(o->cached_objects);
 
-       INIT_LIST_HEAD(&o->packed_git_mru);
        close_object_store(o);
        packfile_store_free(o->packfiles);
        o->packfiles = NULL;
diff --git a/odb.h b/odb.h
index b79e7280c149cbc83eb2085e5aed2e05648270d2..3044b6a661369e0c1e3516ccdf86273be51a11cd 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -3,7 +3,6 @@
 
 #include "hashmap.h"
 #include "object.h"
-#include "list.h"
 #include "oidset.h"
 #include "oidmap.h"
 #include "string-list.h"
@@ -138,9 +137,6 @@ struct object_database {
         * Should only be accessed directly by packfile.c and midx.c.
         */
        struct packfile_store *packfiles;
-       /* A most-recently-used ordered version of the packed_git list. */
-       struct list_head packed_git_mru;
-
        struct {
                struct packed_git **packs;
                unsigned flags;
index 17e0b8ab27ece6ef89e60e5f9ee5b137b9bf0599..861d7ffd6fa9db5095d6ec3d6cd0c329a894793c 100644 (file)
@@ -1017,10 +1017,10 @@ static void prepare_packed_git_mru(struct repository *r)
 {
        struct packed_git *p;
 
-       INIT_LIST_HEAD(&r->objects->packed_git_mru);
+       INIT_LIST_HEAD(&r->objects->packfiles->mru);
 
        for (p = r->objects->packfiles->packs; p; p = p->next)
-               list_add_tail(&p->mru, &r->objects->packed_git_mru);
+               list_add_tail(&p->mru, &r->objects->packfiles->mru);
 }
 
 static void prepare_packed_git(struct repository *r)
@@ -1095,7 +1095,7 @@ struct packed_git *get_all_packs(struct repository *r)
 struct list_head *get_packed_git_mru(struct repository *r)
 {
        prepare_packed_git(r);
-       return &r->objects->packed_git_mru;
+       return &r->objects->packfiles->mru;
 }
 
 unsigned long unpack_object_header_buffer(const unsigned char *buf,
@@ -2078,10 +2078,10 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
        if (!r->objects->packfiles->packs)
                return 0;
 
-       list_for_each(pos, &r->objects->packed_git_mru) {
+       list_for_each(pos, &r->objects->packfiles->mru) {
                struct packed_git *p = list_entry(pos, struct packed_git, mru);
                if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
-                       list_move(&p->mru, &r->objects->packed_git_mru);
+                       list_move(&p->mru, &r->objects->packfiles->mru);
                        return 1;
                }
        }
@@ -2347,6 +2347,7 @@ struct packfile_store *packfile_store_new(struct object_database *odb)
        struct packfile_store *store;
        CALLOC_ARRAY(store, 1);
        store->odb = odb;
+       INIT_LIST_HEAD(&store->mru);
        hashmap_init(&store->map, pack_map_entry_cmp, NULL, 0);
        return store;
 }
index 9bbef5116477298fe7eb6d935848a56f4658ba5b..d48d46cc1bdce7e188121c349c8cad8df35329e4 100644 (file)
@@ -64,6 +64,9 @@ struct packfile_store {
         */
        struct packed_git *packs;
 
+       /* A most-recently-used ordered version of the packs list. */
+       struct list_head mru;
+
        /*
         * A map of packfile names to packed_git structs for tracking which
         * packs have been loaded already.