From c428216d4df289704ad01bb413c177bc0de32e0c Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Wed, 7 May 2025 01:50:34 +0000 Subject: [PATCH 1/5] scalar: customize register_dir()'s behavior In advance of adding a --[no-]maintenance option to several 'scalar' subcommands, extend the register_dir() method to include an option for how it should handle background maintenance. It's important that we understand the context of toggle_maintenance() that will enable _or disable_ maintenance depending on its input value. Add a doc comment with this information. Similarly, update register_dir() to either enable maintenance or leave it alone. Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- scalar.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/scalar.c b/scalar.c index d359f08bb8..b20b063471 100644 --- a/scalar.c +++ b/scalar.c @@ -209,6 +209,12 @@ static int set_recommended_config(int reconfigure) return 0; } +/** + * Enable or disable the maintenance mode for the current repository: + * + * * If 'enable' is nonzero, run 'git maintenance start'. + * * If 'enable' is zero, run 'git maintenance unregister --force'. + */ static int toggle_maintenance(int enable) { return run_git("maintenance", @@ -259,7 +265,15 @@ static int stop_fsmonitor_daemon(void) return 0; } -static int register_dir(void) +/** + * Register the current directory as a Scalar enlistment, and set the + * recommended configuration. + * + * * If 'maintenance' is non-zero, then enable background maintenance. + * * If 'maintenance' is zero, then leave background maintenance as it is + * currently configured. + */ +static int register_dir(int maintenance) { if (add_or_remove_enlistment(1)) return error(_("could not add enlistment")); @@ -267,8 +281,9 @@ static int register_dir(void) if (set_recommended_config(0)) return error(_("could not set recommended config")); - if (toggle_maintenance(1)) - warning(_("could not turn on maintenance")); + if (maintenance && + toggle_maintenance(maintenance)) + warning(_("could not toggle maintenance")); if (have_fsmonitor_support() && start_fsmonitor_daemon()) { return error(_("could not start the FSMonitor daemon")); @@ -550,7 +565,7 @@ static int cmd_clone(int argc, const char **argv) if (res) goto cleanup; - res = register_dir(); + res = register_dir(1); cleanup: free(branch_to_free); @@ -610,7 +625,7 @@ static int cmd_register(int argc, const char **argv) setup_enlistment_directory(argc, argv, usage, options, NULL); - return register_dir(); + return register_dir(1); } static int get_scalar_repos(const char *key, const char *value, @@ -803,13 +818,13 @@ static int cmd_run(int argc, const char **argv) strbuf_release(&buf); if (i == 0) - return register_dir(); + return register_dir(1); if (i > 0) return run_git("maintenance", "run", "--task", tasks[i].task, NULL); - if (register_dir()) + if (register_dir(1)) return -1; for (i = 1; tasks[i].arg; i++) if (run_git("maintenance", "run", From 9816e24a78e3973164f324d50caa948ecfa2ab81 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Wed, 7 May 2025 01:50:35 +0000 Subject: [PATCH 2/5] 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 +++++++- scalar.c | 8 ++++++-- t/t9210-scalar.sh | 13 ++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) 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 ~~~~~~~~~~ diff --git a/scalar.c b/scalar.c index b20b063471..da0c46bc96 100644 --- a/scalar.c +++ b/scalar.c @@ -612,11 +612,14 @@ static int cmd_list(int argc, const char **argv UNUSED) static int cmd_register(int argc, const char **argv) { + int maintenance = 1; struct option options[] = { + OPT_BOOL(0, "maintenance", &maintenance, + N_("specify if background maintenance should be enabled")), OPT_END(), }; const char * const usage[] = { - N_("scalar register []"), + N_("scalar register [--[no-]maintenance] []"), NULL }; @@ -625,7 +628,8 @@ static int cmd_register(int argc, const char **argv) setup_enlistment_directory(argc, argv, usage, options, NULL); - return register_dir(1); + /* If --no-maintenance, then leave maintenance as-is. */ + return register_dir(maintenance); } static int get_scalar_repos(const char *key, const char *value, diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index a81662713e..89a6a2a24d 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -108,7 +108,7 @@ test_expect_success 'scalar register warns when background maintenance fails' ' git init register-repo && GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \ scalar register register-repo 2>err && - grep "could not turn on maintenance" err + grep "could not toggle maintenance" err ' test_expect_success 'scalar unregister' ' @@ -129,6 +129,17 @@ test_expect_success 'scalar unregister' ' scalar unregister vanish ' +test_expect_success 'scalar register --no-maintenance' ' + git init register-no-maint && + event_log="$(pwd)/no-maint.event" && + GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \ + GIT_TRACE2_EVENT="$event_log" \ + GIT_TRACE2_EVENT_DEPTH=100 \ + scalar register --no-maintenance register-no-maint 2>err && + test_must_be_empty err && + test_subcommand ! git maintenance unregister --force Date: Wed, 7 May 2025 01:50:36 +0000 Subject: [PATCH 3/5] 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(-) 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: [PATCH 4/5] 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(-) 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: [PATCH 5/5] 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(-) 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;