Skip to content

Commit 1ed76c4

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

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,49 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14081408
return maintenance_run_tasks(&opts);
14091409
}
14101410

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

1463+
if (!has_schedule_config())
1464+
set_recommended_schedule();
1465+
14201466
config_get.git_cmd = 1;
14211467
strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
14221468
the_repository->worktree ? the_repository->worktree

t/t7900-maintenance.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,23 @@ test_expect_success 'register and unregister' '
305305
git config --global --add maintenance.repo /existing1 &&
306306
git config --global --add maintenance.repo /existing2 &&
307307
git config --global --get-all maintenance.repo >before &&
308+
309+
# We still have maintenance.<task>.schedule config set,
310+
# so this does not update the local schedule
311+
git maintenance register &&
312+
test_must_fail git config maintenance.auto &&
313+
314+
# Clear previous maintenance.<task>.schedule values
315+
for task in loose-objects commit-graph incremental-repack
316+
do
317+
git config --unset maintenance.$task.schedule || return 1
318+
done &&
308319
git maintenance register &&
320+
test_cmp_config false maintenance.auto &&
321+
test_cmp_config false maintenance.gc.enabled &&
322+
test_cmp_config true maintenance.prefetch.enabled &&
323+
test_cmp_config hourly maintenance.commit-graph.schedule &&
324+
test_cmp_config daily maintenance.incremental-repack.schedule &&
309325
git config --global --get-all maintenance.repo >actual &&
310326
cp before after &&
311327
pwd >>after &&

0 commit comments

Comments
 (0)