Skip to content

Commit 6a7d3ee

Browse files
pks-tgitster
authored andcommitted
builtin/maintenance: run maintenance tasks depending on type
We basically have three different ways to execute repository maintenance: 1. Manual maintenance via `git maintenance run`. 2. Automatic maintenance via `git maintenance run --auto`. 3. Scheduled maintenance via `git maintenance run --schedule=`. At the moment, maintenance strategies only have an effect for the last type of maintenance. This is about to change in subsequent commits, but to do so we need to be able to skip some tasks depending on how exactly maintenance was invoked. Introduce a new maintenance type that discern between manual (1 & 2) and scheduled (3) maintenance. Convert the `enabled` field into a bitset so that it becomes possible to specifiy which tasks exactly should run in a specific context. The types picked for existing strategies match the status quo: - The default strategy is only ever executed as part of a manual maintenance run. It is not possible to use it for scheduled maintenance. - The incremental strategy is only ever executed as part of a scheduled maintenance run. It is not possible to use it for manual maintenance. The strategies will be tweaked in subsequent commits to make use of this new infrastructure. Signed-off-by: Patrick Steinhardt <ps@pks.im> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e83e92e commit 6a7d3ee

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

builtin/gc.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,9 +1827,16 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
18271827
return result;
18281828
}
18291829

1830+
enum maintenance_type {
1831+
/* As invoked via `git maintenance run --schedule=`. */
1832+
MAINTENANCE_TYPE_SCHEDULED = (1 << 0),
1833+
/* As invoked via `git maintenance run` and with `--auto`. */
1834+
MAINTENANCE_TYPE_MANUAL = (1 << 1),
1835+
};
1836+
18301837
struct maintenance_strategy {
18311838
struct {
1832-
int enabled;
1839+
unsigned type;
18331840
enum schedule_priority schedule;
18341841
} tasks[TASK__COUNT];
18351842
};
@@ -1839,31 +1846,31 @@ static const struct maintenance_strategy none_strategy = { 0 };
18391846
static const struct maintenance_strategy default_strategy = {
18401847
.tasks = {
18411848
[TASK_GC] = {
1842-
.enabled = 1,
1849+
.type = MAINTENANCE_TYPE_MANUAL,
18431850
},
18441851
},
18451852
};
18461853

18471854
static const struct maintenance_strategy incremental_strategy = {
18481855
.tasks = {
18491856
[TASK_COMMIT_GRAPH] = {
1850-
.enabled = 1,
1857+
.type = MAINTENANCE_TYPE_SCHEDULED,
18511858
.schedule = SCHEDULE_HOURLY,
18521859
},
18531860
[TASK_PREFETCH] = {
1854-
.enabled = 1,
1861+
.type = MAINTENANCE_TYPE_SCHEDULED,
18551862
.schedule = SCHEDULE_HOURLY,
18561863
},
18571864
[TASK_INCREMENTAL_REPACK] = {
1858-
.enabled = 1,
1865+
.type = MAINTENANCE_TYPE_SCHEDULED,
18591866
.schedule = SCHEDULE_DAILY,
18601867
},
18611868
[TASK_LOOSE_OBJECTS] = {
1862-
.enabled = 1,
1869+
.type = MAINTENANCE_TYPE_SCHEDULED,
18631870
.schedule = SCHEDULE_DAILY,
18641871
},
18651872
[TASK_PACK_REFS] = {
1866-
.enabled = 1,
1873+
.type = MAINTENANCE_TYPE_SCHEDULED,
18671874
.schedule = SCHEDULE_WEEKLY,
18681875
},
18691876
},
@@ -1881,6 +1888,7 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
18811888
{
18821889
struct strbuf config_name = STRBUF_INIT;
18831890
struct maintenance_strategy strategy;
1891+
enum maintenance_type type;
18841892
const char *config_str;
18851893

18861894
/*
@@ -1915,8 +1923,10 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
19151923
strategy = parse_maintenance_strategy(config_str);
19161924
else
19171925
strategy = none_strategy;
1926+
type = MAINTENANCE_TYPE_SCHEDULED;
19181927
} else {
19191928
strategy = default_strategy;
1929+
type = MAINTENANCE_TYPE_MANUAL;
19201930
}
19211931

19221932
for (size_t i = 0; i < TASK__COUNT; i++) {
@@ -1926,8 +1936,8 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
19261936
strbuf_addf(&config_name, "maintenance.%s.enabled",
19271937
tasks[i].name);
19281938
if (!repo_config_get_bool(the_repository, config_name.buf, &config_value))
1929-
strategy.tasks[i].enabled = config_value;
1930-
if (!strategy.tasks[i].enabled)
1939+
strategy.tasks[i].type = config_value ? type : 0;
1940+
if (!(strategy.tasks[i].type & type))
19311941
continue;
19321942

19331943
if (opts->schedule) {

0 commit comments

Comments
 (0)