Skip to content

Commit f29f552

Browse files
committed
environment: move "warn_on_object_refname_ambiguity" into struct repo_config_values
The `warn_on_object_refname_ambiguity` variable was previously a global integer, which makes it shared across repository instances in a single process. Move it into `repo_config_values` so the value is associated with the repository from which it was read. This preserves existing behavior while avoiding cross-repository state leakage and is another step toward eliminating repository-dependent global 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>
1 parent 704bdc7 commit f29f552

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

builtin/cat-file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ static int batch_objects(struct batch_options *opt)
875875
struct strbuf input = STRBUF_INIT;
876876
struct strbuf output = STRBUF_INIT;
877877
struct expand_data data = EXPAND_DATA_INIT;
878+
struct repo_config_values *cfg = repo_config_values(the_repository);
878879
int save_warning;
879880
int retval = 0;
880881

@@ -947,8 +948,8 @@ static int batch_objects(struct batch_options *opt)
947948
* warn) ends up dwarfing the actual cost of the object lookups
948949
* themselves. We can work around it by just turning off the warning.
949950
*/
950-
save_warning = warn_on_object_refname_ambiguity;
951-
warn_on_object_refname_ambiguity = 0;
951+
save_warning = cfg->warn_on_object_refname_ambiguity;
952+
cfg->warn_on_object_refname_ambiguity = 0;
952953

953954
if (opt->batch_mode == BATCH_MODE_QUEUE_AND_DISPATCH) {
954955
batch_objects_command(opt, &output, &data);
@@ -976,7 +977,7 @@ static int batch_objects(struct batch_options *opt)
976977
cleanup:
977978
strbuf_release(&input);
978979
strbuf_release(&output);
979-
warn_on_object_refname_ambiguity = save_warning;
980+
cfg->warn_on_object_refname_ambiguity = save_warning;
980981
return retval;
981982
}
982983

builtin/pack-objects.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4661,6 +4661,7 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
46614661
struct setup_revision_opt s_r_opt = {
46624662
.allow_exclude_promisor_objects = 1,
46634663
};
4664+
struct repo_config_values *cfg = repo_config_values(the_repository);
46644665
char line[1000];
46654666
int flags = 0;
46664667
int save_warning;
@@ -4671,8 +4672,8 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
46714672
/* make sure shallows are read */
46724673
is_repository_shallow(the_repository);
46734674

4674-
save_warning = warn_on_object_refname_ambiguity;
4675-
warn_on_object_refname_ambiguity = 0;
4675+
save_warning = cfg->warn_on_object_refname_ambiguity;
4676+
cfg->warn_on_object_refname_ambiguity = 0;
46764677

46774678
while (fgets(line, sizeof(line), stdin) != NULL) {
46784679
int len = strlen(line);
@@ -4700,7 +4701,7 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
47004701
die(_("bad revision '%s'"), line);
47014702
}
47024703

4703-
warn_on_object_refname_ambiguity = save_warning;
4704+
cfg->warn_on_object_refname_ambiguity = save_warning;
47044705

47054706
if (use_bitmap_index && !get_object_list_from_bitmap(revs))
47064707
return;

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ int minimum_abbrev = 4, default_abbrev = -1;
4747
int ignore_case;
4848
int assume_unchanged;
4949
int is_bare_repository_cfg = -1; /* unspecified */
50-
int warn_on_object_refname_ambiguity = 1;
5150
char *git_commit_encoding;
5251
char *git_log_output_encoding;
5352
char *apply_default_whitespace;
@@ -744,4 +743,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
744743
cfg->protect_ntfs = PROTECT_NTFS_DEFAULT;
745744
cfg->core_sparse_checkout_cone = 0;
746745
cfg->sparse_expect_files_outside_of_patterns = 0;
746+
cfg->warn_on_object_refname_ambiguity = 1;
747747
}

environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct repo_config_values {
9898
int protect_hfs;
9999
int protect_ntfs;
100100
int core_sparse_checkout_cone;
101+
int warn_on_object_refname_ambiguity;
101102

102103
/* section "sparse" config values */
103104
int sparse_expect_files_outside_of_patterns;
@@ -175,7 +176,6 @@ extern int has_symlinks;
175176
extern int minimum_abbrev, default_abbrev;
176177
extern int ignore_case;
177178
extern int assume_unchanged;
178-
extern int warn_on_object_refname_ambiguity;
179179
extern char *apply_default_whitespace;
180180
extern char *apply_default_ignorewhitespace;
181181
extern unsigned long pack_size_limit_cfg;

object-name.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,11 +969,12 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
969969
int refs_found = 0;
970970
int at, reflog_len, nth_prior = 0;
971971
int fatal = !(flags & GET_OID_QUIETLY);
972+
struct repo_config_values *cfg = repo_config_values(the_repository);
972973

973974
if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
974975
if (!(flags & GET_OID_SKIP_AMBIGUITY_CHECK) &&
975976
repo_settings_get_warn_ambiguous_refs(r) &&
976-
warn_on_object_refname_ambiguity) {
977+
cfg->warn_on_object_refname_ambiguity) {
977978
refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0);
978979
if (refs_found > 0) {
979980
warning(warn_msg, len, str);

revision.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,10 +2901,11 @@ static void read_revisions_from_stdin(struct rev_info *revs,
29012901
int seen_end_of_options = 0;
29022902
int save_warning;
29032903
int flags = 0;
2904+
struct repo_config_values *cfg = repo_config_values(the_repository);
29042905

2905-
save_warning = warn_on_object_refname_ambiguity;
2906-
warn_on_object_refname_ambiguity = 0;
2907-
2906+
save_warning = cfg->warn_on_object_refname_ambiguity;
2907+
cfg->warn_on_object_refname_ambiguity = 0;
2908+
29082909
strbuf_init(&sb, 1000);
29092910
while (strbuf_getline(&sb, stdin) != EOF) {
29102911
if (!sb.len)
@@ -2937,7 +2938,7 @@ static void read_revisions_from_stdin(struct rev_info *revs,
29372938
read_pathspec_from_stdin(&sb, prune);
29382939

29392940
strbuf_release(&sb);
2940-
warn_on_object_refname_ambiguity = save_warning;
2941+
cfg->warn_on_object_refname_ambiguity = save_warning;
29412942
}
29422943

29432944
static void NORETURN diagnose_missing_default(const char *def)

submodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,13 @@ static void collect_changed_submodules(struct repository *r,
898898
struct setup_revision_opt s_r_opt = {
899899
.assume_dashdash = 1,
900900
};
901+
struct repo_config_values *cfg = repo_config_values(the_repository);
901902

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;
904905
repo_init_revisions(r, &rev, NULL);
905906
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;
907908
if (prepare_revision_walk(&rev))
908909
die(_("revision walk setup failed"));
909910

0 commit comments

Comments
 (0)