Skip to content

Commit 639ff98

Browse files
derrickstoleepks-t
andcommitted
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>
1 parent 6ab38b7 commit 639ff98

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

scalar.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "help.h"
2020
#include "setup.h"
2121
#include "trace2.h"
22+
#include "path.h"
2223

2324
static void setup_enlistment_directory(int argc, const char **argv,
2425
const char * const *usagestr,
@@ -95,6 +96,16 @@ struct scalar_config {
9596
int overwrite_on_reconfigure;
9697
};
9798

99+
static int set_config_with_comment(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+
98109
static int set_scalar_config(const struct scalar_config *config, int reconfigure)
99110
{
100111
char *value = NULL;
@@ -103,7 +114,7 @@ static int set_scalar_config(const struct scalar_config *config, int reconfigure
103114
if ((reconfigure && config->overwrite_on_reconfigure) ||
104115
repo_config_get_string(the_repository, config->key, &value)) {
105116
trace2_data_string("scalar", the_repository, config->key, "created");
106-
res = repo_config_set_gently(the_repository, config->key, config->value);
117+
res = set_config_with_comment(config->key, config->value);
107118
} else {
108119
trace2_data_string("scalar", the_repository, config->key, "exists");
109120
res = 0;
@@ -197,9 +208,8 @@ static int set_recommended_config(int reconfigure)
197208
if (repo_config_get_string(the_repository, "log.excludeDecoration", &value)) {
198209
trace2_data_string("scalar", the_repository,
199210
"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_config_with_comment("log.excludeDecoration",
212+
"refs/prefetch/*"))
203213
return error(_("could not configure "
204214
"log.excludeDecoration"));
205215
} else {

t/t9210-scalar.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ 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_grep "preloadIndex = true # set by scalar" one/src/.git/config &&
214+
test_grep "excludeDecoration = refs/prefetch/\* # set by scalar" one/src/.git/config &&
215+
213216
test_subcommand git maintenance start <reconfigure &&
214217
test_subcommand ! git maintenance unregister --force <reconfigure &&
215218

0 commit comments

Comments
 (0)