odb: move kept cache into `struct packfile_store`
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>
Patrick Steinhardt committed
Sep 23, 2025 at 12:17 UTC
bd1a521de869dc9b26ca88efc5eae022222918c1
3 files changed
+23
-17
odb.h
+1
-9
@@ -131,16 +131,8 @@ struct object_database {
131
struct commit_graph *commit_graph;
132
unsigned commit_graph_attempted : 1; /* if loading has been attempted */
133
134
- /*
135
- * private data
136
- *
137
- * Should only be accessed directly by packfile.c and midx.c.
138
- */
134
+ /* Should only be accessed directly by packfile.c and midx.c. */
135
struct packfile_store *packfiles;
140
- struct {
141
- struct packed_git **packs;
142
- unsigned flags;
143
- } kept_pack_cache;
136
137
/*
138
* This is meant to hold a *small* number of objects that you would
packfile.c
+8
-8
@@ -2091,19 +2091,19 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
2091
static void maybe_invalidate_kept_pack_cache(struct repository *r,
2092
unsigned flags)
2093
{
2094
- if (!r->objects->kept_pack_cache.packs)
2094
+ if (!r->objects->packfiles->kept_cache.packs)
2095
return;
2096
- if (r->objects->kept_pack_cache.flags == flags)
2096
+ if (r->objects->packfiles->kept_cache.flags == flags)
2097
return;
2098
- FREE_AND_NULL(r->objects->kept_pack_cache.packs);
2099
- r->objects->kept_pack_cache.flags = 0;
2098
+ FREE_AND_NULL(r->objects->packfiles->kept_cache.packs);
2099
+ r->objects->packfiles->kept_cache.flags = 0;
2100
}
2101
2102
struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
2103
{
2104
maybe_invalidate_kept_pack_cache(r, flags);
2105
2106
- if (!r->objects->kept_pack_cache.packs) {
2106
+ if (!r->objects->packfiles->kept_cache.packs) {
2107
struct packed_git **packs = NULL;
2108
size_t nr = 0, alloc = 0;
2109
struct packed_git *p;
@@ -2126,11 +2126,11 @@ struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
2126
ALLOC_GROW(packs, nr + 1, alloc);
2127
packs[nr] = NULL;
2128
2129
- r->objects->kept_pack_cache.packs = packs;
2130
- r->objects->kept_pack_cache.flags = flags;
2129
+ r->objects->packfiles->kept_cache.packs = packs;
2130
+ r->objects->packfiles->kept_cache.flags = flags;
2131
}
2132
2133
- return r->objects->kept_pack_cache.packs;
2133
+ return r->objects->packfiles->kept_cache.packs;
2134
}
2135
2136
int find_kept_pack_entry(struct repository *r,
packfile.h
+14
@@ -64,6 +64,20 @@ struct packfile_store {
64
*/
65
struct packed_git *packs;
66
67
+ /*
68
+ * Cache of packfiles which are marked as "kept", either because there
69
+ * is an on-disk ".keep" file or because they are marked as "kept" in
70
+ * memory.
71
+ *
72
+ * Should not be accessed directly, but via `kept_pack_cache()`. The
73
+ * list of packs gets invalidated when the stored flags and the flags
74
+ * passed to `kept_pack_cache()` mismatch.
75
+ */
76
+ struct {
77
+ struct packed_git **packs;
78
+ unsigned flags;
79
+ } kept_cache;
80
+
81
/* A most-recently-used ordered version of the packs list. */
82
struct list_head mru;
83