From: Derrick Stolee <dstolee@xxxxxxxxxxxxx> The 'git maintenance (register|start)' subcommands add the current repository to the global Git config so maintenance will operate on that repository. It does not specify what maintenance should occur or how often. If a user sets any 'maintenance.<task>.scheduled' config value, then they have chosen a specific schedule for themselves and Git should respect that. However, in an effort to recommend a good schedule for repositories of all sizes, set new config values for recommended tasks that are safe to run in the background while users run foreground Git commands. These commands are generally everything but the 'gc' task. Author's Note: I feel we should do _something_ to recommend a good schedule to users, but I'm not 100% set on this schedule. This is the schedule we use in Scalar and VFS for Git for very large repositories using the GVFS protocol. While the schedule works in that environment, it is possible that "normal" Git repositories could benefit from something more obvious (such as running 'gc' once a day). However, this patch gives us a place to start a conversation on what we should recommend. For my purposes, Scalar will set these config values so we can always differ from core Git's recommendations. Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx> --- Documentation/git-maintenance.txt | 6 +++++ builtin/gc.c | 44 +++++++++++++++++++++++++++++++ t/t7900-maintenance.sh | 5 ++++ 3 files changed, 55 insertions(+) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index 600272caa5..a4b46ea329 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -37,6 +37,12 @@ register:: `maintenance.<task>.schedule`. The tasks that are enabled are safe for running in the background without disrupting foreground processes. ++ +If your repository has no 'maintenance.<task>.schedule' configuration +values set, then Git will set configuration values to some recommended +settings. These settings disable foreground maintenance while performing +maintenance tasks in the background that will not interrupt foreground Git +operations. run:: Run one or more maintenance tasks. If one or more `--task` options diff --git a/builtin/gc.c b/builtin/gc.c index b09287f0fc..080d58735c 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1446,6 +1446,47 @@ static int task_option_parse(const struct option *opt, return 0; } +static int has_schedule_config(void) +{ + int i, found = 0; + struct strbuf config_name = STRBUF_INIT; + size_t prefix; + + strbuf_addstr(&config_name, "maintenance."); + prefix = config_name.len; + + for (i = 0; !found && i < TASK__COUNT; i++) { + int value; + + strbuf_setlen(&config_name, prefix); + strbuf_addf(&config_name, "%s.schedule", tasks[i].name); + + if (!git_config_get_int(config_name.buf, &value)) + found = 1; + } + + strbuf_release(&config_name); + return found; +} + +static void set_recommended_schedule(void) +{ + git_config_set("maintenance.auto", "false"); + git_config_set("maintenance.gc.enabled", "false"); + + git_config_set("maintenance.prefetch.enabled", "true"); + git_config_set("maintenance.prefetch.schedule", "3500"); + + git_config_set("maintenance.commit-graph.enabled", "true"); + git_config_set("maintenance.commit-graph.schedule", "3500"); + + git_config_set("maintenance.loose-objects.enabled", "true"); + git_config_set("maintenance.loose-objects.schedule", "86000"); + + git_config_set("maintenance.incremental-repack.enabled", "true"); + git_config_set("maintenance.incremental-repack.schedule", "86000"); +} + static int maintenance_register(void) { struct child_process config_set = CHILD_PROCESS_INIT; @@ -1455,6 +1496,9 @@ static int maintenance_register(void) if (!the_repository || !the_repository->gitdir) return 0; + if (has_schedule_config()) + set_recommended_schedule(); + config_get.git_cmd = 1; strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo", the_repository->worktree ? the_repository->worktree diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 6491031be8..7417e5858a 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -300,6 +300,11 @@ test_expect_success 'register and unregister' ' git config --global --add maintenance.repo /existing2 && git config --global --get-all maintenance.repo >before && git maintenance register && + test_cmp_config false maintenance.auto && + test_cmp_config false maintenance.gc.enabled && + test_cmp_config true maintenance.prefetch.enabled && + test_cmp_config 3500 maintenance.commit-graph.schedule && + test_cmp_config 86000 maintenance.incremental-repack.schedule && git config --global --get-all maintenance.repo >actual && cp before after && pwd >>after && -- gitgitgadget