[PATCH v2 1/2] dir: encapsulate excludes_file lazy-load
- From
Tian Yuchen <cat@malon.dev>
- Date
- Jun 26, 2026, 07:50 UTC
- Message-ID
- <20260626075037.532164-2-cat@malon.dev>
- In-Reply-To
- <20260626075037.532164-1-cat@malon.dev>
The global variable 'excludes_file' is used to track the path to the global ignore file, 'core.excludesfile'. If this variable is NULL, setup_standard_excludes() in dir.c forcefully evaluates and assigns the XDG default path to it.
Introduce repo_excludes_file() as a getter to encapsulate this lazy-loading logic. This prepares the variable to be safely moved into 'struct repo_config_values' in the subsequent commit.
Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev> --- dir.c | 4 ++-- environment.c | 7 +++++++ environment.h | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/dir.c b/dir.c index 7a73690fbc..4f87a52b3c 100644 --- a/dir.c +++ b/dir.c @@ -3481,11 +3481,11 @@ static GIT_PATH_FUNC(git_path_info_exclude, "info/exclude") void setup_standard_excludes(struct dir_struct *dir) { + const char *excludes_file = repo_excludes_file(the_repository); + dir->exclude_per_dir = ".gitignore"; /* core.excludesfile defaulting to $XDG_CONFIG_HOME/git/ignore */ - if (!excludes_file) - excludes_file = xdg_config_home("ignore"); if (excludes_file && !access_or_warn(excludes_file, R_OK, 0)) add_patterns_from_file_1(dir, excludes_file, dir->untracked ? &dir->internal.ss_excludes_file : NULL); diff --git a/environment.c b/environment.c index ba2c60103f..8efcaeafa6 100644 --- a/environment.c +++ b/environment.c @@ -134,6 +134,13 @@ int is_bare_repository(void) return is_bare_repository_cfg && !repo_get_work_tree(the_repository); } +const char *repo_excludes_file(struct repository *repo) +{ + if (!excludes_file) + excludes_file = xdg_config_home("ignore"); + return excludes_file; +} + int have_git_dir(void) { return startup_info->have_repository diff --git a/environment.h b/environment.h index 6f18286955..52d531e4ea 100644 --- a/environment.h +++ b/environment.h @@ -133,6 +133,11 @@ int git_default_config(const char *, const char *, int git_default_core_config(const char *var, const char *value, const struct config_context *ctx, void *cb); +/* + * TODO: This still relies on the global state. + */ +const char *repo_excludes_file(struct repository *repo); + void repo_config_values_init(struct repo_config_values *cfg); /*
-- 2.43.0