]> git.ipfire.org Git - thirdparty/git.git/commitdiff
env: move "warn_on_object_refname_ambiguity" into `struct repo_config_values`
authorOlamide Caleb Bello <belkid98@gmail.com>
Thu, 23 Apr 2026 16:54:32 +0000 (17:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Apr 2026 10:35:42 +0000 (19:35 +0900)
The `core.warnAmbiguousRefs` configuration was previously stored in a
global `int` variable, making it shared across repository instances
and risking cross‑repository state leakage.

Store it instead in `repo_config_values`, where eagerly‑parsed
repository configuration lives. This option is parsed eagerly because
ambiguity warnings influence how users interpret object references in
many commands; a lazy parse could cause these warnings to behave
inconsistently or to appear for the wrong repository, confusing users
and hindering libification. This preserves the existing behavior while
tying the value to the repository from which it was read, avoiding
cross‑repository state leakage and continuing the effort to reduce
reliance on global configuration state.

Update all references to use `repo_config_values()`.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/cat-file.c
builtin/pack-objects.c
environment.c
environment.h
object-name.c
revision.c
submodule.c

index d9fbad535868bb90fba41a8c9e4e3c4381e4cade..cfc543018684c104623d01837093fc381c0ad9b8 100644 (file)
@@ -901,6 +901,7 @@ static int batch_objects(struct batch_options *opt)
        struct strbuf input = STRBUF_INIT;
        struct strbuf output = STRBUF_INIT;
        struct expand_data data = EXPAND_DATA_INIT;
+       struct repo_config_values *cfg = repo_config_values(the_repository);
        int save_warning;
        int retval = 0;
 
@@ -973,8 +974,8 @@ static int batch_objects(struct batch_options *opt)
         * warn) ends up dwarfing the actual cost of the object lookups
         * themselves. We can work around it by just turning off the warning.
         */
-       save_warning = warn_on_object_refname_ambiguity;
-       warn_on_object_refname_ambiguity = 0;
+       save_warning = cfg->warn_on_object_refname_ambiguity;
+       cfg->warn_on_object_refname_ambiguity = 0;
 
        if (opt->batch_mode == BATCH_MODE_QUEUE_AND_DISPATCH) {
                batch_objects_command(opt, &output, &data);
@@ -1002,7 +1003,7 @@ static int batch_objects(struct batch_options *opt)
  cleanup:
        strbuf_release(&input);
        strbuf_release(&output);
-       warn_on_object_refname_ambiguity = save_warning;
+       cfg->warn_on_object_refname_ambiguity = save_warning;
        return retval;
 }
 
index 8ccbe7e17832cd1a5387bd697f559ab57325d77a..7df75fe91e1488e14e422de9770181a38072c880 100644 (file)
@@ -4788,6 +4788,7 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
        struct setup_revision_opt s_r_opt = {
                .allow_exclude_promisor_objects = 1,
        };
+       struct repo_config_values *cfg = repo_config_values(the_repository);
        char line[1000];
        int flags = 0;
        int save_warning;
@@ -4798,8 +4799,8 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
        /* make sure shallows are read */
        is_repository_shallow(the_repository);
 
-       save_warning = warn_on_object_refname_ambiguity;
-       warn_on_object_refname_ambiguity = 0;
+       save_warning = cfg->warn_on_object_refname_ambiguity;
+       cfg->warn_on_object_refname_ambiguity = 0;
 
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
@@ -4827,7 +4828,7 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
                        die(_("bad revision '%s'"), line);
        }
 
-       warn_on_object_refname_ambiguity = save_warning;
+       cfg->warn_on_object_refname_ambiguity = save_warning;
 
        if (use_bitmap_index && !get_object_list_from_bitmap(revs))
                return;
index 57587ede56a1be40fb59c6dac825c96bd41eaaee..ba2c60103ff51c5e50a6c0e08635c9a3453eead6 100644 (file)
@@ -47,7 +47,6 @@ int minimum_abbrev = 4, default_abbrev = -1;
 int ignore_case;
 int assume_unchanged;
 int is_bare_repository_cfg = -1; /* unspecified */
-int warn_on_object_refname_ambiguity = 1;
 char *git_commit_encoding;
 char *git_log_output_encoding;
 char *apply_default_whitespace;
@@ -725,4 +724,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
        cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
        cfg->core_sparse_checkout_cone = 0;
        cfg->sparse_expect_files_outside_of_patterns = 0;
+       cfg->warn_on_object_refname_ambiguity = 1;
 }
index 609cdaa07fc8ca5a8630a55fbc6dc38c973a13b4..1ff0a7ba8b0e82a3f7260340ce5c44f2fdfdfe8c 100644 (file)
@@ -97,6 +97,7 @@ struct repo_config_values {
        int pack_compression_level;
        int precomposed_unicode;
        int core_sparse_checkout_cone;
+       int warn_on_object_refname_ambiguity;
 
        /* section "sparse" config values */
        int sparse_expect_files_outside_of_patterns;
@@ -174,7 +175,6 @@ extern int has_symlinks;
 extern int minimum_abbrev, default_abbrev;
 extern int ignore_case;
 extern int assume_unchanged;
-extern int warn_on_object_refname_ambiguity;
 extern char *apply_default_whitespace;
 extern char *apply_default_ignorewhitespace;
 extern unsigned long pack_size_limit_cfg;
index 21dcdc4a0e7c550cd65266ca55d61ef030b140f6..319d3db01da1101beb0642d70598fd9b6f9d7762 100644 (file)
@@ -684,11 +684,12 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
        int refs_found = 0;
        int at, reflog_len, nth_prior = 0;
        int fatal = !(flags & GET_OID_QUIETLY);
+       struct repo_config_values *cfg = repo_config_values(the_repository);
 
        if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
                if (!(flags & GET_OID_SKIP_AMBIGUITY_CHECK) &&
                    repo_settings_get_warn_ambiguous_refs(r) &&
-                   warn_on_object_refname_ambiguity) {
+                   cfg->warn_on_object_refname_ambiguity) {
                        refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0);
                        if (refs_found > 0) {
                                warning(warn_msg, len, str);
index 599b3a66c369ca3b0099311250cf758788fdf6ce..4e7faa7eb15022ef39315adb346a2f064f9db36b 100644 (file)
@@ -2922,9 +2922,10 @@ static void read_revisions_from_stdin(struct rev_info *revs,
        int seen_end_of_options = 0;
        int save_warning;
        int flags = 0;
+       struct repo_config_values *cfg = repo_config_values(the_repository);
 
-       save_warning = warn_on_object_refname_ambiguity;
-       warn_on_object_refname_ambiguity = 0;
+       save_warning = cfg->warn_on_object_refname_ambiguity;
+       cfg->warn_on_object_refname_ambiguity = 0;
 
        strbuf_init(&sb, 1000);
        while (strbuf_getline(&sb, stdin) != EOF) {
@@ -2958,7 +2959,7 @@ static void read_revisions_from_stdin(struct rev_info *revs,
                read_pathspec_from_stdin(&sb, prune);
 
        strbuf_release(&sb);
-       warn_on_object_refname_ambiguity = save_warning;
+       cfg->warn_on_object_refname_ambiguity = save_warning;
 }
 
 static void NORETURN diagnose_missing_default(const char *def)
index b1a0363f9d2a96a1084953bf46f9c788d425741f..f26235bbb728eeaa38aaac3ae6a9665f6a85dcf1 100644 (file)
@@ -898,12 +898,13 @@ static void collect_changed_submodules(struct repository *r,
        struct setup_revision_opt s_r_opt = {
                .assume_dashdash = 1,
        };
+       struct repo_config_values *cfg = repo_config_values(the_repository);
 
-       save_warning = warn_on_object_refname_ambiguity;
-       warn_on_object_refname_ambiguity = 0;
+       save_warning = cfg->warn_on_object_refname_ambiguity;
+       cfg->warn_on_object_refname_ambiguity = 0;
        repo_init_revisions(r, &rev, NULL);
        setup_revisions_from_strvec(argv, &rev, &s_r_opt);
-       warn_on_object_refname_ambiguity = save_warning;
+       cfg->warn_on_object_refname_ambiguity = save_warning;
        if (prepare_revision_walk(&rev))
                die(_("revision walk setup failed"));