From: Derrick Stolee <stolee@xxxxxxxxx> 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 <stolee@xxxxxxxxx> --- Documentation/scalar.adoc | 8 +++++++- scalar.c | 17 ++++++++++------- t/t9210-scalar.sh | 7 +++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc index 7e4259c6743f..b2b244a86499 100644 --- a/Documentation/scalar.adoc +++ b/Documentation/scalar.adoc @@ -11,7 +11,7 @@ SYNOPSIS scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] [--[no-]src] <url> [<enlistment>] scalar list -scalar register [<enlistment>] +scalar register [--[no-]maintenance] [<enlistment>] scalar unregister [<enlistment>] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>] scalar reconfigure [ --all | <enlistment> ] @@ -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 d359f08bb8e2..2a21fd55f39b 100644 --- a/scalar.c +++ b/scalar.c @@ -259,7 +259,7 @@ static int stop_fsmonitor_daemon(void) return 0; } -static int register_dir(void) +static int register_dir(int maintenance) { if (add_or_remove_enlistment(1)) return error(_("could not add enlistment")); @@ -267,7 +267,7 @@ static int register_dir(void) if (set_recommended_config(0)) return error(_("could not set recommended config")); - if (toggle_maintenance(1)) + if (toggle_maintenance(maintenance)) warning(_("could not turn on maintenance")); if (have_fsmonitor_support() && start_fsmonitor_daemon()) { @@ -550,7 +550,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); @@ -597,11 +597,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 [<enlistment>]"), + N_("scalar register [--[no-]maintenance] [<enlistment>]"), NULL }; @@ -610,7 +613,7 @@ static int cmd_register(int argc, const char **argv) setup_enlistment_directory(argc, argv, usage, options, NULL); - return register_dir(); + return register_dir(maintenance); } static int get_scalar_repos(const char *key, const char *value, @@ -803,13 +806,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", diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index a81662713eb8..a488f72de9fe 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -129,6 +129,13 @@ test_expect_success 'scalar unregister' ' scalar unregister vanish ' +test_expect_success 'scalar register --no-maintenance' ' + git init register-no-maint && + GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \ + scalar register --no-maintenance register-no-maint 2>err && + test_must_be_empty err +' + test_expect_success 'set up repository to clone' ' test_commit first && test_commit second && -- gitgitgadget