@@ -788,9 +788,17 @@ static int maintenance_task_gc(struct maintenance_opts *opts)
typedef int maintenance_task_fn(struct maintenance_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,
selected:1;
int selected_order;
@@ -808,6 +816,7 @@ static struct maintenance_task tasks[] = {
[TASK_GC] = {
"gc",
maintenance_task_gc,
+ need_to_gc,
1,
},
[TASK_COMMIT_GRAPH] = {
@@ -863,6 +872,11 @@ static int maintenance_run(struct maintenance_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;
@@ -877,6 +891,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
)
'
@@ -19,7 +19,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
'