aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/gc.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-05-07 09:21:42 +0200
committerJunio C Hamano <gitster@pobox.com>2025-05-07 10:50:15 -0700
commit283621a553b60b26f14b9cf7e8b8c852ddba55d9 (patch)
treef602bec391d56778ed124fbf57a6fa0e879c75c3 /builtin/gc.c
parent255251cce179efffe6dd17bc26f2729f6fcfd3bd (diff)
downloadgit-283621a553b60b26f14b9cf7e8b8c852ddba55d9.tar.gz
builtin/maintenance: introduce "rerere-gc" task
While git-gc(1) knows to garbage collect the rerere cache, git-maintenance(1) does not yet have a task for this cleanup. Introduce a new "rerere-gc" task to plug this gap. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 03b4e32bb5..3393d2535d 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -16,6 +16,7 @@
#include "builtin.h"
#include "abspath.h"
#include "date.h"
+#include "dir.h"
#include "environment.h"
#include "hex.h"
#include "config.h"
@@ -33,6 +34,7 @@
#include "pack-objects.h"
#include "path.h"
#include "reflog.h"
+#include "rerere.h"
#include "blob.h"
#include "tree.h"
#include "promisor-remote.h"
@@ -393,6 +395,35 @@ static int maintenance_task_rerere_gc(struct maintenance_run_opts *opts UNUSED,
return run_command(&rerere_cmd);
}
+static int rerere_gc_condition(struct gc_config *cfg UNUSED)
+{
+ struct strbuf path = STRBUF_INIT;
+ int should_gc = 0, limit = 1;
+ DIR *dir = NULL;
+
+ git_config_get_int("maintenance.rerere-gc.auto", &limit);
+ if (limit <= 0) {
+ should_gc = limit < 0;
+ goto out;
+ }
+
+ /*
+ * We skip garbage collection in case we either have no "rr-cache"
+ * directory or when it doesn't contain at least one entry.
+ */
+ repo_git_path_replace(the_repository, &path, "rr-cache");
+ dir = opendir(path.buf);
+ if (!dir)
+ goto out;
+ should_gc = !!readdir_skip_dot_and_dotdot(dir);
+
+out:
+ strbuf_release(&path);
+ if (dir)
+ closedir(dir);
+ return should_gc;
+}
+
static int too_many_loose_objects(struct gc_config *cfg)
{
/*
@@ -1511,6 +1542,7 @@ enum maintenance_task_label {
TASK_PACK_REFS,
TASK_REFLOG_EXPIRE,
TASK_WORKTREE_PRUNE,
+ TASK_RERERE_GC,
/* Leave as final value */
TASK__COUNT
@@ -1557,6 +1589,11 @@ static struct maintenance_task tasks[] = {
maintenance_task_worktree_prune,
worktree_prune_condition,
},
+ [TASK_RERERE_GC] = {
+ "rerere-gc",
+ maintenance_task_rerere_gc,
+ rerere_gc_condition,
+ },
};
static int compare_tasks_by_selection(const void *a_, const void *b_)