Commit

20c0a93007eb3d4b4659a6ae450b7b2377b1c236

rerere: extract logic to determine whether entries are stale

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt <ps@pks.im> · 2026-09-04 07:03 UTC · committed by Junio C Hamano

Browse files
1 file changed, +31 −13
modified rerere.c
@@ -1173,22 +1173,44 @@ static void unlink_rr_item(struct rerere_id *id)
1173 1173 strbuf_release(&buf);
1174 1174 }
1175 1175
1176 - static void prune_one(struct rerere_id *id,
1177 - timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve)
1176 + static void rerere_gc_cutoffs(struct repository *r,
1177 + timestamp_t *cutoff_resolve,
1178 + timestamp_t *cutoff_noresolve)
1179 + {
1180 + timestamp_t now = time(NULL);
1181 +
1182 + if (repo_config_get_expiry_in_days(r, "gc.rerereresolved",
1183 + cutoff_resolve, now))
1184 + *cutoff_resolve = now - 60 * 86400;
1185 + if (repo_config_get_expiry_in_days(r, "gc.rerereunresolved",
1186 + cutoff_noresolve, now))
1187 + *cutoff_noresolve = now - 15 * 86400;
1188 + }
1189 +
1190 + static bool rerere_id_is_stale(struct rerere_id *id,
1191 + timestamp_t cutoff_resolve,
1192 + timestamp_t cutoff_noresolve)
1178 1193 {
1179 1194 timestamp_t then;
1180 1195 timestamp_t cutoff;
1181 1196
1182 1197 then = rerere_last_used_at(id);
1183 - if (then)
1198 + if (then) {
1184 1199 cutoff = cutoff_resolve;
1185 - else {
1200 + } else {
1186 1201 then = rerere_created_at(id);
1187 1202 if (!then)
1188 - return;
1203 + return false;
1189 1204 cutoff = cutoff_noresolve;
1190 1205 }
1191 - if (then < cutoff)
1206 +
1207 + return then < cutoff;
1208 + }
1209 +
1210 + static void prune_one(struct rerere_id *id,
1211 + timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve)
1212 + {
1213 + if (rerere_id_is_stale(id, cutoff_resolve, cutoff_noresolve))
1192 1214 unlink_rr_item(id);
1193 1215 }
1194 1216
@@ -1206,18 +1228,14 @@ void rerere_gc(struct repository *r, struct string_list *rr)
1206 1228 DIR *dir;
1207 1229 struct dirent *e;
1208 1230 int i;
1209 - timestamp_t now = time(NULL);
1210 - timestamp_t cutoff_noresolve = now - 15 * 86400;
1211 - timestamp_t cutoff_resolve = now - 60 * 86400;
1231 + timestamp_t cutoff_noresolve;
1232 + timestamp_t cutoff_resolve;
1212 1233 struct strbuf buf = STRBUF_INIT;
1213 1234
1214 1235 if (setup_rerere(r, rr, 0) < 0)
1215 1236 return;
1216 1237
1217 - repo_config_get_expiry_in_days(the_repository, "gc.rerereresolved",
1218 - &cutoff_resolve, now);
1219 - repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved",
1220 - &cutoff_noresolve, now);
1238 + rerere_gc_cutoffs(r, &cutoff_resolve, &cutoff_noresolve);
1221 1239 repo_config(the_repository, git_default_config, NULL);
1222 1240 dir = opendir(repo_git_path_replace(the_repository, &buf, "rr-cache"));
1223 1241 if (!dir)