]> git.ipfire.org Git - thirdparty/git.git/commitdiff
scalar: annotate config file with "set by scalar"
authorDerrick Stolee <stolee@gmail.com>
Fri, 12 Dec 2025 15:15:24 +0000 (15:15 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Dec 2025 23:43:27 +0000 (08:43 +0900)
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>
scalar.c
t/t9210-scalar.sh

index f7543116272b773f7f54f4a4638dd78a5a6f9e3e..1c7bd1a8f8b67b5770dd7818ff7437a715483ea5 100644 (file)
--- a/scalar.c
+++ b/scalar.c
@@ -19,6 +19,7 @@
 #include "help.h"
 #include "setup.h"
 #include "trace2.h"
+#include "path.h"
 
 static void setup_enlistment_directory(int argc, const char **argv,
                                       const char * const *usagestr,
@@ -95,7 +96,17 @@ struct scalar_config {
        int overwrite_on_reconfigure;
 };
 
-static int set_scalar_config(const struct scalar_config *config, int reconfigure)
+static int set_scalar_config(const char *key, const char *value)
+{
+       char *file = repo_git_path(the_repository, "config");
+       int res = repo_config_set_multivar_in_file_gently(the_repository, file,
+                                                         key, value, NULL,
+                                                         " # set by scalar", 0);
+       free(file);
+       return res;
+}
+
+static int set_config_if_missing(const struct scalar_config *config, int reconfigure)
 {
        char *value = NULL;
        int res;
@@ -103,7 +114,7 @@ static int set_scalar_config(const struct scalar_config *config, int reconfigure
        if ((reconfigure && config->overwrite_on_reconfigure) ||
            repo_config_get_string(the_repository, config->key, &value)) {
                trace2_data_string("scalar", the_repository, config->key, "created");
-               res = repo_config_set_gently(the_repository, config->key, config->value);
+               res = set_scalar_config(config->key, config->value);
        } else {
                trace2_data_string("scalar", the_repository, config->key, "exists");
                res = 0;
@@ -178,14 +189,14 @@ static int set_recommended_config(int reconfigure)
        char *value;
 
        for (i = 0; config[i].key; i++) {
-               if (set_scalar_config(config + i, reconfigure))
+               if (set_config_if_missing(config + i, reconfigure))
                        return error(_("could not configure %s=%s"),
                                     config[i].key, config[i].value);
        }
 
        if (have_fsmonitor_support()) {
                struct scalar_config fsmonitor = { "core.fsmonitor", "true" };
-               if (set_scalar_config(&fsmonitor, reconfigure))
+               if (set_config_if_missing(&fsmonitor, reconfigure))
                        return error(_("could not configure %s=%s"),
                                     fsmonitor.key, fsmonitor.value);
        }
@@ -197,9 +208,8 @@ static int set_recommended_config(int reconfigure)
        if (repo_config_get_string(the_repository, "log.excludeDecoration", &value)) {
                trace2_data_string("scalar", the_repository,
                                   "log.excludeDecoration", "created");
-               if (repo_config_set_multivar_gently(the_repository, "log.excludeDecoration",
-                                                   "refs/prefetch/*",
-                                                   CONFIG_REGEX_NONE, 0))
+               if (set_scalar_config("log.excludeDecoration",
+                                           "refs/prefetch/*"))
                        return error(_("could not configure "
                                       "log.excludeDecoration"));
        } else {
index bd6f0c40d229b606bcdac2f8428f9c9436e40860..43c210a23d4bef2ac43bf4c5dfbef627747f827c 100755 (executable)
@@ -210,6 +210,9 @@ test_expect_success 'scalar reconfigure' '
        GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
        test_path_is_file one/src/cron.txt &&
        test true = "$(git -C one/src config core.preloadIndex)" &&
+       test_grep "preloadIndex = true # set by scalar" one/src/.git/config &&
+       test_grep "excludeDecoration = refs/prefetch/\* # set by scalar" one/src/.git/config &&
+
        test_subcommand git maintenance start <reconfigure &&
        test_subcommand ! git maintenance unregister --force <reconfigure &&