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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 3, 2021 at 13:34 UTC cb59d55ec1c0b9e25d8a54efe4ce00b72ba62bc4
3 files changed +67 -28
contrib/scalar/scalar.c
+51 -28
@@ -108,18 +108,20 @@ static int run_git(const char *arg, ...)
108 return res;
109 }
110
111 -static int set_recommended_config(void)
111 +static int set_recommended_config(int reconfigure)
112 {
113 struct {
114 const char *key;
115 const char *value;
116 + int overwrite_on_reconfigure;
117 } 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 },
123 #ifndef WIN32
122 - { "core.untrackedCache", "true" },
124 + { "core.untrackedCache", "true", 1 },
125 #else
126 /*
127 * Unfortunately, Scalar's Functional Tests demonstrated
@@ -133,28 +135,29 @@ static int set_recommended_config(void)
135 * Therefore, with a sad heart, we disable this very useful
136 * feature on Windows.
137 */
136 - { "core.untrackedCache", "false" },
138 + { "core.untrackedCache", "false", 1 },
139 #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 },
157 #ifdef WIN32
156 - { "http.sslBackend", "schannel" },
158 + { "http.sslBackend", "schannel", 1 },
159 #endif
160 + /* Optional */
161 { "status.aheadBehind", "false" },
162 { "commitGraph.generationVersion", "1" },
163 { "core.autoCRLF", "false" },
@@ -166,7 +169,8 @@ static int set_recommended_config(void)
169 char *value;
170
171 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)) {
174 trace2_data_string("scalar", the_repository, config[i].key, "created");
175 if (git_config_set_gently(config[i].key,
176 config[i].value) < 0)
@@ -231,7 +235,7 @@ static int register_dir(void)
235 int res = add_or_remove_enlistment(1);
236
237 if (!res)
234 - res = set_recommended_config();
238 + res = set_recommended_config(0);
239
240 if (!res)
241 res = toggle_maintenance(1);
@@ -419,7 +423,7 @@ static int cmd_clone(int argc, const char **argv)
423 (res = run_git("sparse-checkout", "init", "--cone", NULL)))
424 goto cleanup;
425
422 - if (set_recommended_config())
426 + if (set_recommended_config(0))
427 return error(_("could not configure '%s'"), dir);
428
429 if ((res = run_git("fetch", "--quiet", "origin", NULL))) {
@@ -484,6 +488,24 @@ static int cmd_register(int argc, const char **argv)
488 return register_dir();
489 }
490
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 +
509 static int cmd_run(int argc, const char **argv)
510 {
511 struct option options[] = {
@@ -620,6 +642,7 @@ static struct {
642 { "register", cmd_register },
643 { "unregister", cmd_unregister },
644 { "run", cmd_run },
645 + { "reconfigure", cmd_reconfigure },
646 { NULL, NULL},
647 };
648
contrib/scalar/scalar.txt
+8
@@ -13,6 +13,7 @@ scalar list
13 scalar register [<enlistment>]
14 scalar unregister [<enlistment>]
15 scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
16 +scalar reconfigure <enlistment>
17
18 DESCRIPTION
19 -----------
@@ -117,6 +118,13 @@ opinionated default settings that make Git work more efficiently with
118 large repositories. As this task is run as part of `scalar clone`
119 automatically, explicit invocations of this task are rarely needed.
120
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 +
128 SEE ALSO
129 --------
130 linkgit:git-clone[1], linkgit:git-maintenance[1].
contrib/scalar/t/t9099-scalar.sh
+8
@@ -65,4 +65,12 @@ test_expect_success 'scalar clone' '
65 )
66 '
67
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 +
76 test_done