Skip to content

Commit a34fef8

Browse files
derrickstoleegitster
authored andcommitted
scalar reconfigure: add --maintenance=<mode> 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=<mode> option to 'scalar reconfigure' that provides options for enabling (default), disabling, or leaving background maintenance config as-is. Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 882ce0c commit a34fef8

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

Documentation/scalar.adoc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ scalar list
1414
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

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

163-
With the `--all` option, all enlistments currently registered with Scalar
164-
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.
165176

166177
Diagnose
167178
~~~~~~~~

scalar.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,19 @@ static int remove_deleted_enlistment(struct strbuf *path)
668668
static int cmd_reconfigure(int argc, const char **argv)
669669
{
670670
int all = 0;
671+
const char *maintenance_str = NULL;
672+
int maintenance = 1; /* Enable maintenance by default. */
673+
671674
struct option options[] = {
672675
OPT_BOOL('a', "all", &all,
673676
N_("reconfigure all registered enlistments")),
677+
OPT_STRING(0, "maintenance", &maintenance_str,
678+
N_("<mode>"),
679+
N_("signal how to adjust background maintenance")),
674680
OPT_END(),
675681
};
676682
const char * const usage[] = {
677-
N_("scalar reconfigure [--all | <enlistment>]"),
683+
N_("scalar reconfigure [--maintenance=<mode>] [--all | <enlistment>]"),
678684
NULL
679685
};
680686
struct string_list scalar_repos = STRING_LIST_INIT_DUP;
@@ -694,6 +700,18 @@ static int cmd_reconfigure(int argc, const char **argv)
694700
usage_msg_opt(_("--all or <enlistment>, but not both"),
695701
usage, options);
696702

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+
697715
git_config(get_scalar_repos, &scalar_repos);
698716

699717
for (size_t i = 0; i < scalar_repos.nr; i++) {
@@ -758,7 +776,8 @@ static int cmd_reconfigure(int argc, const char **argv)
758776
the_repository = old_repo;
759777
repo_clear(&r);
760778

761-
if (toggle_maintenance(1) >= 0)
779+
if (maintenance >= 0 &&
780+
toggle_maintenance(maintenance) >= 0)
762781
succeeded = 1;
763782

764783
loop_end:

t/t9210-scalar.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,18 @@ test_expect_success 'scalar reconfigure' '
210210
GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
211211
test_path_is_file one/src/cron.txt &&
212212
test true = "$(git -C one/src config core.preloadIndex)" &&
213-
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
214225
'
215226

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

0 commit comments

Comments
 (0)