From 11dbb4ace3ac428574fadf6f7895f56aba9dca81 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 12 Sep 2024 13:30:24 +0200 Subject: environment: stop storing "core.warnAmbiguousRefs" globally Same as the preceding commits, storing the "core.warnAmbiguousRefs" value globally is misdesigned as this setting may be set per repository. Move the logic into the repo-settings subsystem. The usual pattern here is that users are expected to call `prepare_repo_settings()` before they access the settings themselves. This seems somewhat fragile though, as it is easy to miss and leads to somewhat ugly code patterns at the call sites. Instead, introduce a new function that encapsulates this logic for us. This also allows us to change how exactly the lazy initialization works in the future, e.g. by only partially initializing values as requested by the caller. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- repo-settings.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'repo-settings.c') diff --git a/repo-settings.c b/repo-settings.c index 1322fd2f97..4699b4b365 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -140,3 +140,12 @@ enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *re return LOG_REFS_UNSET; } + +int repo_settings_get_warn_ambiguous_refs(struct repository *repo) +{ + prepare_repo_settings(repo); + if (repo->settings.warn_ambiguous_refs < 0) + repo_cfg_bool(repo, "core.warnambiguousrefs", + &repo->settings.warn_ambiguous_refs, 1); + return repo->settings.warn_ambiguous_refs; +} -- cgit v1.2.3