Skip to content

Commit 61f7a38

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a4cb1a2 commit 61f7a38

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

Documentation/git-maintenance.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ 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+
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.
4057

4158
run::
4259
Run one or more maintenance tasks. If one or more `--task` options

builtin/gc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,13 +1434,23 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14341434

14351435
static int maintenance_register(void)
14361436
{
1437+
char *config_value;
14371438
struct child_process config_set = CHILD_PROCESS_INIT;
14381439
struct child_process config_get = CHILD_PROCESS_INIT;
14391440

14401441
/* There is no current repository, so skip registering it */
14411442
if (!the_repository || !the_repository->gitdir)
14421443
return 0;
14431444

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+
14441454
config_get.git_cmd = 1;
14451455
strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
14461456
the_repository->worktree ? the_repository->worktree

t/t7900-maintenance.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,14 @@ test_expect_success 'register and unregister' '
354354
git config --global --add maintenance.repo /existing1 &&
355355
git config --global --add maintenance.repo /existing2 &&
356356
git config --global --get-all maintenance.repo >before &&
357+
357358
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+
362365
git maintenance unregister &&
363366
git config --global --get-all maintenance.repo >actual &&
364367
test_cmp before actual
@@ -392,4 +395,13 @@ test_expect_success 'start preserves existing schedule' '
392395
grep "Important information!" cron.txt
393396
'
394397

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+
395407
test_done

0 commit comments

Comments
 (0)