Skip to content

Commit a4ad8f8

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. 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 a4ad8f8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

scalar.c

Lines changed: 13 additions & 3 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,
@@ -99,16 +100,20 @@ static int set_scalar_config(const struct scalar_config *config, int reconfigure
99100
{
100101
char *value = NULL;
101102
int res;
103+
char *file = repo_git_path(the_repository, "config");
102104

103105
if ((reconfigure && config->overwrite_on_reconfigure) ||
104106
repo_config_get_string(the_repository, config->key, &value)) {
105107
trace2_data_string("scalar", the_repository, config->key, "created");
106-
res = repo_config_set_gently(the_repository, config->key, config->value);
108+
res = repo_config_set_multivar_in_file_gently(the_repository, file, config->key,
109+
config->value, NULL,
110+
" # set by scalar", 0);
107111
} else {
108112
trace2_data_string("scalar", the_repository, config->key, "exists");
109113
res = 0;
110114
}
111115

116+
free(file);
112117
free(value);
113118
return res;
114119
}
@@ -195,13 +200,18 @@ static int set_recommended_config(int reconfigure)
195200
* for multiple values.
196201
*/
197202
if (repo_config_get_string(the_repository, "log.excludeDecoration", &value)) {
203+
char *file = repo_git_path(the_repository, "config");
198204
trace2_data_string("scalar", the_repository,
199205
"log.excludeDecoration", "created");
200-
if (repo_config_set_multivar_gently(the_repository, "log.excludeDecoration",
206+
if (repo_config_set_multivar_in_file_gently(the_repository, file,
207+
"log.excludeDecoration",
201208
"refs/prefetch/*",
202-
CONFIG_REGEX_NONE, 0))
209+
CONFIG_REGEX_NONE,
210+
" # set by scalar",
211+
0))
203212
return error(_("could not configure "
204213
"log.excludeDecoration"));
214+
free(file);
205215
} else {
206216
trace2_data_string("scalar", the_repository,
207217
"log.excludeDecoration", "exists");

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)