maintenance: use 'incremental' strategy by default
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. To make it simple for users to start background maintenance with a recommended schedlue, update the 'maintenance.strategy' config option in both the 'register' and 'start' subcommands. This allows users to customize beyond the defaults using individual 'maintenance.<task>.schedule' options, but also the user can opt-out of this strategy using 'maintenance.strategy=none'. Helped-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Oct 15, 2020 at 17:22 UTC
61f7a383d3b9a7306f1fd44a8dfa070deacc0752
3 files changed
+43
-4
Documentation/git-maintenance.txt
+17
@@ -37,6 +37,23 @@ register::
37
`maintenance.<task>.schedule`. The tasks that are enabled are safe
38
for running in the background without disrupting foreground
39
processes.
40
++
41
+The `register` subcomand will also set the `maintenance.strategy` config
42
+value to `incremental`, if this value is not previously set. The
43
+`incremental` strategy uses the following schedule for each maintenance
44
+task:
45
++
46
+--
47
+* `gc`: disabled.
48
+* `commit-graph`: hourly.
49
+* `prefetch`: hourly.
50
+* `loose-objects`: daily.
51
+* `incremental-repack`: daily.
52
+--
53
++
54
+`git maintenance register` will also disable foreground maintenance by
55
+setting `maintenance.auto = false` in the current repository. This config
56
+setting will remain after a `git maintenance unregister` command.
57
58
run::
59
Run one or more maintenance tasks. If one or more `--task` options
builtin/gc.c
+10
@@ -1434,6 +1434,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
1434
1435
static int maintenance_register(void)
1436
{
1437
+ char *config_value;
1438
struct child_process config_set = CHILD_PROCESS_INIT;
1439
struct child_process config_get = CHILD_PROCESS_INIT;
1440
@@ -1441,6 +1442,15 @@ static int maintenance_register(void)
1442
if (!the_repository || !the_repository->gitdir)
1443
return 0;
1444
1445
+ /* Disable foreground maintenance */
1446
+ git_config_set("maintenance.auto", "false");
1447
+
1448
+ /* Set maintenance strategy, if unset */
1449
+ if (!git_config_get_string("maintenance.strategy", &config_value))
1450
+ free(config_value);
1451
+ else
1452
+ git_config_set("maintenance.strategy", "incremental");
1453
+
1454
config_get.git_cmd = 1;
1455
strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
1456
the_repository->worktree ? the_repository->worktree
t/t7900-maintenance.sh
+16
-4
@@ -354,11 +354,14 @@ test_expect_success 'register and unregister' '
354
git config --global --add maintenance.repo /existing1 &&
355
git config --global --add maintenance.repo /existing2 &&
356
git config --global --get-all maintenance.repo >before &&
357
+
358
git maintenance register &&
358
- git config --global --get-all maintenance.repo >actual &&
359
- cp before after &&
360
- pwd >>after &&
361
- test_cmp after actual &&
359
+ test_cmp_config false maintenance.auto &&
360
+ git config --global --get-all maintenance.repo >between &&
361
+ cp before expect &&
362
+ pwd >>expect &&
363
+ test_cmp expect between &&
364
+
365
git maintenance unregister &&
366
git config --global --get-all maintenance.repo >actual &&
367
test_cmp before actual
@@ -392,4 +395,13 @@ test_expect_success 'start preserves existing schedule' '
395
grep "Important information!" cron.txt
396
'
397
398
+test_expect_success 'register preserves existing strategy' '
399
+ git config maintenance.strategy none &&
400
+ git maintenance register &&
401
+ test_config maintenance.strategy none &&
402
+ git config --unset maintenance.strategy &&
403
+ git maintenance register &&
404
+ test_config maintenance.strategy incremental
405
+'
406
+
407
test_done