Skip to content

Commit 1b8050f

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>.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@microsoft.com>
1 parent 8d4eb40 commit 1b8050f

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
@@ -1446,6 +1446,47 @@ static int task_option_parse(const struct option *opt,
14461446
return 0;
14471447
}
14481448

1449+
static int has_schedule_config(void)
1450+
{
1451+
int i, found = 0;
1452+
struct strbuf config_name = STRBUF_INIT;
1453+
size_t prefix;
1454+
1455+
strbuf_addstr(&config_name, "maintenance.");
1456+
prefix = config_name.len;
1457+
1458+
for (i = 0; !found && i < TASK__COUNT; i++) {
1459+
int value;
1460+
1461+
strbuf_setlen(&config_name, prefix);
1462+
strbuf_addf(&config_name, "%s.schedule", tasks[i].name);
1463+
1464+
if (!git_config_get_int(config_name.buf, &value))
1465+
found = 1;
1466+
}
1467+
1468+
strbuf_release(&config_name);
1469+
return found;
1470+
}
1471+
1472+
static void set_recommended_schedule(void)
1473+
{
1474+
git_config_set("maintenance.auto", "false");
1475+
git_config_set("maintenance.gc.enabled", "false");
1476+
1477+
git_config_set("maintenance.prefetch.enabled", "true");
1478+
git_config_set("maintenance.prefetch.schedule", "3500");
1479+
1480+
git_config_set("maintenance.commit-graph.enabled", "true");
1481+
git_config_set("maintenance.commit-graph.schedule", "3500");
1482+
1483+
git_config_set("maintenance.loose-objects.enabled", "true");
1484+
git_config_set("maintenance.loose-objects.schedule", "86000");
1485+
1486+
git_config_set("maintenance.incremental-repack.enabled", "true");
1487+
git_config_set("maintenance.incremental-repack.schedule", "86000");
1488+
}
1489+
14491490
static int maintenance_register(void)
14501491
{
14511492
struct child_process config_set = CHILD_PROCESS_INIT;
@@ -1455,6 +1496,9 @@ static int maintenance_register(void)
14551496
if (!the_repository || !the_repository->gitdir)
14561497
return 0;
14571498

1499+
if (has_schedule_config())
1500+
set_recommended_schedule();
1501+
14581502
config_get.git_cmd = 1;
14591503
strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
14601504
the_repository->worktree ? the_repository->worktree

t/t7900-maintenance.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ test_expect_success 'register and unregister' '
300300
git config --global --add maintenance.repo /existing2 &&
301301
git config --global --get-all maintenance.repo >before &&
302302
git maintenance register &&
303+
test_cmp_config false maintenance.auto &&
304+
test_cmp_config false maintenance.gc.enabled &&
305+
test_cmp_config true maintenance.prefetch.enabled &&
306+
test_cmp_config 3500 maintenance.commit-graph.schedule &&
307+
test_cmp_config 86000 maintenance.incremental-repack.schedule &&
303308
git config --global --get-all maintenance.repo >actual &&
304309
cp before after &&
305310
pwd >>after &&

0 commit comments

Comments
 (0)