Skip to content

Commit bd1a521

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe835b0 commit bd1a521

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

odb.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,8 @@ struct object_database {
131131
struct commit_graph *commit_graph;
132132
unsigned commit_graph_attempted : 1; /* if loading has been attempted */
133133

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. */
139135
struct packfile_store *packfiles;
140-
struct {
141-
struct packed_git **packs;
142-
unsigned flags;
143-
} kept_pack_cache;
144136

145137
/*
146138
* This is meant to hold a *small* number of objects that you would

packfile.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,19 +2091,19 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
20912091
static void maybe_invalidate_kept_pack_cache(struct repository *r,
20922092
unsigned flags)
20932093
{
2094-
if (!r->objects->kept_pack_cache.packs)
2094+
if (!r->objects->packfiles->kept_cache.packs)
20952095
return;
2096-
if (r->objects->kept_pack_cache.flags == flags)
2096+
if (r->objects->packfiles->kept_cache.flags == flags)
20972097
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;
21002100
}
21012101

21022102
struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
21032103
{
21042104
maybe_invalidate_kept_pack_cache(r, flags);
21052105

2106-
if (!r->objects->kept_pack_cache.packs) {
2106+
if (!r->objects->packfiles->kept_cache.packs) {
21072107
struct packed_git **packs = NULL;
21082108
size_t nr = 0, alloc = 0;
21092109
struct packed_git *p;
@@ -2126,11 +2126,11 @@ struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
21262126
ALLOC_GROW(packs, nr + 1, alloc);
21272127
packs[nr] = NULL;
21282128

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;
21312131
}
21322132

2133-
return r->objects->kept_pack_cache.packs;
2133+
return r->objects->packfiles->kept_cache.packs;
21342134
}
21352135

21362136
int find_kept_pack_entry(struct repository *r,

packfile.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ struct packfile_store {
6464
*/
6565
struct packed_git *packs;
6666

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+
6781
/* A most-recently-used ordered version of the packs list. */
6882
struct list_head mru;
6983

0 commit comments

Comments
 (0)