Skip to content

Commit 0ff5227

Browse files
pks-tgitster
authored andcommitted
packfile: refactor kept-pack cache to work with packfile stores
The kept pack cache is a cache of packfiles that are marked as kept either via an accompanying ".kept" file or via an in-memory flag. The cache can be retrieved via `kept_pack_cache()`, where one needs to pass in a repository. Ultimately though the kept-pack cache is a property of the packfile store, and this causes problems in a subsequent commit where we want to move down the packfile store to be a per-object-source entity. Prepare for this and refactor the kept-pack cache to work on top of a packfile store instead. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6869f5 commit 0ff5227

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed

builtin/pack-objects.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,9 @@ static int want_cruft_object_mtime(struct repository *r,
15291529
const struct object_id *oid,
15301530
unsigned flags, uint32_t mtime)
15311531
{
1532-
struct packed_git **cache;
1532+
struct packed_git **cache = packfile_store_get_kept_pack_cache(r->objects->packfiles, flags);
15331533

1534-
for (cache = kept_pack_cache(r, flags); *cache; cache++) {
1534+
for (; *cache; cache++) {
15351535
struct packed_git *p = *cache;
15361536
off_t ofs;
15371537
uint32_t candidate_mtime;
@@ -1624,9 +1624,9 @@ static int want_found_object(const struct object_id *oid, int exclude,
16241624
*/
16251625
unsigned flags = 0;
16261626
if (ignore_packed_keep_on_disk)
1627-
flags |= ON_DISK_KEEP_PACKS;
1627+
flags |= KEPT_PACK_ON_DISK;
16281628
if (ignore_packed_keep_in_core)
1629-
flags |= IN_CORE_KEEP_PACKS;
1629+
flags |= KEPT_PACK_IN_CORE;
16301630

16311631
/*
16321632
* If the object is in a pack that we want to ignore, *and* we
@@ -3931,7 +3931,7 @@ static void read_stdin_packs(enum stdin_packs_mode mode, int rev_list_unpacked)
39313931
* an optimization during delta selection.
39323932
*/
39333933
revs.no_kept_objects = 1;
3934-
revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
3934+
revs.keep_pack_cache_flags |= KEPT_PACK_IN_CORE;
39353935
revs.blob_objects = 1;
39363936
revs.tree_objects = 1;
39373937
revs.tag_objects = 1;
@@ -4030,7 +4030,7 @@ static void show_cruft_commit(struct commit *commit, void *data)
40304030

40314031
static int cruft_include_check_obj(struct object *obj, void *data UNUSED)
40324032
{
4033-
return !has_object_kept_pack(to_pack.repo, &obj->oid, IN_CORE_KEEP_PACKS);
4033+
return !has_object_kept_pack(to_pack.repo, &obj->oid, KEPT_PACK_IN_CORE);
40344034
}
40354035

40364036
static int cruft_include_check(struct commit *commit, void *data)

packfile.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,25 +2164,26 @@ int packfile_store_read_object_info(struct packfile_store *store,
21642164
return 0;
21652165
}
21662166

2167-
static void maybe_invalidate_kept_pack_cache(struct repository *r,
2167+
static void maybe_invalidate_kept_pack_cache(struct packfile_store *store,
21682168
unsigned flags)
21692169
{
2170-
if (!r->objects->packfiles->kept_cache.packs)
2170+
if (!store->kept_cache.packs)
21712171
return;
2172-
if (r->objects->packfiles->kept_cache.flags == flags)
2172+
if (store->kept_cache.flags == flags)
21732173
return;
2174-
FREE_AND_NULL(r->objects->packfiles->kept_cache.packs);
2175-
r->objects->packfiles->kept_cache.flags = 0;
2174+
FREE_AND_NULL(store->kept_cache.packs);
2175+
store->kept_cache.flags = 0;
21762176
}
21772177

2178-
struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
2178+
struct packed_git **packfile_store_get_kept_pack_cache(struct packfile_store *store,
2179+
unsigned flags)
21792180
{
2180-
maybe_invalidate_kept_pack_cache(r, flags);
2181+
maybe_invalidate_kept_pack_cache(store, flags);
21812182

2182-
if (!r->objects->packfiles->kept_cache.packs) {
2183+
if (!store->kept_cache.packs) {
21832184
struct packed_git **packs = NULL;
2185+
struct packfile_list_entry *e;
21842186
size_t nr = 0, alloc = 0;
2185-
struct packed_git *p;
21862187

21872188
/*
21882189
* We want "all" packs here, because we need to cover ones that
@@ -2192,31 +2193,33 @@ struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
21922193
* covers, one kept and one not kept, but the midx returns only
21932194
* the non-kept version.
21942195
*/
2195-
repo_for_each_pack(r, p) {
2196-
if ((p->pack_keep && (flags & ON_DISK_KEEP_PACKS)) ||
2197-
(p->pack_keep_in_core && (flags & IN_CORE_KEEP_PACKS))) {
2196+
for (e = packfile_store_get_packs(store); e; e = e->next) {
2197+
struct packed_git *p = e->pack;
2198+
2199+
if ((p->pack_keep && (flags & KEPT_PACK_ON_DISK)) ||
2200+
(p->pack_keep_in_core && (flags & KEPT_PACK_IN_CORE))) {
21982201
ALLOC_GROW(packs, nr + 1, alloc);
21992202
packs[nr++] = p;
22002203
}
22012204
}
22022205
ALLOC_GROW(packs, nr + 1, alloc);
22032206
packs[nr] = NULL;
22042207

2205-
r->objects->packfiles->kept_cache.packs = packs;
2206-
r->objects->packfiles->kept_cache.flags = flags;
2208+
store->kept_cache.packs = packs;
2209+
store->kept_cache.flags = flags;
22072210
}
22082211

2209-
return r->objects->packfiles->kept_cache.packs;
2212+
return store->kept_cache.packs;
22102213
}
22112214

22122215
int find_kept_pack_entry(struct repository *r,
22132216
const struct object_id *oid,
22142217
unsigned flags,
22152218
struct pack_entry *e)
22162219
{
2217-
struct packed_git **cache;
2220+
struct packed_git **cache = packfile_store_get_kept_pack_cache(r->objects->packfiles, flags);
22182221

2219-
for (cache = kept_pack_cache(r, flags); *cache; cache++) {
2222+
for (; *cache; cache++) {
22202223
struct packed_git *p = *cache;
22212224
if (fill_pack_entry(oid, e, p))
22222225
return 1;

packfile.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ struct packed_git *packfile_store_load_pack(struct packfile_store *store,
210210
int packfile_store_freshen_object(struct packfile_store *store,
211211
const struct object_id *oid);
212212

213+
enum kept_pack_type {
214+
KEPT_PACK_ON_DISK = (1 << 0),
215+
KEPT_PACK_IN_CORE = (1 << 1),
216+
};
217+
218+
/*
219+
* Retrieve the cache of kept packs from the given packfile store. Accepts a
220+
* combination of `kept_pack_type` flags. The cache is computed on demand and
221+
* will be recomputed whenever the flags change.
222+
*/
223+
struct packed_git **packfile_store_get_kept_pack_cache(struct packfile_store *store,
224+
unsigned flags);
225+
213226
struct pack_window {
214227
struct pack_window *next;
215228
unsigned char *base;
@@ -385,9 +398,6 @@ int packed_object_info(struct repository *r,
385398
void mark_bad_packed_object(struct packed_git *, const struct object_id *);
386399
const struct packed_git *has_packed_and_bad(struct repository *, const struct object_id *);
387400

388-
#define ON_DISK_KEEP_PACKS 1
389-
#define IN_CORE_KEEP_PACKS 2
390-
391401
/*
392402
* Iff a pack file in the given repository contains the object named by sha1,
393403
* return true and store its location to e.
@@ -398,8 +408,6 @@ int has_object_pack(struct repository *r, const struct object_id *oid);
398408
int has_object_kept_pack(struct repository *r, const struct object_id *oid,
399409
unsigned flags);
400410

401-
struct packed_git **kept_pack_cache(struct repository *r, unsigned flags);
402-
403411
/*
404412
* Return 1 if an object in a promisor packfile is or refers to the given
405413
* object, 0 otherwise.

reachable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static int want_recent_object(struct recent_data *data,
242242
const struct object_id *oid)
243243
{
244244
if (data->ignore_in_core_kept_packs &&
245-
has_object_kept_pack(data->revs->repo, oid, IN_CORE_KEEP_PACKS))
245+
has_object_kept_pack(data->revs->repo, oid, KEPT_PACK_IN_CORE))
246246
return 0;
247247
return 1;
248248
}

revision.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,14 +2541,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
25412541
die(_("--unpacked=<packfile> no longer supported"));
25422542
} else if (!strcmp(arg, "--no-kept-objects")) {
25432543
revs->no_kept_objects = 1;
2544-
revs->keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
2545-
revs->keep_pack_cache_flags |= ON_DISK_KEEP_PACKS;
2544+
revs->keep_pack_cache_flags |= KEPT_PACK_IN_CORE;
2545+
revs->keep_pack_cache_flags |= KEPT_PACK_ON_DISK;
25462546
} else if (skip_prefix(arg, "--no-kept-objects=", &optarg)) {
25472547
revs->no_kept_objects = 1;
25482548
if (!strcmp(optarg, "in-core"))
2549-
revs->keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
2549+
revs->keep_pack_cache_flags |= KEPT_PACK_IN_CORE;
25502550
if (!strcmp(optarg, "on-disk"))
2551-
revs->keep_pack_cache_flags |= ON_DISK_KEEP_PACKS;
2551+
revs->keep_pack_cache_flags |= KEPT_PACK_ON_DISK;
25522552
} else if (!strcmp(arg, "-r")) {
25532553
revs->diff = 1;
25542554
revs->diffopt.flags.recursive = 1;

0 commit comments

Comments
 (0)