From: Aniket Gupta Date: Sat, 24 Oct 2026 22:00:11 GMT Subject: [PATCH 3/4] environment: move core_eol into repo_config_values Message-ID: <20261024220012.486-4-aniketgupta3001@gmail.com> In-Reply-To: <20261024220012.486-1-aniketgupta3001@gmail.com> The global variable 'core_eol' holds the value of the 'core.eol' configuration, which sets the line ending used for files that are converted to the working tree format. Move it into 'struct repo_config_values' to continue the libification effort. As with 'enum auto_crlf', moving 'enum eol' to 'convert.h' would introduce a circular dependency chain: convert.h -> hash.h -> repository.h -> environment.h. Therefore, keep the enum definition in 'environment.h' next to the other ones, under the existing NEEDSWORK comment. Initialize the per-repository value to its default in 'repo_config_values_init()'. Modify the configuration parsing in environment.c to update the per-repository structure directly, and introduce the getter 'repo_core_eol()' to read the value in 'convert.c'. Signed-off-by: Aniket Gupta --- convert.c | 6 +++--- convert.h | 12 ------------ environment.c | 17 ++++++++++++----- environment.h | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/convert.c b/convert.c index 7c7fdd4b2d..1d4e8a246b 100644 --- a/convert.c +++ b/convert.c @@ -164,9 +164,9 @@ static int text_eol_is_crlf(struct repository *repo) return 1; else if (repo_auto_crlf(repo) == AUTO_CRLF_INPUT) return 0; - if (core_eol == EOL_CRLF) + if (repo_core_eol(repo) == EOL_CRLF) return 1; - if (core_eol == EOL_UNSET && EOL_NATIVE == EOL_CRLF) + if (repo_core_eol(repo) == EOL_UNSET && EOL_NATIVE == EOL_CRLF) return 1; return 0; } @@ -192,7 +192,7 @@ static enum eol output_eol(struct repository *repo, return text_eol_is_crlf(repo) ? EOL_CRLF : EOL_LF; } warning(_("illegal crlf_action %d"), (int)crlf_action); - return core_eol; + return repo_core_eol(repo); } static void check_global_conv_flags_eol(const char *path, diff --git a/convert.h b/convert.h index dae11d372d..3c51130177 100644 --- a/convert.h +++ b/convert.h @@ -19,17 +19,6 @@ struct strbuf; extern int global_conv_flags_eol; -enum eol { - EOL_UNSET, - EOL_CRLF, - EOL_LF, -#ifdef NATIVE_CRLF - EOL_NATIVE = EOL_CRLF -#else - EOL_NATIVE = EOL_LF -#endif -}; - enum ce_delay_state { CE_NO_DELAY = 0, CE_CAN_DELAY = 1, @@ -84,7 +73,6 @@ struct conv_attrs { void convert_attrs(struct index_state *istate, struct conv_attrs *ca, const char *path); -extern enum eol core_eol; extern char *check_roundtrip_encoding; const char *get_cached_convert_stats_ascii(struct index_state *istate, const char *path); diff --git a/environment.c b/environment.c index bbac8ed8c9..6445994986 100644 --- a/environment.c +++ b/environment.c @@ -49,7 +49,6 @@ int fsync_object_files = -1; int use_fsync = -1; enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT; enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT; -enum eol core_eol = EOL_UNSET; int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; char *check_roundtrip_encoding; #ifndef OBJECT_CREATION_MODE @@ -158,6 +157,13 @@ enum auto_crlf repo_auto_crlf(struct repository *repo) : AUTO_CRLF_FALSE; } +enum eol repo_core_eol(struct repository *repo) +{ + return repo->initialized + ? repo_config_values(repo)->core_eol + : EOL_UNSET; +} + const char *repo_excludes_file(struct repository *repo) { struct repo_config_values *cfg = repo_config_values(repo); @@ -447,13 +453,13 @@ int git_default_core_config(const char *var, const char *value, if (!strcmp(var, "core.eol")) { if (value && !strcasecmp(value, "lf")) - core_eol = EOL_LF; + cfg->core_eol = EOL_LF; else if (value && !strcasecmp(value, "crlf")) - core_eol = EOL_CRLF; + cfg->core_eol = EOL_CRLF; else if (value && !strcasecmp(value, "native")) - core_eol = EOL_NATIVE; + cfg->core_eol = EOL_NATIVE; else - core_eol = EOL_UNSET; + cfg->core_eol = EOL_UNSET; return 0; } @@ -784,6 +790,7 @@ void repo_config_values_init(struct repo_config_values *cfg) cfg->has_symlinks = platform_has_symlinks(); cfg->use_nanosec = 0; cfg->auto_crlf = AUTO_CRLF_FALSE; + cfg->core_eol = EOL_UNSET; /* section "sparse" config values */ cfg->sparse_expect_files_outside_of_patterns = 0; diff --git a/environment.h b/environment.h index 872da3576b..bf6701560d 100644 --- a/environment.h +++ b/environment.h @@ -129,6 +129,17 @@ enum auto_crlf { AUTO_CRLF_INPUT = -1 }; +enum eol { + EOL_UNSET, + EOL_CRLF, + EOL_LF, +#ifdef NATIVE_CRLF + EOL_NATIVE = EOL_CRLF +#else + EOL_NATIVE = EOL_LF +#endif +}; + struct repo_config_values { /* section "core" config values */ char *attributes_file; @@ -156,6 +167,7 @@ struct repo_config_values { int has_symlinks; int use_nanosec; enum auto_crlf auto_crlf; + enum eol core_eol; /* section "sparse" config values */ int sparse_expect_files_outside_of_patterns; @@ -212,6 +224,8 @@ int repo_has_symlinks(struct repository *repo); enum auto_crlf repo_auto_crlf(struct repository *repo); +enum eol repo_core_eol(struct repository *repo); + const char *repo_excludes_file(struct repository *repo); void repo_config_values_init(struct repo_config_values *cfg); -- 2.43.0