[PATCH v7 6/9] environment: migrate apply_default_whitespace and apply_default_ignorewhitespace
From: Tian Yuchen <hidden>
Date: 2026-07-06 14:26:19
Subsystem:
the rest · Maintainer:
Linus Torvalds
The global variables 'apply_default_whitespace' and 'apply_default_ignorewhitespace' are used to store the default whitespace configuration for 'git apply'. Move these variables into 'struct repo_config_values' to continue the libification effort. Dynamically allocated strings fetched via 'repo_config_get_string()' are now tracked per-repository and safely freed in 'repo_config_values_clear()'. As part of this transition, update 'git_apply_config()' to accept a 'struct repository *' argument rather than relying on the 'the_repository' global. Mentored-by: Christian Couder [off-list ref] Mentored-by: Ayush Chandekar [off-list ref] Mentored-by: Olamide Caleb Bello [off-list ref] Signed-off-by: Tian Yuchen <redacted> --- apply.c | 20 ++++++++++++-------- environment.c | 6 ++++-- environment.h | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/apply.c b/apply.c
index 249248d4f2..66db9b7678 100644
--- a/apply.c
+++ b/apply.c@@ -47,11 +47,13 @@ struct gitdiff_data { int p_value; }; -static void git_apply_config(void) +static void git_apply_config(struct repository *repo) { - repo_config_get_string(the_repository, "apply.whitespace", &apply_default_whitespace); - repo_config_get_string(the_repository, "apply.ignorewhitespace", &apply_default_ignorewhitespace); - repo_config(the_repository, git_xmerge_config, NULL); + repo_config_get_string(repo, "apply.whitespace", + &repo_config_values(repo)->apply_default_whitespace); + repo_config_get_string(repo, "apply.ignorewhitespace", + &repo_config_values(repo)->apply_default_ignorewhitespace); + repo_config(repo, git_xmerge_config, NULL); } static int parse_whitespace_option(struct apply_state *state, const char *option)
@@ -126,10 +128,12 @@ int init_apply_state(struct apply_state *state, strset_init(&state->kept_symlinks); strbuf_init(&state->root, 0); - git_apply_config(); - if (apply_default_whitespace && parse_whitespace_option(state, apply_default_whitespace)) + git_apply_config(repo); + if (repo_config_values(repo)->apply_default_whitespace && + parse_whitespace_option(state, repo_config_values(repo)->apply_default_whitespace)) return -1; - if (apply_default_ignorewhitespace && parse_ignorewhitespace_option(state, apply_default_ignorewhitespace)) + if (repo_config_values(repo)->apply_default_ignorewhitespace && + parse_ignorewhitespace_option(state, repo_config_values(repo)->apply_default_ignorewhitespace)) return -1; return 0; }
@@ -192,7 +196,7 @@ int check_apply_state(struct apply_state *state, int force_apply) static void set_default_whitespace_mode(struct apply_state *state) { - if (!state->whitespace_option && !apply_default_whitespace) + if (!state->whitespace_option && !repo_config_values(state->repo)->apply_default_whitespace) state->ws_error_action = (state->apply ? warn_on_ws_error : nowarn_ws_error); }
diff --git a/environment.c b/environment.c
index 3782bf68aa..8744790219 100644
--- a/environment.c
+++ b/environment.c@@ -49,8 +49,6 @@ int assume_unchanged; int is_bare_repository_cfg = -1; /* unspecified */ char *git_commit_encoding; char *git_log_output_encoding; -char *apply_default_whitespace; -char *apply_default_ignorewhitespace; int fsync_object_files = -1; int use_fsync = -1; enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
@@ -725,6 +723,8 @@ void repo_config_values_init(struct repo_config_values *cfg) cfg->editor_program = NULL; cfg->pager_program = NULL; cfg->askpass_program = NULL; + cfg->apply_default_whitespace = NULL; + cfg->apply_default_ignorewhitespace = NULL; cfg->apply_sparse_checkout = 0; cfg->branch_track = BRANCH_TRACK_REMOTE; cfg->trust_ctime = 1;
@@ -758,4 +758,6 @@ void repo_config_values_clear(struct repository *repo) FREE_AND_NULL(cfg->editor_program); FREE_AND_NULL(cfg->pager_program); FREE_AND_NULL(cfg->askpass_program); + FREE_AND_NULL(cfg->apply_default_whitespace); + FREE_AND_NULL(cfg->apply_default_ignorewhitespace); }
diff --git a/environment.h b/environment.h
index d55b1ba073..9aecd64152 100644
--- a/environment.h
+++ b/environment.h@@ -94,6 +94,8 @@ struct repo_config_values { char *editor_program; char *pager_program; char *askpass_program; + char *apply_default_whitespace; + char *apply_default_ignorewhitespace; int apply_sparse_checkout; int trust_ctime; int check_stat;
@@ -182,8 +184,6 @@ extern int has_symlinks; extern int minimum_abbrev, default_abbrev; extern int ignore_case; extern int assume_unchanged; -extern char *apply_default_whitespace; -extern char *apply_default_ignorewhitespace; extern unsigned long pack_size_limit_cfg; extern int protect_hfs;
--
2.43.0