@@ -755,9 +755,17 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
typedef int maintenance_task_fn(struct maintenance_run_opts *opts);
+/*
+ * An auto condition function returns 1 if the task should run
+ * and 0 if the task should NOT run. See needs_to_gc() for an
+ * example.
+ */
+typedef int maintenance_auto_fn(void);
+
struct maintenance_task {
const char *name;
maintenance_task_fn *fn;
+ maintenance_auto_fn *auto_condition;
unsigned enabled:1;
/* -1 if not selected. */
@@ -776,6 +784,7 @@ static struct maintenance_task tasks[] = {
[TASK_GC] = {
"gc",
maintenance_task_gc,
+ need_to_gc,
1,
},
[TASK_COMMIT_GRAPH] = {
@@ -831,6 +840,11 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts)
if (!found_selected && !tasks[i].enabled)
continue;
+ if (opts->auto_flag &&
+ (!tasks[i].auto_condition ||
+ !tasks[i].auto_condition()))
+ continue;
+
if (tasks[i].fn(opts)) {
error(_("task '%s' failed"), tasks[i].name);
result = 1;
@@ -845,6 +859,8 @@ static void initialize_task_config(void)
{
int i;
struct strbuf config_name = STRBUF_INIT;
+ gc_config();
+
for (i = 0; i < TASK__COUNT; i++) {
int config_value;
@@ -108,7 +108,7 @@ test_expect_success 'git fetch --multiple (two remotes)' '
GIT_TRACE=1 git fetch --multiple one two 2>trace &&
git branch -r > output &&
test_cmp ../expect output &&
- grep "built-in: git gc" trace >gc &&
+ grep "built-in: git maintenance" trace >gc &&
test_line_count = 1 gc
)
'
@@ -23,7 +23,7 @@ test_expect_success 'run [--auto|--quiet]' '
GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
git maintenance run --no-quiet 2>/dev/null &&
test_subcommand git gc --quiet <run-no-auto.txt &&
- test_subcommand git gc --auto --quiet <run-auto.txt &&
+ test_subcommand ! git gc --auto --quiet <run-auto.txt &&
test_subcommand git gc --no-quiet <run-no-quiet.txt
'