[PATCH 1/2] rerere: extract logic to determine whether entries are stale
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Sep 3, 2026, 09:04 UTC
- Message-ID
- <20260903-b4-pks-maintenance-rerere-gc-heuristic-v1-1-9929c45a9788@pks.im>
- In-Reply-To
- <20260903-b4-pks-maintenance-rerere-gc-heuristic-v1-0-9929c45a9788@pks.im>
When garbage collecting rerere entries we need to figure out whether any given entry is stale before pruning it. In a subsequent commit we're about to introduce a second caller that wants to determine staleness, but the logic is not currently reusable.
Extract the logic to compute staleness by introducing two new helper functions `rerere_gc_cutoffs()` and `rerere_id_is_stale()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- rerere.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/rerere.c b/rerere.c index 3d3bd0db16..d01af6b71b 100644 --- a/rerere.c +++ b/rerere.c @@ -1173,23 +1173,38 @@ static void unlink_rr_item(struct rerere_id *id) strbuf_release(&buf); } -static void prune_one(struct rerere_id *id, - timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve) +static void rerere_gc_cutoffs(struct repository *r, + timestamp_t *cutoff_resolve, + timestamp_t *cutoff_noresolve) +{ + timestamp_t now = time(NULL); + + if (repo_config_get_expiry_in_days(r, "gc.rerereresolved", + cutoff_resolve, now)) + *cutoff_resolve = now - 60 * 86400; + if (repo_config_get_expiry_in_days(r, "gc.rerereunresolved", + cutoff_noresolve, now)) + *cutoff_noresolve = now - 15 * 86400; +} + +static bool rerere_id_is_stale(struct rerere_id *id, + timestamp_t cutoff_resolve, + timestamp_t cutoff_noresolve) { timestamp_t then; timestamp_t cutoff; then = rerere_last_used_at(id); - if (then) + if (then) { cutoff = cutoff_resolve; - else { + } else { then = rerere_created_at(id); if (!then) - return; + return false; cutoff = cutoff_noresolve; } - if (then < cutoff) - unlink_rr_item(id); + + return then < cutoff; } /* Does the basename in "path" look plausibly like an rr-cache entry? */ @@ -1206,18 +1221,14 @@ void rerere_gc(struct repository *r, struct string_list *rr) DIR *dir; struct dirent *e; int i; - timestamp_t now = time(NULL); - timestamp_t cutoff_noresolve = now - 15 * 86400; - timestamp_t cutoff_resolve = now - 60 * 86400; + timestamp_t cutoff_noresolve; + timestamp_t cutoff_resolve; struct strbuf buf = STRBUF_INIT; if (setup_rerere(r, rr, 0) < 0) return; - repo_config_get_expiry_in_days(the_repository, "gc.rerereresolved", - &cutoff_resolve, now); - repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved", - &cutoff_noresolve, now); + rerere_gc_cutoffs(r, &cutoff_resolve, &cutoff_noresolve); repo_config(the_repository, git_default_config, NULL); dir = opendir(repo_git_path_replace(the_repository, &buf, "rr-cache")); if (!dir) @@ -1237,7 +1248,8 @@ void rerere_gc(struct repository *r, struct string_list *rr) for (id.variant = 0, id.collection = rr_dir; id.variant < id.collection->status_nr; id.variant++) { - prune_one(&id, cutoff_resolve, cutoff_noresolve); + if (rerere_id_is_stale(&id, cutoff_resolve, cutoff_noresolve)) + unlink_rr_item(&id); if (id.collection->status[id.variant]) now_empty = 0; }
-- 2.55.0.979.g7e5102b832.dirty