From: Derrick Stolee Date: Wed, 7 May 2025 01:50:37 +0000 (+0000) Subject: scalar reconfigure: add --maintenance= option X-Git-Tag: v2.50.0-rc0~23^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a34fef86e09f4dfe8b1198dd56e0631d24302b0e;p=thirdparty%2Fgit.git scalar reconfigure: add --maintenance= 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= option to 'scalar reconfigure' that provides options for enabling (default), disabling, or leaving background maintenance config as-is. Helped-by: Junio C Hamano Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc index 7753df3b43..387527be1e 100644 --- a/Documentation/scalar.adoc +++ b/Documentation/scalar.adoc @@ -14,7 +14,7 @@ scalar list scalar register [--[no-]maintenance] [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] -scalar reconfigure [ --all | ] +scalar reconfigure [--maintenance=] [ --all | ] scalar diagnose [] scalar delete @@ -160,8 +160,19 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment was somehow corrupted or changed by mistake, this subcommand allows to reconfigure the enlistment. -With the `--all` option, all enlistments currently registered with Scalar -will be reconfigured. Use this option after each Scalar upgrade. +--all:: + When `--all` is specified, reconfigure all enlistments currently + registered with Scalar by the `scalar.repo` config key. Use this + option after each upgrade to get the latest features. + +--maintenance=:: + By default, Scalar configures the enlistment to use Git's + background maintenance feature; this is the same as using the + `--maintenance=enable` value for this option. Use the + `--maintenance=disable` to remove each considered enlistment + from background maintenance. Use `--maitnenance=keep' to leave + the background maintenance configuration untouched for These + repositories. Diagnose ~~~~~~~~ diff --git a/scalar.c b/scalar.c index dd6e1447e0..847d2dd2f5 100644 --- a/scalar.c +++ b/scalar.c @@ -668,13 +668,19 @@ static int remove_deleted_enlistment(struct strbuf *path) static int cmd_reconfigure(int argc, const char **argv) { int all = 0; + const char *maintenance_str = NULL; + int maintenance = 1; /* Enable maintenance by default. */ + struct option options[] = { OPT_BOOL('a', "all", &all, N_("reconfigure all registered enlistments")), + OPT_STRING(0, "maintenance", &maintenance_str, + N_(""), + N_("signal how to adjust background maintenance")), OPT_END(), }; const char * const usage[] = { - N_("scalar reconfigure [--all | ]"), + N_("scalar reconfigure [--maintenance=] [--all | ]"), NULL }; struct string_list scalar_repos = STRING_LIST_INIT_DUP; @@ -694,6 +700,18 @@ static int cmd_reconfigure(int argc, const char **argv) usage_msg_opt(_("--all or , but not both"), usage, options); + if (maintenance_str) { + if (!strcmp(maintenance_str, "enable")) + maintenance = 1; + else if (!strcmp(maintenance_str, "disable")) + maintenance = 0; + else if (!strcmp(maintenance_str, "keep")) + maintenance = -1; + else + die(_("unknown mode for --maintenance option: %s"), + maintenance_str); + } + git_config(get_scalar_repos, &scalar_repos); for (size_t i = 0; i < scalar_repos.nr; i++) { @@ -758,7 +776,8 @@ static int cmd_reconfigure(int argc, const char **argv) the_repository = old_repo; repo_clear(&r); - if (toggle_maintenance(1) >= 0) + if (maintenance >= 0 && + toggle_maintenance(maintenance) >= 0) succeeded = 1; loop_end: diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index 89a6a2a24d..bd6f0c40d2 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -210,7 +210,18 @@ test_expect_success 'scalar reconfigure' ' GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a && test_path_is_file one/src/cron.txt && test true = "$(git -C one/src config core.preloadIndex)" && - test_subcommand git maintenance start