[PATCH v2 1/2] rerere: extract logic to determine whether entries are stale
From: Patrick Steinhardt <hidden>
Date: 2026-09-04 07:03:30
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 <redacted> --- rerere.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-)
diff --git a/rerere.c b/rerere.c
index 3d3bd0db16..073422dbf3 100644
--- a/rerere.c
+++ b/rerere.c@@ -1173,22 +1173,44 @@ 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) + + return then < cutoff; +} + +static void prune_one(struct rerere_id *id, + timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve) +{ + if (rerere_id_is_stale(id, cutoff_resolve, cutoff_noresolve)) unlink_rr_item(id); }
@@ -1206,18 +1228,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)
--
2.55.0.1007.g17ff1f9808.dirty