git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Patrick SteinhardtNext: Derrick Stolee
Message 2 of 17 in “builtin/maintenance: improve heuristic for "rerere gc"”
  1. 0/2 builtin/maintenance: improve heuristic for "rerere gc"Patrick Steinhardt, Sep 3, 2026
  2. 1/2 rerere: extract logic to determine whether entries are stalePatrick Steinhardt, Sep 3, 2026
  3. Derrick StoleeSep 3, 2026
  4. Patrick SteinhardtSep 4, 2026
  5. 2/2 builtin/maintenance: improve heuristic for "rerere gc"Patrick Steinhardt, Sep 3, 2026
  6. Derrick StoleeSep 3, 2026
  7. Patrick SteinhardtSep 4, 2026
  8. Thomas BachemSep 3, 2026
  9. 0/2 builtin/maintenance: improve heuristic for "rerere gc"Patrick Steinhardt, Sep 4, 2026
  10. 1/2 rerere: extract logic to determine whether entries are stalePatrick Steinhardt, Sep 4, 2026
  11. 2/2 builtin/maintenance: improve heuristic for "rerere gc"Patrick Steinhardt, Sep 4, 2026
  12. Derrick StoleeSep 4, 2026
  13. Junio C HamanoSep 4, 2026
  14. Junio C HamanoSep 4, 2026
  15. Thomas BachemSep 4, 2026
  16. Patrick SteinhardtSep 7, 2026
  17. Patrick SteinhardtSep 7, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.