Skip to content

Commit cb59d55

Browse files
dschogitster
authored andcommitted
scalar: allow reconfiguring an existing enlistment
This comes in handy during Scalar upgrades, or when config settings were messed up by mistake. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7020c88 commit cb59d55

File tree

3 files changed

+67
-28
lines changed

3 files changed

+67
-28
lines changed

contrib/scalar/scalar.c

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,20 @@ static int run_git(const char *arg, ...)
108108
return res;
109109
}
110110

111-
static int set_recommended_config(void)
111+
static int set_recommended_config(int reconfigure)
112112
{
113113
struct {
114114
const char *key;
115115
const char *value;
116+
int overwrite_on_reconfigure;
116117
} config[] = {
117-
{ "am.keepCR", "true" },
118-
{ "core.FSCache", "true" },
119-
{ "core.multiPackIndex", "true" },
120-
{ "core.preloadIndex", "true" },
118+
/* Required */
119+
{ "am.keepCR", "true", 1 },
120+
{ "core.FSCache", "true", 1 },
121+
{ "core.multiPackIndex", "true", 1 },
122+
{ "core.preloadIndex", "true", 1 },
121123
#ifndef WIN32
122-
{ "core.untrackedCache", "true" },
124+
{ "core.untrackedCache", "true", 1 },
123125
#else
124126
/*
125127
* Unfortunately, Scalar's Functional Tests demonstrated
@@ -133,28 +135,29 @@ static int set_recommended_config(void)
133135
* Therefore, with a sad heart, we disable this very useful
134136
* feature on Windows.
135137
*/
136-
{ "core.untrackedCache", "false" },
138+
{ "core.untrackedCache", "false", 1 },
137139
#endif
138-
{ "core.logAllRefUpdates", "true" },
139-
{ "credential.https://dev.azure.com.useHttpPath", "true" },
140-
{ "credential.validate", "false" }, /* GCM4W-only */
141-
{ "gc.auto", "0" },
142-
{ "gui.GCWarning", "false" },
143-
{ "index.threads", "true" },
144-
{ "index.version", "4" },
145-
{ "merge.stat", "false" },
146-
{ "merge.renames", "true" },
147-
{ "pack.useBitmaps", "false" },
148-
{ "pack.useSparse", "true" },
149-
{ "receive.autoGC", "false" },
150-
{ "reset.quiet", "true" },
151-
{ "feature.manyFiles", "false" },
152-
{ "feature.experimental", "false" },
153-
{ "fetch.unpackLimit", "1" },
154-
{ "fetch.writeCommitGraph", "false" },
140+
{ "core.logAllRefUpdates", "true", 1 },
141+
{ "credential.https://dev.azure.com.useHttpPath", "true", 1 },
142+
{ "credential.validate", "false", 1 }, /* GCM4W-only */
143+
{ "gc.auto", "0", 1 },
144+
{ "gui.GCWarning", "false", 1 },
145+
{ "index.threads", "true", 1 },
146+
{ "index.version", "4", 1 },
147+
{ "merge.stat", "false", 1 },
148+
{ "merge.renames", "true", 1 },
149+
{ "pack.useBitmaps", "false", 1 },
150+
{ "pack.useSparse", "true", 1 },
151+
{ "receive.autoGC", "false", 1 },
152+
{ "reset.quiet", "true", 1 },
153+
{ "feature.manyFiles", "false", 1 },
154+
{ "feature.experimental", "false", 1 },
155+
{ "fetch.unpackLimit", "1", 1 },
156+
{ "fetch.writeCommitGraph", "false", 1 },
155157
#ifdef WIN32
156-
{ "http.sslBackend", "schannel" },
158+
{ "http.sslBackend", "schannel", 1 },
157159
#endif
160+
/* Optional */
158161
{ "status.aheadBehind", "false" },
159162
{ "commitGraph.generationVersion", "1" },
160163
{ "core.autoCRLF", "false" },
@@ -166,7 +169,8 @@ static int set_recommended_config(void)
166169
char *value;
167170

168171
for (i = 0; config[i].key; i++) {
169-
if (git_config_get_string(config[i].key, &value)) {
172+
if ((reconfigure && config[i].overwrite_on_reconfigure) ||
173+
git_config_get_string(config[i].key, &value)) {
170174
trace2_data_string("scalar", the_repository, config[i].key, "created");
171175
if (git_config_set_gently(config[i].key,
172176
config[i].value) < 0)
@@ -231,7 +235,7 @@ static int register_dir(void)
231235
int res = add_or_remove_enlistment(1);
232236

233237
if (!res)
234-
res = set_recommended_config();
238+
res = set_recommended_config(0);
235239

236240
if (!res)
237241
res = toggle_maintenance(1);
@@ -419,7 +423,7 @@ static int cmd_clone(int argc, const char **argv)
419423
(res = run_git("sparse-checkout", "init", "--cone", NULL)))
420424
goto cleanup;
421425

422-
if (set_recommended_config())
426+
if (set_recommended_config(0))
423427
return error(_("could not configure '%s'"), dir);
424428

425429
if ((res = run_git("fetch", "--quiet", "origin", NULL))) {
@@ -484,6 +488,24 @@ static int cmd_register(int argc, const char **argv)
484488
return register_dir();
485489
}
486490

491+
static int cmd_reconfigure(int argc, const char **argv)
492+
{
493+
struct option options[] = {
494+
OPT_END(),
495+
};
496+
const char * const usage[] = {
497+
N_("scalar reconfigure [<enlistment>]"),
498+
NULL
499+
};
500+
501+
argc = parse_options(argc, argv, NULL, options,
502+
usage, 0);
503+
504+
setup_enlistment_directory(argc, argv, usage, options, NULL);
505+
506+
return set_recommended_config(1);
507+
}
508+
487509
static int cmd_run(int argc, const char **argv)
488510
{
489511
struct option options[] = {
@@ -620,6 +642,7 @@ static struct {
620642
{ "register", cmd_register },
621643
{ "unregister", cmd_unregister },
622644
{ "run", cmd_run },
645+
{ "reconfigure", cmd_reconfigure },
623646
{ NULL, NULL},
624647
};
625648

contrib/scalar/scalar.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ scalar list
1313
scalar register [<enlistment>]
1414
scalar unregister [<enlistment>]
1515
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
16+
scalar reconfigure <enlistment>
1617

1718
DESCRIPTION
1819
-----------
@@ -117,6 +118,13 @@ opinionated default settings that make Git work more efficiently with
117118
large repositories. As this task is run as part of `scalar clone`
118119
automatically, explicit invocations of this task are rarely needed.
119120

121+
Reconfigure
122+
~~~~~~~~~~~
123+
124+
After a Scalar upgrade, or when the configuration of a Scalar enlistment
125+
was somehow corrupted or changed by mistake, this subcommand allows to
126+
reconfigure the enlistment.
127+
120128
SEE ALSO
121129
--------
122130
linkgit:git-clone[1], linkgit:git-maintenance[1].

contrib/scalar/t/t9099-scalar.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,12 @@ test_expect_success 'scalar clone' '
6565
)
6666
'
6767

68+
test_expect_success 'scalar reconfigure' '
69+
git init one/src &&
70+
scalar register one &&
71+
git -C one/src config core.preloadIndex false &&
72+
scalar reconfigure one &&
73+
test true = "$(git -C one/src config core.preloadIndex)"
74+
'
75+
6876
test_done

0 commit comments

Comments
 (0)