Skip to content

Commit 8c8d7d0

Browse files
committed
Merge branch 'ds/scalar-no-maintenance' into jch
Two "scalar" subcommands that adds a repository that hasn't been under "scalar"'s control are taught an option not to enable the scheduled maintenance on it. * ds/scalar-no-maintenance: scalar reconfigure: add --maintenance=<mode> option scalar clone: add --no-maintenance option scalar register: add --no-maintenance option scalar: customize register_dir()'s behavior
2 parents e774d20 + a34fef8 commit 8c8d7d0

File tree

4 files changed

+114
-20
lines changed

4 files changed

+114
-20
lines changed

Documentation/scalar.adoc

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ SYNOPSIS
99
--------
1010
[verse]
1111
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
12-
[--[no-]src] <url> [<enlistment>]
12+
[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]
1313
scalar list
14-
scalar register [<enlistment>]
14+
scalar register [--[no-]maintenance] [<enlistment>]
1515
scalar unregister [<enlistment>]
1616
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
17-
scalar reconfigure [ --all | <enlistment> ]
17+
scalar reconfigure [--maintenance=<mode>] [ --all | <enlistment> ]
1818
scalar diagnose [<enlistment>]
1919
scalar delete <enlistment>
2020

@@ -97,6 +97,11 @@ cloning. If the HEAD at the remote did not point at any branch when
9797
A sparse-checkout is initialized by default. This behavior can be
9898
turned off via `--full-clone`.
9999

100+
--[no-]maintenance::
101+
By default, `scalar clone` configures the enlistment to use Git's
102+
background maintenance feature. Use the `--no-maintenance` to skip
103+
this configuration.
104+
100105
List
101106
~~~~
102107

@@ -117,6 +122,12 @@ Note: when this subcommand is called in a worktree that is called `src/`, its
117122
parent directory is considered to be the Scalar enlistment. If the worktree is
118123
_not_ called `src/`, it itself will be considered to be the Scalar enlistment.
119124

125+
--[no-]maintenance::
126+
By default, `scalar register` configures the enlistment to use Git's
127+
background maintenance feature. Use the `--no-maintenance` to skip
128+
this configuration. This does not disable any maintenance that may
129+
already be enabled in other ways.
130+
120131
Unregister
121132
~~~~~~~~~~
122133

@@ -149,8 +160,19 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment
149160
was somehow corrupted or changed by mistake, this subcommand allows to
150161
reconfigure the enlistment.
151162

152-
With the `--all` option, all enlistments currently registered with Scalar
153-
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.
154176

155177
Diagnose
156178
~~~~~~~~

scalar.c

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ static int set_recommended_config(int reconfigure)
210210
return 0;
211211
}
212212

213+
/**
214+
* Enable or disable the maintenance mode for the current repository:
215+
*
216+
* * If 'enable' is nonzero, run 'git maintenance start'.
217+
* * If 'enable' is zero, run 'git maintenance unregister --force'.
218+
*/
213219
static int toggle_maintenance(int enable)
214220
{
215221
return run_git("maintenance",
@@ -260,16 +266,25 @@ static int stop_fsmonitor_daemon(void)
260266
return 0;
261267
}
262268

263-
static int register_dir(void)
269+
/**
270+
* Register the current directory as a Scalar enlistment, and set the
271+
* recommended configuration.
272+
*
273+
* * If 'maintenance' is non-zero, then enable background maintenance.
274+
* * If 'maintenance' is zero, then leave background maintenance as it is
275+
* currently configured.
276+
*/
277+
static int register_dir(int maintenance)
264278
{
265279
if (add_or_remove_enlistment(1))
266280
return error(_("could not add enlistment"));
267281

268282
if (set_recommended_config(0))
269283
return error(_("could not set recommended config"));
270284

271-
if (toggle_maintenance(1))
272-
warning(_("could not turn on maintenance"));
285+
if (maintenance &&
286+
toggle_maintenance(maintenance))
287+
warning(_("could not toggle maintenance"));
273288

274289
if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
275290
return error(_("could not start the FSMonitor daemon"));
@@ -412,7 +427,7 @@ static int cmd_clone(int argc, const char **argv)
412427
const char *branch = NULL;
413428
char *branch_to_free = NULL;
414429
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
415-
int src = 1, tags = 1;
430+
int src = 1, tags = 1, maintenance = 1;
416431
struct option clone_options[] = {
417432
OPT_STRING('b', "branch", &branch, N_("<branch>"),
418433
N_("branch to checkout after clone")),
@@ -425,11 +440,13 @@ static int cmd_clone(int argc, const char **argv)
425440
N_("create repository within 'src' directory")),
426441
OPT_BOOL(0, "tags", &tags,
427442
N_("specify if tags should be fetched during clone")),
443+
OPT_BOOL(0, "maintenance", &maintenance,
444+
N_("specify if background maintenance should be enabled")),
428445
OPT_END(),
429446
};
430447
const char * const clone_usage[] = {
431448
N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
432-
"\t[--[no-]src] [--[no-]tags] <url> [<enlistment>]"),
449+
"\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]"),
433450
NULL
434451
};
435452
const char *url;
@@ -551,7 +568,8 @@ static int cmd_clone(int argc, const char **argv)
551568
if (res)
552569
goto cleanup;
553570

554-
res = register_dir();
571+
/* If --no-maintenance, then skip maintenance command entirely. */
572+
res = register_dir(maintenance);
555573

556574
cleanup:
557575
free(branch_to_free);
@@ -598,11 +616,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
598616

599617
static int cmd_register(int argc, const char **argv)
600618
{
619+
int maintenance = 1;
601620
struct option options[] = {
621+
OPT_BOOL(0, "maintenance", &maintenance,
622+
N_("specify if background maintenance should be enabled")),
602623
OPT_END(),
603624
};
604625
const char * const usage[] = {
605-
N_("scalar register [<enlistment>]"),
626+
N_("scalar register [--[no-]maintenance] [<enlistment>]"),
606627
NULL
607628
};
608629

@@ -611,7 +632,8 @@ static int cmd_register(int argc, const char **argv)
611632

612633
setup_enlistment_directory(argc, argv, usage, options, NULL);
613634

614-
return register_dir();
635+
/* If --no-maintenance, then leave maintenance as-is. */
636+
return register_dir(maintenance);
615637
}
616638

617639
static int get_scalar_repos(const char *key, const char *value,
@@ -647,13 +669,19 @@ static int remove_deleted_enlistment(struct strbuf *path)
647669
static int cmd_reconfigure(int argc, const char **argv)
648670
{
649671
int all = 0;
672+
const char *maintenance_str = NULL;
673+
int maintenance = 1; /* Enable maintenance by default. */
674+
650675
struct option options[] = {
651676
OPT_BOOL('a', "all", &all,
652677
N_("reconfigure all registered enlistments")),
678+
OPT_STRING(0, "maintenance", &maintenance_str,
679+
N_("<mode>"),
680+
N_("signal how to adjust background maintenance")),
653681
OPT_END(),
654682
};
655683
const char * const usage[] = {
656-
N_("scalar reconfigure [--all | <enlistment>]"),
684+
N_("scalar reconfigure [--maintenance=<mode>] [--all | <enlistment>]"),
657685
NULL
658686
};
659687
struct string_list scalar_repos = STRING_LIST_INIT_DUP;
@@ -673,6 +701,18 @@ static int cmd_reconfigure(int argc, const char **argv)
673701
usage_msg_opt(_("--all or <enlistment>, but not both"),
674702
usage, options);
675703

704+
if (maintenance_str) {
705+
if (!strcmp(maintenance_str, "enable"))
706+
maintenance = 1;
707+
else if (!strcmp(maintenance_str, "disable"))
708+
maintenance = 0;
709+
else if (!strcmp(maintenance_str, "keep"))
710+
maintenance = -1;
711+
else
712+
die(_("unknown mode for --maintenance option: %s"),
713+
maintenance_str);
714+
}
715+
676716
git_config(get_scalar_repos, &scalar_repos);
677717

678718
for (size_t i = 0; i < scalar_repos.nr; i++) {
@@ -737,7 +777,8 @@ static int cmd_reconfigure(int argc, const char **argv)
737777
the_repository = old_repo;
738778
repo_clear(&r);
739779

740-
if (toggle_maintenance(1) >= 0)
780+
if (maintenance >= 0 &&
781+
toggle_maintenance(maintenance) >= 0)
741782
succeeded = 1;
742783

743784
loop_end:
@@ -804,13 +845,13 @@ static int cmd_run(int argc, const char **argv)
804845
strbuf_release(&buf);
805846

806847
if (i == 0)
807-
return register_dir();
848+
return register_dir(1);
808849

809850
if (i > 0)
810851
return run_git("maintenance", "run",
811852
"--task", tasks[i].task, NULL);
812853

813-
if (register_dir())
854+
if (register_dir(1))
814855
return -1;
815856
for (i = 1; tasks[i].arg; i++)
816857
if (run_git("maintenance", "run",

t/t9210-scalar.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ test_expect_success 'scalar register warns when background maintenance fails' '
108108
git init register-repo &&
109109
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
110110
scalar register register-repo 2>err &&
111-
grep "could not turn on maintenance" err
111+
grep "could not toggle maintenance" err
112112
'
113113

114114
test_expect_success 'scalar unregister' '
@@ -129,6 +129,17 @@ test_expect_success 'scalar unregister' '
129129
scalar unregister vanish
130130
'
131131

132+
test_expect_success 'scalar register --no-maintenance' '
133+
git init register-no-maint &&
134+
event_log="$(pwd)/no-maint.event" &&
135+
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
136+
GIT_TRACE2_EVENT="$event_log" \
137+
GIT_TRACE2_EVENT_DEPTH=100 \
138+
scalar register --no-maintenance register-no-maint 2>err &&
139+
test_must_be_empty err &&
140+
test_subcommand ! git maintenance unregister --force <no-maint.event
141+
'
142+
132143
test_expect_success 'set up repository to clone' '
133144
test_commit first &&
134145
test_commit second &&
@@ -199,7 +210,18 @@ test_expect_success 'scalar reconfigure' '
199210
GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
200211
test_path_is_file one/src/cron.txt &&
201212
test true = "$(git -C one/src config core.preloadIndex)" &&
202-
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
203225
'
204226

205227
test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '

t/t9211-scalar-clone.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,16 @@ test_expect_success 'progress without tty' '
177177
test_expect_success 'scalar clone warns when background maintenance fails' '
178178
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
179179
scalar clone "file://$(pwd)/to-clone" maint-fail 2>err &&
180-
grep "could not turn on maintenance" err
180+
grep "could not toggle maintenance" err
181+
'
182+
183+
test_expect_success 'scalar clone --no-maintenance' '
184+
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
185+
GIT_TRACE2_EVENT="$(pwd)/no-maint.event" \
186+
GIT_TRACE2_EVENT_DEPTH=100 \
187+
scalar clone --no-maintenance "file://$(pwd)/to-clone" no-maint 2>err &&
188+
! grep "could not toggle maintenance" err &&
189+
test_subcommand ! git maintenance unregister --force <no-maint.event
181190
'
182191

183192
test_expect_success '`scalar clone --no-src`' '

0 commit comments

Comments
 (0)