maintenance: replace run_auto_gc()

The run_auto_gc() method is used in several places to trigger a check
for repo maintenance after some Git commands, such as 'git commit' or
'git fetch'.

To allow for extra customization of this maintenance activity, replace
the 'git gc --auto [--quiet]' call with one to 'git maintenance run
--auto [--quiet]'. As we extend the maintenance builtin with other
steps, users will be able to select different maintenance activities.

Rename run_auto_gc() to run_auto_maintenance() to be clearer what is
happening on this call, and to expose all callers in the current diff.
Rewrite the method to use a struct child_process to simplify the calls
slightly.

Since 'git fetch' already allows disabling the 'git gc --auto'
subprocess, add an equivalent option with a different name to be more
descriptive of the new behavior: '--[no-]maintenance'. Update the
documentation to include these options at the same time.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee
2020-09-17 18:11:44 +00:00
committed by Junio C Hamano
parent 3ddaad0e06
commit a95ce12430
10 changed files with 25 additions and 23 deletions

View File

@ -1866,15 +1866,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
return result;
}
int run_auto_gc(int quiet)
int run_auto_maintenance(int quiet)
{
struct strvec argv_gc_auto = STRVEC_INIT;
int status;
struct child_process maint = CHILD_PROCESS_INIT;
strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL);
if (quiet)
strvec_push(&argv_gc_auto, "--quiet");
status = run_command_v_opt(argv_gc_auto.v, RUN_GIT_CMD);
strvec_clear(&argv_gc_auto);
return status;
maint.git_cmd = 1;
strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
return run_command(&maint);
}