Skip to content

Commit 7c6b051

Browse files
committed
maintenance: recommended schedule in register/start
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>.schedule' 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' weekly). 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@microsoft.com>
1 parent f181bdc commit 7c6b051

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Documentation/git-maintenance.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ register::
3737
`maintenance.<task>.schedule`. The tasks that are enabled are safe
3838
for running in the background without disrupting foreground
3939
processes.
40+
+
41+
If your repository has no 'maintenance.<task>.schedule' configuration
42+
values set, then Git will set configuration values to some recommended
43+
settings. These settings disable foreground maintenance while performing
44+
maintenance tasks in the background that will not interrupt foreground Git
45+
operations.
4046

4147
run::
4248
Run one or more maintenance tasks. If one or more `--task` options

builtin/gc.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,47 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14071407
return maintenance_run_tasks(&opts);
14081408
}
14091409

1410+
static int has_schedule_config(void)
1411+
{
1412+
int i, found = 0;
1413+
struct strbuf config_name = STRBUF_INIT;
1414+
size_t prefix;
1415+
1416+
strbuf_addstr(&config_name, "maintenance.");
1417+
prefix = config_name.len;
1418+
1419+
for (i = 0; !found && i < TASK__COUNT; i++) {
1420+
int value;
1421+
1422+
strbuf_setlen(&config_name, prefix);
1423+
strbuf_addf(&config_name, "%s.schedule", tasks[i].name);
1424+
1425+
if (!git_config_get_int(config_name.buf, &value))
1426+
found = 1;
1427+
}
1428+
1429+
strbuf_release(&config_name);
1430+
return found;
1431+
}
1432+
1433+
static void set_recommended_schedule(void)
1434+
{
1435+
git_config_set("maintenance.auto", "false");
1436+
git_config_set("maintenance.gc.enabled", "false");
1437+
1438+
git_config_set("maintenance.prefetch.enabled", "true");
1439+
git_config_set("maintenance.prefetch.schedule", "hourly");
1440+
1441+
git_config_set("maintenance.commit-graph.enabled", "true");
1442+
git_config_set("maintenance.commit-graph.schedule", "hourly");
1443+
1444+
git_config_set("maintenance.loose-objects.enabled", "true");
1445+
git_config_set("maintenance.loose-objects.schedule", "daily");
1446+
1447+
git_config_set("maintenance.incremental-repack.enabled", "true");
1448+
git_config_set("maintenance.incremental-repack.schedule", "daily");
1449+
}
1450+
14101451
static int maintenance_register(void)
14111452
{
14121453
struct child_process config_set = CHILD_PROCESS_INIT;
@@ -1416,6 +1457,9 @@ static int maintenance_register(void)
14161457
if (!the_repository || !the_repository->gitdir)
14171458
return 0;
14181459

1460+
if (has_schedule_config())
1461+
set_recommended_schedule();
1462+
14191463
config_get.git_cmd = 1;
14201464
strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
14211465
the_repository->worktree ? the_repository->worktree

t/t7900-maintenance.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ test_expect_success 'register and unregister' '
310310
git config --global --add maintenance.repo /existing2 &&
311311
git config --global --get-all maintenance.repo >before &&
312312
git maintenance register &&
313+
test_cmp_config false maintenance.auto &&
314+
test_cmp_config false maintenance.gc.enabled &&
315+
test_cmp_config true maintenance.prefetch.enabled &&
316+
test_cmp_config 3500 maintenance.commit-graph.schedule &&
317+
test_cmp_config 86000 maintenance.incremental-repack.schedule &&
313318
git config --global --get-all maintenance.repo >actual &&
314319
cp before after &&
315320
pwd >>after &&

0 commit comments

Comments
 (0)