]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: stop storing "core.logAllRefUpdates" globally
authorPatrick Steinhardt <ps@pks.im>
Thu, 12 Sep 2024 11:30:18 +0000 (13:30 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Sep 2024 17:15:43 +0000 (10:15 -0700)
The value of "core.logAllRefUpdates" is being stored in the global
variable `log_all_ref_updates`. This design is somewhat aged nowadays,
where it is entirely possible to access multiple repositories in the
same process which all have different values for this setting. So using
a single global variable to track it is plain wrong.

Remove the global variable. Instead, we now provide a new function part
of the repo-settings subsystem that parses the value for a specific
repository. While that may require us to read the value multiple times,
we work around this by reading it once when the ref backends are set up
and caching the value there.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
config.c
environment.c
environment.h
refs/files-backend.c
refs/reftable-backend.c
repo-settings.c
repo-settings.h
setup.c

index 6db7f39492ef96946eb5cbd4a46b7cfd96bdb9fd..7e18b87c7a47bbb66b968409eee190be6b76eb73 100644 (file)
@@ -951,6 +951,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
        const char *old_desc, *reflog_msg;
        if (opts->new_branch) {
                if (opts->new_orphan_branch) {
+                       enum log_refs_config log_all_ref_updates =
+                               repo_settings_get_log_all_ref_updates(the_repository);
                        char *refname;
 
                        refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);
index f3066c3747705821acf6b3a76291246ef9395a31..47101c3e9775ef01632abb1061c77995c7cc9e97 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1452,16 +1452,6 @@ static int git_default_core_config(const char *var, const char *value,
                return 0;
        }
 
-       if (!strcmp(var, "core.logallrefupdates")) {
-               if (value && !strcasecmp(value, "always"))
-                       log_all_ref_updates = LOG_REFS_ALWAYS;
-               else if (git_config_bool(var, value))
-                       log_all_ref_updates = LOG_REFS_NORMAL;
-               else
-                       log_all_ref_updates = LOG_REFS_NONE;
-               return 0;
-       }
-
        if (!strcmp(var, "core.warnambiguousrefs")) {
                warn_ambiguous_refs = git_config_bool(var, value);
                return 0;
index 64ae13ef24001e5a9af15247e70d9d7f056612b0..992d87e0d60e4b7a6d40738508779561377b9e80 100644 (file)
@@ -77,7 +77,6 @@ int sparse_expect_files_outside_of_patterns;
 int merge_log_config = -1;
 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
 unsigned long pack_size_limit_cfg;
-enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
 int max_allowed_tree_depth =
 #ifdef _MSC_VER
        /*
index 0b4e5afc36d849de083177dc73a748a2fa9a626f..315fd31995163905c854b8c37fccf24828379420 100644 (file)
@@ -181,8 +181,6 @@ extern int core_apply_sparse_checkout;
 extern int core_sparse_checkout_cone;
 extern int sparse_expect_files_outside_of_patterns;
 
-extern enum log_refs_config log_all_ref_updates;
-
 enum rebase_setup_type {
        AUTOREBASE_NEVER = 0,
        AUTOREBASE_LOCAL,
index f5871abcf75e32b6158091630d92b4f3a298c663..a536d7d1b57e9a50df01d409e19319efe4051485 100644 (file)
@@ -75,6 +75,7 @@ struct files_ref_store {
        unsigned int store_flags;
 
        char *gitcommondir;
+       enum log_refs_config log_all_ref_updates;
 
        struct ref_cache *loose;
 
@@ -107,6 +108,7 @@ static struct ref_store *files_ref_store_init(struct repository *repo,
        refs->gitcommondir = strbuf_detach(&sb, NULL);
        refs->packed_ref_store =
                packed_ref_store_init(repo, refs->gitcommondir, flags);
+       refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
 
        chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
        chdir_notify_reparent("files-backend $GIT_COMMONDIR",
@@ -1704,7 +1706,7 @@ static int log_ref_setup(struct files_ref_store *refs,
                         const char *refname, int force_create,
                         int *logfd, struct strbuf *err)
 {
-       enum log_refs_config log_refs_cfg = log_all_ref_updates;
+       enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
        struct strbuf logfile_sb = STRBUF_INIT;
        char *logfile;
 
index c78186423a1e18a37ab92650f864dd13e524f11c..043e19439f6c49b99527079a81a81f5a2ad1175e 100644 (file)
@@ -52,6 +52,7 @@ struct reftable_ref_store {
        struct reftable_write_options write_options;
 
        unsigned int store_flags;
+       enum log_refs_config log_all_ref_updates;
        int err;
 };
 
@@ -157,21 +158,21 @@ static struct reftable_stack *stack_for(struct reftable_ref_store *store,
        }
 }
 
-static int should_write_log(struct ref_store *refs, const char *refname)
+static int should_write_log(struct reftable_ref_store *refs, const char *refname)
 {
-       enum log_refs_config log_refs_cfg = log_all_ref_updates;
+       enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
        if (log_refs_cfg == LOG_REFS_UNSET)
                log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
 
        switch (log_refs_cfg) {
        case LOG_REFS_NONE:
-               return refs_reflog_exists(refs, refname);
+               return refs_reflog_exists(&refs->base, refname);
        case LOG_REFS_ALWAYS:
                return 1;
        case LOG_REFS_NORMAL:
                if (should_autocreate_reflog(log_refs_cfg, refname))
                        return 1;
-               return refs_reflog_exists(refs, refname);
+               return refs_reflog_exists(&refs->base, refname);
        default:
                BUG("unhandled core.logAllRefUpdates value %d", log_refs_cfg);
        }
@@ -278,6 +279,7 @@ static struct ref_store *reftable_be_init(struct repository *repo,
        base_ref_store_init(&refs->base, repo, gitdir, &refs_be_reftable);
        strmap_init(&refs->worktree_stacks);
        refs->store_flags = store_flags;
+       refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
 
        refs->write_options.hash_id = repo->hash_algo->format_id;
        refs->write_options.default_permissions = calc_shared_perm(0666 & ~mask);
@@ -1220,7 +1222,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
                } else if (!(u->flags & REF_SKIP_CREATE_REFLOG) &&
                           (u->flags & REF_HAVE_NEW) &&
                           (u->flags & REF_FORCE_CREATE_REFLOG ||
-                           should_write_log(&arg->refs->base, u->refname))) {
+                           should_write_log(arg->refs, u->refname))) {
                        struct reftable_log_record *log;
                        int create_reflog = 1;
 
index 3a76ba276c9a4388840262961de589cb63eb4cb6..1322fd2f972366ea2f76b9feb4a9c0bde2da17a9 100644 (file)
@@ -124,3 +124,19 @@ void prepare_repo_settings(struct repository *r)
         */
        r->settings.command_requires_full_index = 1;
 }
+
+enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)
+{
+       const char *value;
+
+       if (!repo_config_get_string_tmp(repo, "core.logallrefupdates", &value)) {
+               if (value && !strcasecmp(value, "always"))
+                       return LOG_REFS_ALWAYS;
+               else if (git_config_bool("core.logallrefupdates", value))
+                       return LOG_REFS_NORMAL;
+               else
+                       return LOG_REFS_NONE;
+       }
+
+       return LOG_REFS_UNSET;
+}
index d03b6e57f0c31bc64234428451a6452fad305f55..76adb96a669a0a0894481d1bbc2d47b8c6e7fb6d 100644 (file)
@@ -65,4 +65,7 @@ struct repo_settings {
 
 void prepare_repo_settings(struct repository *r);
 
+/* Read the value for "core.logAllRefUpdates". */
+enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo);
+
 #endif /* REPO_SETTINGS_H */
diff --git a/setup.c b/setup.c
index 19cce5afa72d41c2e09b1f106b0e2203b6d823e2..74991914726a8769ddd8fc2f172519690ba7aed9 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2354,7 +2354,7 @@ static int create_default_files(const char *template_path,
        else {
                git_config_set("core.bare", "false");
                /* allow template config file to override the default */
-               if (log_all_ref_updates == LOG_REFS_UNSET)
+               if (repo_settings_get_log_all_ref_updates(the_repository) == LOG_REFS_UNSET)
                        git_config_set("core.logallrefupdates", "true");
                if (needs_work_tree_config(original_git_dir, work_tree))
                        git_config_set("core.worktree", work_tree);