Skip to content

Commit 95c79ef

Browse files
committed
Merge branch 'ds/scalar-no-maintenance'
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: improve --maintenance docs 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 abb674a + e918917 commit 95c79ef

File tree

4 files changed

+113
-20
lines changed

4 files changed

+113
-20
lines changed

Documentation/scalar.adoc

Lines changed: 26 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=(enable|disable|keep)] [ --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,18 @@ 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=(enable|disable|keep)::
169+
By default, Scalar configures the enlistment to use Git's
170+
background maintenance feature; this is the same as using the
171+
`enable` value for this option. Use the `disable` value to
172+
remove each considered enlistment from background maintenance.
173+
Use `keep' to leave the background maintenance configuration
174+
untouched for these repositories.
154175

155176
Diagnose
156177
~~~~~~~~

scalar.c

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

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

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

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

270-
if (toggle_maintenance(1))
271-
warning(_("could not turn on maintenance"));
284+
if (maintenance &&
285+
toggle_maintenance(maintenance))
286+
warning(_("could not toggle maintenance"));
272287

273288
if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
274289
return error(_("could not start the FSMonitor daemon"));
@@ -411,7 +426,7 @@ static int cmd_clone(int argc, const char **argv)
411426
const char *branch = NULL;
412427
char *branch_to_free = NULL;
413428
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
414-
int src = 1, tags = 1;
429+
int src = 1, tags = 1, maintenance = 1;
415430
struct option clone_options[] = {
416431
OPT_STRING('b', "branch", &branch, N_("<branch>"),
417432
N_("branch to checkout after clone")),
@@ -424,11 +439,13 @@ static int cmd_clone(int argc, const char **argv)
424439
N_("create repository within 'src' directory")),
425440
OPT_BOOL(0, "tags", &tags,
426441
N_("specify if tags should be fetched during clone")),
442+
OPT_BOOL(0, "maintenance", &maintenance,
443+
N_("specify if background maintenance should be enabled")),
427444
OPT_END(),
428445
};
429446
const char * const clone_usage[] = {
430447
N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
431-
"\t[--[no-]src] [--[no-]tags] <url> [<enlistment>]"),
448+
"\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]"),
432449
NULL
433450
};
434451
const char *url;
@@ -550,7 +567,8 @@ static int cmd_clone(int argc, const char **argv)
550567
if (res)
551568
goto cleanup;
552569

553-
res = register_dir();
570+
/* If --no-maintenance, then skip maintenance command entirely. */
571+
res = register_dir(maintenance);
554572

555573
cleanup:
556574
free(branch_to_free);
@@ -597,11 +615,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
597615

598616
static int cmd_register(int argc, const char **argv)
599617
{
618+
int maintenance = 1;
600619
struct option options[] = {
620+
OPT_BOOL(0, "maintenance", &maintenance,
621+
N_("specify if background maintenance should be enabled")),
601622
OPT_END(),
602623
};
603624
const char * const usage[] = {
604-
N_("scalar register [<enlistment>]"),
625+
N_("scalar register [--[no-]maintenance] [<enlistment>]"),
605626
NULL
606627
};
607628

@@ -610,7 +631,8 @@ static int cmd_register(int argc, const char **argv)
610631

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

613-
return register_dir();
634+
/* If --no-maintenance, then leave maintenance as-is. */
635+
return register_dir(maintenance);
614636
}
615637

616638
static int get_scalar_repos(const char *key, const char *value,
@@ -646,13 +668,19 @@ static int remove_deleted_enlistment(struct strbuf *path)
646668
static int cmd_reconfigure(int argc, const char **argv)
647669
{
648670
int all = 0;
671+
const char *maintenance_str = NULL;
672+
int maintenance = 1; /* Enable maintenance by default. */
673+
649674
struct option options[] = {
650675
OPT_BOOL('a', "all", &all,
651676
N_("reconfigure all registered enlistments")),
677+
OPT_STRING(0, "maintenance", &maintenance_str,
678+
N_("(enable|disable|keep)"),
679+
N_("signal how to adjust background maintenance")),
652680
OPT_END(),
653681
};
654682
const char * const usage[] = {
655-
N_("scalar reconfigure [--all | <enlistment>]"),
683+
N_("scalar reconfigure [--maintenance=(enable|disable|keep)] [--all | <enlistment>]"),
656684
NULL
657685
};
658686
struct string_list scalar_repos = STRING_LIST_INIT_DUP;
@@ -672,6 +700,18 @@ static int cmd_reconfigure(int argc, const char **argv)
672700
usage_msg_opt(_("--all or <enlistment>, but not both"),
673701
usage, options);
674702

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

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

739-
if (toggle_maintenance(1) >= 0)
779+
if (maintenance >= 0 &&
780+
toggle_maintenance(maintenance) >= 0)
740781
succeeded = 1;
741782

742783
loop_end:
@@ -803,13 +844,13 @@ static int cmd_run(int argc, const char **argv)
803844
strbuf_release(&buf);
804845

805846
if (i == 0)
806-
return register_dir();
847+
return register_dir(1);
807848

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

812-
if (register_dir())
853+
if (register_dir(1))
813854
return -1;
814855
for (i = 1; tasks[i].arg; i++)
815856
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)