scalar: annotate config file with "set by scalar"

A repo may have config options set by 'scalar clone' or 'scalar register' and then updated by 'scalar reconfigure'. It can be helpful to point out which of those options were set by the latest scalar recommendations. Add "# set by scalar" to the end of each config option to assist users in identifying why these config options were set in their repo. Use a new helper method to simplify the two callsites. Co-authored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Dec 12, 2025 at 15:15 UTC 48695fcde51e10d6d6e72653fb94b5fd339cd6e6
2 files changed +20 -7
scalar.c
+17 -7
@@ -19,6 +19,7 @@
19 #include "help.h"
20 #include "setup.h"
21 #include "trace2.h"
22 +#include "path.h"
23
24 static void setup_enlistment_directory(int argc, const char **argv,
25 const char * const *usagestr,
@@ -95,7 +96,17 @@ struct scalar_config {
96 int overwrite_on_reconfigure;
97 };
98
98 -static int set_scalar_config(const struct scalar_config *config, int reconfigure)
99 +static int set_scalar_config(const char *key, const char *value)
100 +{
101 + char *file = repo_git_path(the_repository, "config");
102 + int res = repo_config_set_multivar_in_file_gently(the_repository, file,
103 + key, value, NULL,
104 + " # set by scalar", 0);
105 + free(file);
106 + return res;
107 +}
108 +
109 +static int set_config_if_missing(const struct scalar_config *config, int reconfigure)
110 {
111 char *value = NULL;
112 int res;
@@ -103,7 +114,7 @@ static int set_scalar_config(const struct scalar_config *config, int reconfigure
114 if ((reconfigure && config->overwrite_on_reconfigure) ||
115 repo_config_get_string(the_repository, config->key, &value)) {
116 trace2_data_string("scalar", the_repository, config->key, "created");
106 - res = repo_config_set_gently(the_repository, config->key, config->value);
117 + res = set_scalar_config(config->key, config->value);
118 } else {
119 trace2_data_string("scalar", the_repository, config->key, "exists");
120 res = 0;
@@ -178,14 +189,14 @@ static int set_recommended_config(int reconfigure)
189 char *value;
190
191 for (i = 0; config[i].key; i++) {
181 - if (set_scalar_config(config + i, reconfigure))
192 + if (set_config_if_missing(config + i, reconfigure))
193 return error(_("could not configure %s=%s"),
194 config[i].key, config[i].value);
195 }
196
197 if (have_fsmonitor_support()) {
198 struct scalar_config fsmonitor = { "core.fsmonitor", "true" };
188 - if (set_scalar_config(&fsmonitor, reconfigure))
199 + if (set_config_if_missing(&fsmonitor, reconfigure))
200 return error(_("could not configure %s=%s"),
201 fsmonitor.key, fsmonitor.value);
202 }
@@ -197,9 +208,8 @@ static int set_recommended_config(int reconfigure)
208 if (repo_config_get_string(the_repository, "log.excludeDecoration", &value)) {
209 trace2_data_string("scalar", the_repository,
210 "log.excludeDecoration", "created");
200 - if (repo_config_set_multivar_gently(the_repository, "log.excludeDecoration",
201 - "refs/prefetch/*",
202 - CONFIG_REGEX_NONE, 0))
211 + if (set_scalar_config("log.excludeDecoration",
212 + "refs/prefetch/*"))
213 return error(_("could not configure "
214 "log.excludeDecoration"));
215 } else {
t/t9210-scalar.sh
+3
@@ -210,6 +210,9 @@ test_expect_success 'scalar reconfigure' '
210 GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
211 test_path_is_file one/src/cron.txt &&
212 test true = "$(git -C one/src config core.preloadIndex)" &&
213 + test_grep "preloadIndex = true # set by scalar" one/src/.git/config &&
214 + test_grep "excludeDecoration = refs/prefetch/\* # set by scalar" one/src/.git/config &&
215 +
216 test_subcommand git maintenance start <reconfigure &&
217 test_subcommand ! git maintenance unregister --force <reconfigure &&
218