maintenance: add --task option
A user may want to only run certain maintenance tasks in a certain order. Add the --task=<task> option, which allows a user to specify an ordered list of tasks to run. These cannot be run multiple times, however. Here is where our array of maintenance_task pointers becomes critical. We can sort the array of pointers based on the task order, but we do not want to move the struct data itself in order to preserve the hashmap references. We use the hashmap to match the --task=<task> arguments into the task struct data. Keep in mind that the 'enabled' member of the maintenance_task struct is a placeholder for a future 'maintenance.<task>.enabled' config option. Thus, we use the 'enabled' member to specify which tasks are run when the user does not specify any --task=<task> arguments. The 'enabled' member should be ignored if --task=<task> appears. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
663b2b1b90
commit
090511bc0b
@ -27,4 +27,31 @@ test_expect_success 'run [--auto|--quiet]' '
|
||||
test_subcommand git gc --no-quiet <run-no-quiet.txt
|
||||
'
|
||||
|
||||
test_expect_success 'run --task=<task>' '
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
|
||||
git maintenance run --task=commit-graph 2>/dev/null &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \
|
||||
git maintenance run --task=gc 2>/dev/null &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
|
||||
git maintenance run --task=commit-graph 2>/dev/null &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
|
||||
git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
|
||||
test_subcommand ! git gc --quiet <run-commit-graph.txt &&
|
||||
test_subcommand git gc --quiet <run-gc.txt &&
|
||||
test_subcommand git gc --quiet <run-both.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
|
||||
test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
|
||||
'
|
||||
|
||||
test_expect_success 'run --task=bogus' '
|
||||
test_must_fail git maintenance run --task=bogus 2>err &&
|
||||
test_i18ngrep "is not a valid task" err
|
||||
'
|
||||
|
||||
test_expect_success 'run --task duplicate' '
|
||||
test_must_fail git maintenance run --task=gc --task=gc 2>err &&
|
||||
test_i18ngrep "cannot be selected multiple times" err
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user