summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/config/maintenance.txt15
-rw-r--r--builtin/gc.c28
-rwxr-xr-xt/t7900-maintenance.sh49
3 files changed, 90 insertions, 2 deletions
diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt
index 70585564fa..a5ead09e4b 100644
--- a/Documentation/config/maintenance.txt
+++ b/Documentation/config/maintenance.txt
@@ -3,6 +3,21 @@ maintenance.auto::
`git maintenance run --auto` after doing their normal work. Defaults
to true.
+maintenance.strategy::
+ This string config option provides a way to specify one of a few
+ recommended schedules for background maintenance. This only affects
+ which tasks are run during `git maintenance run --schedule=X`
+ commands, provided no `--task=<task>` arguments are provided.
+ Further, if a `maintenance.<task>.schedule` config value is set,
+ then that value is used instead of the one provided by
+ `maintenance.strategy`. The possible strategy strings are:
++
+* `none`: This default setting implies no task are run at any schedule.
+* `incremental`: This setting optimizes for performing small maintenance
+ activities that do not delete any data. This does not schedule the `gc`
+ task, but runs the `prefetch` and `commit-graph` tasks hourly and the
+ `loose-objects` and `incremental-repack` tasks daily.
+
maintenance.<task>.enabled::
This boolean config option controls whether the maintenance task
with name `<task>` is run when no `--task` option is specified to
diff --git a/builtin/gc.c b/builtin/gc.c
index a387f46585..a8248e7a45 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1308,12 +1308,35 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts)
return result;
}
-static void initialize_task_config(void)
+static void initialize_maintenance_strategy(void)
+{
+ char *config_str;
+
+ if (git_config_get_string("maintenance.strategy", &config_str))
+ return;
+
+ if (!strcasecmp(config_str, "incremental")) {
+ tasks[TASK_GC].schedule = SCHEDULE_NONE;
+ tasks[TASK_COMMIT_GRAPH].enabled = 1;
+ tasks[TASK_COMMIT_GRAPH].schedule = SCHEDULE_HOURLY;
+ tasks[TASK_PREFETCH].enabled = 1;
+ tasks[TASK_PREFETCH].schedule = SCHEDULE_HOURLY;
+ tasks[TASK_INCREMENTAL_REPACK].enabled = 1;
+ tasks[TASK_INCREMENTAL_REPACK].schedule = SCHEDULE_DAILY;
+ tasks[TASK_LOOSE_OBJECTS].enabled = 1;
+ tasks[TASK_LOOSE_OBJECTS].schedule = SCHEDULE_DAILY;
+ }
+}
+
+static void initialize_task_config(int schedule)
{
int i;
struct strbuf config_name = STRBUF_INIT;
gc_config();
+ if (schedule)
+ initialize_maintenance_strategy();
+
for (i = 0; i < TASK__COUNT; i++) {
int config_value;
char *config_str;
@@ -1389,7 +1412,6 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
memset(&opts, 0, sizeof(opts));
opts.quiet = !isatty(2);
- initialize_task_config();
for (i = 0; i < TASK__COUNT; i++)
tasks[i].selected_order = -1;
@@ -1402,6 +1424,8 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
if (opts.auto_flag && opts.schedule)
die(_("use at most one of --auto and --schedule=<frequency>"));
+ initialize_task_config(opts.schedule);
+
if (argc != 0)
usage_with_options(builtin_maintenance_run_usage,
builtin_maintenance_run_options);
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 7715e40391..7440a0ea19 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -300,6 +300,55 @@ test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
test_subcommand git multi-pack-index write --no-progress <weekly.txt
'
+test_expect_success 'maintenance.strategy inheritance' '
+ for task in commit-graph loose-objects incremental-repack
+ do
+ git config --unset maintenance.$task.schedule || return 1
+ done &&
+
+ test_when_finished git config --unset maintenance.strategy &&
+ git config maintenance.strategy incremental &&
+
+ GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \
+ git maintenance run --schedule=hourly --quiet &&
+ GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
+ git maintenance run --schedule=daily --quiet &&
+
+ test_subcommand git commit-graph write --split --reachable \
+ --no-progress <incremental-hourly.txt &&
+ test_subcommand ! git prune-packed --quiet <incremental-hourly.txt &&
+ test_subcommand ! git multi-pack-index write --no-progress \
+ <incremental-hourly.txt &&
+
+ test_subcommand git commit-graph write --split --reachable \
+ --no-progress <incremental-daily.txt &&
+ test_subcommand git prune-packed --quiet <incremental-daily.txt &&
+ test_subcommand git multi-pack-index write --no-progress \
+ <incremental-daily.txt &&
+
+ # Modify defaults
+ git config maintenance.commit-graph.schedule daily &&
+ git config maintenance.loose-objects.schedule hourly &&
+ git config maintenance.incremental-repack.enabled false &&
+
+ GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \
+ git maintenance run --schedule=hourly --quiet &&
+ GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \
+ git maintenance run --schedule=daily --quiet &&
+
+ test_subcommand ! git commit-graph write --split --reachable \
+ --no-progress <modified-hourly.txt &&
+ test_subcommand git prune-packed --quiet <modified-hourly.txt &&
+ test_subcommand ! git multi-pack-index write --no-progress \
+ <modified-hourly.txt &&
+
+ test_subcommand git commit-graph write --split --reachable \
+ --no-progress <modified-daily.txt &&
+ test_subcommand git prune-packed --quiet <modified-daily.txt &&
+ test_subcommand ! git multi-pack-index write --no-progress \
+ <modified-daily.txt
+'
+
test_expect_success 'register and unregister' '
test_when_finished git config --global --unset-all maintenance.repo &&
git config --global --add maintenance.repo /existing1 &&