From 9816e24a78e3973164f324d50caa948ecfa2ab81 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Wed, 7 May 2025 01:50:35 +0000 Subject: scalar register: add --no-maintenance option When registering a repository with Scalar to get the latest opinionated configuration, the 'scalar register' command will also set up background maintenance. This is a recommended feature for most user scenarios. However, this is not always recommended in some scenarios where background modifications may interfere with foreground activities. Specifically, setting up a clone for use in automation may require doing certain maintenance steps in the foreground that could become blocked by concurrent background maintenance operations. Allow the user to specify --no-maintenance to 'scalar register'. This requires updating the method prototype for register_dir(), so use the default of enabling this value when otherwise specified. Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- Documentation/scalar.adoc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Documentation') diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc index 7e4259c674..b2b244a864 100644 --- a/Documentation/scalar.adoc +++ b/Documentation/scalar.adoc @@ -11,7 +11,7 @@ SYNOPSIS scalar clone [--single-branch] [--branch ] [--full-clone] [--[no-]src] [] scalar list -scalar register [] +scalar register [--[no-]maintenance] [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] scalar reconfigure [ --all | ] @@ -117,6 +117,12 @@ Note: when this subcommand is called in a worktree that is called `src/`, its parent directory is considered to be the Scalar enlistment. If the worktree is _not_ called `src/`, it itself will be considered to be the Scalar enlistment. +--[no-]maintenance:: + By default, `scalar register` configures the enlistment to use Git's + background maintenance feature. Use the `--no-maintenance` to skip + this configuration. This does not disable any maintenance that may + already be enabled in other ways. + Unregister ~~~~~~~~~~ -- cgit v1.3-5-g9baa From 882ce0c475167039ca368d34699e113042ea47ae Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Wed, 7 May 2025 01:50:36 +0000 Subject: scalar clone: add --no-maintenance option When creating a new enlistment via 'scalar clone', the default is to set up situations that work for most user scenarios. Background maintenance is one of those highly-recommended options for most users. However, when using 'scalar clone' to create an enlistment in a different situation, such as prepping a VM image, it may be valuable to disable background maintenance so the manual maintenance steps do not get blocked by concurrent background maintenance activities. Add a new --no-maintenance option to 'scalar clone'. Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- Documentation/scalar.adoc | 7 ++++++- scalar.c | 9 ++++++--- t/t9211-scalar-clone.sh | 11 ++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) (limited to 'Documentation') diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc index b2b244a864..7753df3b43 100644 --- a/Documentation/scalar.adoc +++ b/Documentation/scalar.adoc @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] scalar clone [--single-branch] [--branch ] [--full-clone] - [--[no-]src] [] + [--[no-]src] [--[no-]tags] [--[no-]maintenance] [] scalar list scalar register [--[no-]maintenance] [] scalar unregister [] @@ -97,6 +97,11 @@ cloning. If the HEAD at the remote did not point at any branch when A sparse-checkout is initialized by default. This behavior can be turned off via `--full-clone`. +--[no-]maintenance:: + By default, `scalar clone` configures the enlistment to use Git's + background maintenance feature. Use the `--no-maintenance` to skip + this configuration. + List ~~~~ diff --git a/scalar.c b/scalar.c index da0c46bc96..dd6e1447e0 100644 --- a/scalar.c +++ b/scalar.c @@ -426,7 +426,7 @@ static int cmd_clone(int argc, const char **argv) const char *branch = NULL; char *branch_to_free = NULL; int full_clone = 0, single_branch = 0, show_progress = isatty(2); - int src = 1, tags = 1; + int src = 1, tags = 1, maintenance = 1; struct option clone_options[] = { OPT_STRING('b', "branch", &branch, N_(""), N_("branch to checkout after clone")), @@ -439,11 +439,13 @@ static int cmd_clone(int argc, const char **argv) N_("create repository within 'src' directory")), OPT_BOOL(0, "tags", &tags, N_("specify if tags should be fetched during clone")), + OPT_BOOL(0, "maintenance", &maintenance, + N_("specify if background maintenance should be enabled")), OPT_END(), }; const char * const clone_usage[] = { N_("scalar clone [--single-branch] [--branch ] [--full-clone]\n" - "\t[--[no-]src] [--[no-]tags] []"), + "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] []"), NULL }; const char *url; @@ -565,7 +567,8 @@ static int cmd_clone(int argc, const char **argv) if (res) goto cleanup; - res = register_dir(1); + /* If --no-maintenance, then skip maintenance command entirely. */ + res = register_dir(maintenance); cleanup: free(branch_to_free); diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh index 01f71910f5..bfbf22a462 100755 --- a/t/t9211-scalar-clone.sh +++ b/t/t9211-scalar-clone.sh @@ -177,7 +177,16 @@ test_expect_success 'progress without tty' ' test_expect_success 'scalar clone warns when background maintenance fails' ' GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \ scalar clone "file://$(pwd)/to-clone" maint-fail 2>err && - grep "could not turn on maintenance" err + grep "could not toggle maintenance" err +' + +test_expect_success 'scalar clone --no-maintenance' ' + GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \ + GIT_TRACE2_EVENT="$(pwd)/no-maint.event" \ + GIT_TRACE2_EVENT_DEPTH=100 \ + scalar clone --no-maintenance "file://$(pwd)/to-clone" no-maint 2>err && + ! grep "could not toggle maintenance" err && + test_subcommand ! git maintenance unregister --force Date: Wed, 7 May 2025 01:50:37 +0000 Subject: 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 --- Documentation/scalar.adoc | 17 ++++++++++++++--- scalar.c | 23 +++++++++++++++++++++-- t/t9210-scalar.sh | 13 ++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) (limited to 'Documentation') 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 Date: Wed, 14 May 2025 09:52:44 -0400 Subject: scalar reconfigure: improve --maintenance docs The --maintenance option for 'scalar reconfigure' has three possible values. Improve the documentation by specifying the option in the -h help menu and usage information. Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- Documentation/scalar.adoc | 13 ++++++------- scalar.c | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'Documentation') diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc index 387527be1e..4bd5b150e8 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 [--maintenance=] [ --all | ] +scalar reconfigure [--maintenance=(enable|disable|keep)] [ --all | ] scalar diagnose [] scalar delete @@ -165,14 +165,13 @@ reconfigure the enlistment. registered with Scalar by the `scalar.repo` config key. Use this option after each upgrade to get the latest features. ---maintenance=:: +--maintenance=(enable|disable|keep):: 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. + `enable` value for this option. Use the `disable` value to + remove each considered enlistment from background maintenance. + Use `keep' to leave the background maintenance configuration + untouched for these repositories. Diagnose ~~~~~~~~ diff --git a/scalar.c b/scalar.c index 847d2dd2f5..355baf75e4 100644 --- a/scalar.c +++ b/scalar.c @@ -675,12 +675,12 @@ static int cmd_reconfigure(int argc, const char **argv) OPT_BOOL('a', "all", &all, N_("reconfigure all registered enlistments")), OPT_STRING(0, "maintenance", &maintenance_str, - N_(""), + N_("(enable|disable|keep)"), N_("signal how to adjust background maintenance")), OPT_END(), }; const char * const usage[] = { - N_("scalar reconfigure [--maintenance=] [--all | ]"), + N_("scalar reconfigure [--maintenance=(enable|disable|keep)] [--all | ]"), NULL }; struct string_list scalar_repos = STRING_LIST_INIT_DUP; -- cgit v1.3-5-g9baa