scalar reconfigure: add --maintenance=<mode> option

When users want to enable the latest and greatest configuration options recommended by Scalar after a Git upgrade, 'scalar reconfigure --all' is a great option that iterates over all repos in the multi-valued 'scalar.repos' config key. However, this feature previously forced users to enable background maintenance. In some environments this is not preferred. Add a new --maintenance=<mode> option to 'scalar reconfigure' that provides options for enabling (default), disabling, or leaving background maintenance config as-is. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed May 7, 2025 at 01:50 UTC a34fef86e09f4dfe8b1198dd56e0631d24302b0e
3 files changed +47 -6
Documentation/scalar.adoc
+14 -3
@@ -14,7 +14,7 @@ scalar list
14 scalar register [--[no-]maintenance] [<enlistment>]
15 scalar unregister [<enlistment>]
16 scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
17 -scalar reconfigure [ --all | <enlistment> ]
17 +scalar reconfigure [--maintenance=<mode>] [ --all | <enlistment> ]
18 scalar diagnose [<enlistment>]
19 scalar delete <enlistment>
20
@@ -160,8 +160,19 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment
160 was somehow corrupted or changed by mistake, this subcommand allows to
161 reconfigure the enlistment.
162
163 -With the `--all` option, all enlistments currently registered with Scalar
164 -will be reconfigured. Use this option after each Scalar upgrade.
163 +--all::
164 + When `--all` is specified, reconfigure all enlistments currently
165 + registered with Scalar by the `scalar.repo` config key. Use this
166 + option after each upgrade to get the latest features.
167 +
168 +--maintenance=<mode>::
169 + By default, Scalar configures the enlistment to use Git's
170 + background maintenance feature; this is the same as using the
171 + `--maintenance=enable` value for this option. Use the
172 + `--maintenance=disable` to remove each considered enlistment
173 + from background maintenance. Use `--maitnenance=keep' to leave
174 + the background maintenance configuration untouched for These
175 + repositories.
176
177 Diagnose
178 ~~~~~~~~
scalar.c
+21 -2
@@ -668,13 +668,19 @@ static int remove_deleted_enlistment(struct strbuf *path)
668 static int cmd_reconfigure(int argc, const char **argv)
669 {
670 int all = 0;
671 + const char *maintenance_str = NULL;
672 + int maintenance = 1; /* Enable maintenance by default. */
673 +
674 struct option options[] = {
675 OPT_BOOL('a', "all", &all,
676 N_("reconfigure all registered enlistments")),
677 + OPT_STRING(0, "maintenance", &maintenance_str,
678 + N_("<mode>"),
679 + N_("signal how to adjust background maintenance")),
680 OPT_END(),
681 };
682 const char * const usage[] = {
677 - N_("scalar reconfigure [--all | <enlistment>]"),
683 + N_("scalar reconfigure [--maintenance=<mode>] [--all | <enlistment>]"),
684 NULL
685 };
686 struct string_list scalar_repos = STRING_LIST_INIT_DUP;
@@ -694,6 +700,18 @@ static int cmd_reconfigure(int argc, const char **argv)
700 usage_msg_opt(_("--all or <enlistment>, but not both"),
701 usage, options);
702
703 + if (maintenance_str) {
704 + if (!strcmp(maintenance_str, "enable"))
705 + maintenance = 1;
706 + else if (!strcmp(maintenance_str, "disable"))
707 + maintenance = 0;
708 + else if (!strcmp(maintenance_str, "keep"))
709 + maintenance = -1;
710 + else
711 + die(_("unknown mode for --maintenance option: %s"),
712 + maintenance_str);
713 + }
714 +
715 git_config(get_scalar_repos, &scalar_repos);
716
717 for (size_t i = 0; i < scalar_repos.nr; i++) {
@@ -758,7 +776,8 @@ static int cmd_reconfigure(int argc, const char **argv)
776 the_repository = old_repo;
777 repo_clear(&r);
778
761 - if (toggle_maintenance(1) >= 0)
779 + if (maintenance >= 0 &&
780 + toggle_maintenance(maintenance) >= 0)
781 succeeded = 1;
782
783 loop_end:
t/t9210-scalar.sh
+12 -1
@@ -210,7 +210,18 @@ test_expect_success 'scalar reconfigure' '
210 GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
211 test_path_is_file one/src/cron.txt &&
212 test true = "$(git -C one/src config core.preloadIndex)" &&
213 - test_subcommand git maintenance start <reconfigure
213 + test_subcommand git maintenance start <reconfigure &&
214 + test_subcommand ! git maintenance unregister --force <reconfigure &&
215 +
216 + GIT_TRACE2_EVENT="$(pwd)/reconfigure-maint-disable" \
217 + scalar reconfigure -a --maintenance=disable &&
218 + test_subcommand ! git maintenance start <reconfigure-maint-disable &&
219 + test_subcommand git maintenance unregister --force <reconfigure-maint-disable &&
220 +
221 + GIT_TRACE2_EVENT="$(pwd)/reconfigure-maint-keep" \
222 + scalar reconfigure --maintenance=keep -a &&
223 + test_subcommand ! git maintenance start <reconfigure-maint-keep &&
224 + test_subcommand ! git maintenance unregister --force <reconfigure-maint-keep
225 '
226
227 test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '