environment: move "warn_on_object_refname_ambiguity" into `struct repo_config_values`

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>

Olamide Caleb Bello committed Jun 2, 2026 at 18:09 UTC 8407abf02aa310f4b8c21e0c9da925f8091564ff
7 files changed +20 -15
builtin/cat-file.c
+4 -3
@@ -901,6 +901,7 @@ static int batch_objects(struct batch_options *opt)
901 struct strbuf input = STRBUF_INIT;
902 struct strbuf output = STRBUF_INIT;
903 struct expand_data data = EXPAND_DATA_INIT;
904 + struct repo_config_values *cfg = repo_config_values(the_repository);
905 int save_warning;
906 int retval = 0;
907
@@ -973,8 +974,8 @@ static int batch_objects(struct batch_options *opt)
974 * warn) ends up dwarfing the actual cost of the object lookups
975 * themselves. We can work around it by just turning off the warning.
976 */
976 - save_warning = warn_on_object_refname_ambiguity;
977 - warn_on_object_refname_ambiguity = 0;
977 + save_warning = cfg->warn_on_object_refname_ambiguity;
978 + cfg->warn_on_object_refname_ambiguity = 0;
979
980 if (opt->batch_mode == BATCH_MODE_QUEUE_AND_DISPATCH) {
981 batch_objects_command(opt, &output, &data);
@@ -1002,7 +1003,7 @@ static int batch_objects(struct batch_options *opt)
1003 cleanup:
1004 strbuf_release(&input);
1005 strbuf_release(&output);
1005 - warn_on_object_refname_ambiguity = save_warning;
1006 + cfg->warn_on_object_refname_ambiguity = save_warning;
1007 return retval;
1008 }
1009
builtin/pack-objects.c
+4 -3
@@ -4788,6 +4788,7 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
4788 struct setup_revision_opt s_r_opt = {
4789 .allow_exclude_promisor_objects = 1,
4790 };
4791 + struct repo_config_values *cfg = repo_config_values(the_repository);
4792 char line[1000];
4793 int flags = 0;
4794 int save_warning;
@@ -4798,8 +4799,8 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
4799 /* make sure shallows are read */
4800 is_repository_shallow(the_repository);
4801
4801 - save_warning = warn_on_object_refname_ambiguity;
4802 - warn_on_object_refname_ambiguity = 0;
4802 + save_warning = cfg->warn_on_object_refname_ambiguity;
4803 + cfg->warn_on_object_refname_ambiguity = 0;
4804
4805 while (fgets(line, sizeof(line), stdin) != NULL) {
4806 int len = strlen(line);
@@ -4827,7 +4828,7 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
4828 die(_("bad revision '%s'"), line);
4829 }
4830
4830 - warn_on_object_refname_ambiguity = save_warning;
4831 + cfg->warn_on_object_refname_ambiguity = save_warning;
4832
4833 if (use_bitmap_index && !get_object_list_from_bitmap(revs))
4834 return;
environment.c
+1 -1
@@ -47,7 +47,6 @@ int minimum_abbrev = 4, default_abbrev = -1;
47 int ignore_case;
48 int assume_unchanged;
49 int is_bare_repository_cfg = -1; /* unspecified */
50 -int warn_on_object_refname_ambiguity = 1;
50 char *git_commit_encoding;
51 char *git_log_output_encoding;
52 char *apply_default_whitespace;
@@ -725,4 +724,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
724 cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
725 cfg->core_sparse_checkout_cone = 0;
726 cfg->sparse_expect_files_outside_of_patterns = 0;
727 + cfg->warn_on_object_refname_ambiguity = 1;
728 }
environment.h
+1 -1
@@ -97,6 +97,7 @@ struct repo_config_values {
97 int pack_compression_level;
98 int precomposed_unicode;
99 int core_sparse_checkout_cone;
100 + int warn_on_object_refname_ambiguity;
101
102 /* section "sparse" config values */
103 int sparse_expect_files_outside_of_patterns;
@@ -174,7 +175,6 @@ extern int has_symlinks;
175 extern int minimum_abbrev, default_abbrev;
176 extern int ignore_case;
177 extern int assume_unchanged;
177 -extern int warn_on_object_refname_ambiguity;
178 extern char *apply_default_whitespace;
179 extern char *apply_default_ignorewhitespace;
180 extern unsigned long pack_size_limit_cfg;
object-name.c
+2 -1
@@ -684,11 +684,12 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
684 int refs_found = 0;
685 int at, reflog_len, nth_prior = 0;
686 int fatal = !(flags & GET_OID_QUIETLY);
687 + struct repo_config_values *cfg = repo_config_values(the_repository);
688
689 if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
690 if (!(flags & GET_OID_SKIP_AMBIGUITY_CHECK) &&
691 repo_settings_get_warn_ambiguous_refs(r) &&
691 - warn_on_object_refname_ambiguity) {
692 + cfg->warn_on_object_refname_ambiguity) {
693 refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0);
694 if (refs_found > 0) {
695 warning(warn_msg, len, str);
revision.c
+4 -3
@@ -2922,9 +2922,10 @@ static void read_revisions_from_stdin(struct rev_info *revs,
2922 int seen_end_of_options = 0;
2923 int save_warning;
2924 int flags = 0;
2925 + struct repo_config_values *cfg = repo_config_values(the_repository);
2926
2926 - save_warning = warn_on_object_refname_ambiguity;
2927 - warn_on_object_refname_ambiguity = 0;
2927 + save_warning = cfg->warn_on_object_refname_ambiguity;
2928 + cfg->warn_on_object_refname_ambiguity = 0;
2929
2930 strbuf_init(&sb, 1000);
2931 while (strbuf_getline(&sb, stdin) != EOF) {
@@ -2958,7 +2959,7 @@ static void read_revisions_from_stdin(struct rev_info *revs,
2959 read_pathspec_from_stdin(&sb, prune);
2960
2961 strbuf_release(&sb);
2961 - warn_on_object_refname_ambiguity = save_warning;
2962 + cfg->warn_on_object_refname_ambiguity = save_warning;
2963 }
2964
2965 static void NORETURN diagnose_missing_default(const char *def)
submodule.c
+4 -3
@@ -898,12 +898,13 @@ static void collect_changed_submodules(struct repository *r,
898 struct setup_revision_opt s_r_opt = {
899 .assume_dashdash = 1,
900 };
901 + struct repo_config_values *cfg = repo_config_values(the_repository);
902
902 - save_warning = warn_on_object_refname_ambiguity;
903 - warn_on_object_refname_ambiguity = 0;
903 + save_warning = cfg->warn_on_object_refname_ambiguity;
904 + cfg->warn_on_object_refname_ambiguity = 0;
905 repo_init_revisions(r, &rev, NULL);
906 setup_revisions_from_strvec(argv, &rev, &s_r_opt);
906 - warn_on_object_refname_ambiguity = save_warning;
907 + cfg->warn_on_object_refname_ambiguity = save_warning;
908 if (prepare_revision_walk(&rev))
909 die(_("revision walk setup failed"));
910