git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] environment: move auto_crlf into repo_config_values

From
AGAniket Gupta <aniketgupta3001@gmail.com>
Date
Oct 24, 2026, 22:00 UTC
Message-ID
<20261024220012.486-3-aniketgupta3001@gmail.com>
In-Reply-To
<20261024220012.486-1-aniketgupta3001@gmail.com>

The global variable 'auto_crlf' holds the value of the 'core.autocrlf' configuration, which controls whether line endings are converted when files are added to and checked out of the repository. Move it into 'struct repo_config_values' to continue the libification effort.

While 'enum auto_crlf' ideally belongs in 'convert.h', moving it there introduces a circular dependency chain:

  convert.h -> hash.h -> repository.h -> environment.h.

Therefore, the enum definition is kept in 'environment.h' just below 'enum object_creation_mode', under the existing NEEDSWORK comment for future cleanup. 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. To read the value, introduce the getter 'repo_auto_crlf()' and pass the repository down to the helpers in 'convert.c' that need it.

Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
 convert.c     | 68 +++++++++++++++++++++++++++++++--------------------
 convert.h     |  8 ------
 environment.c | 13 +++++++---
 environment.h |  9 +++++++
 4 files changed, 60 insertions(+), 38 deletions(-)
diff --git a/convert.c b/convert.c
index 95bdfafdd0..7c7fdd4b2d 100644
--- a/convert.c
+++ b/convert.c
@@ -158,11 +158,11 @@ const char *get_wt_convert_stats_ascii(const char *path)
 	return ret;
 }
 
-static int text_eol_is_crlf(void)
+static int text_eol_is_crlf(struct repository *repo)
 {
-	if (auto_crlf == AUTO_CRLF_TRUE)
+	if (repo_auto_crlf(repo) == AUTO_CRLF_TRUE)
 		return 1;
-	else if (auto_crlf == AUTO_CRLF_INPUT)
+	else if (repo_auto_crlf(repo) == AUTO_CRLF_INPUT)
 		return 0;
 	if (core_eol == EOL_CRLF)
 		return 1;
@@ -171,7 +171,8 @@ static int text_eol_is_crlf(void)
 	return 0;
 }
 
-static enum eol output_eol(enum convert_crlf_action crlf_action)
+static enum eol output_eol(struct repository *repo,
+			   enum convert_crlf_action crlf_action)
 {
 	switch (crlf_action) {
 	case CRLF_BINARY:
@@ -188,7 +189,7 @@ static enum eol output_eol(enum convert_crlf_action crlf_action)
 	case CRLF_TEXT:
 	case CRLF_AUTO:
 		/* fall through */
-		return text_eol_is_crlf() ? EOL_CRLF : EOL_LF;
+		return text_eol_is_crlf(repo) ? EOL_CRLF : EOL_LF;
 	}
 	warning(_("illegal crlf_action %d"), (int)crlf_action);
 	return core_eol;
@@ -244,10 +245,11 @@ static int has_crlf_in_index(struct index_state *istate, const char *path)
 	return has_crlf;
 }
 
-static int will_convert_lf_to_crlf(struct text_stat *stats,
+static int will_convert_lf_to_crlf(struct repository *repo,
+				   struct text_stat *stats,
 				   enum convert_crlf_action crlf_action)
 {
-	if (output_eol(crlf_action) != EOL_CRLF)
+	if (output_eol(repo, crlf_action) != EOL_CRLF)
 		return 0;
 	/* No "naked" LF? Nothing to convert, regardless. */
 	if (!stats->lonelf)
@@ -505,6 +507,8 @@ static int crlf_to_git(struct index_state *istate,
 		       struct strbuf *buf,
 		       enum convert_crlf_action crlf_action, int conv_flags)
 {
+	struct repository *repo = istate && istate->repo ?
+				  istate->repo : the_repository;
 	struct text_stat stats;
 	char *dst;
 	int convert_crlf_into_lf;
@@ -547,7 +551,7 @@ static int crlf_to_git(struct index_state *istate,
 			new_stats.crlf = 0;
 		}
 		/* simulate "git checkout" */
-		if (will_convert_lf_to_crlf(&new_stats, crlf_action)) {
+		if (will_convert_lf_to_crlf(repo, &new_stats, crlf_action)) {
 			new_stats.crlf += new_stats.lonelf;
 			new_stats.lonelf = 0;
 		}
@@ -589,17 +593,18 @@ static int crlf_to_git(struct index_state *istate,
 	return 1;
 }
 
-static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
+static int crlf_to_worktree(struct repository *repo,
+			    const char *src, size_t len, struct strbuf *buf,
 			    enum convert_crlf_action crlf_action)
 {
 	char *to_free = NULL;
 	struct text_stat stats;
 
-	if (!len || output_eol(crlf_action) != EOL_CRLF)
+	if (!len || output_eol(repo, crlf_action) != EOL_CRLF)
 		return 0;
 
 	gather_stats(src, len, &stats);
-	if (!will_convert_lf_to_crlf(&stats, crlf_action))
+	if (!will_convert_lf_to_crlf(repo, &stats, crlf_action))
 		return 0;
 
 	/* are we "faking" in place editing ? */
@@ -1321,6 +1326,8 @@ static struct attr_check *check;
 void convert_attrs(struct index_state *istate,
 		   struct conv_attrs *ca, const char *path)
 {
+	struct repository *repo = istate && istate->repo ?
+				  istate->repo : the_repository;
 	struct attr_check_item *ccheck = NULL;
 
 	if (!check) {
@@ -1354,12 +1361,16 @@ void convert_attrs(struct index_state *istate,
 	/* Save attr and make a decision for action */
 	ca->attr_action = ca->crlf_action;
 	if (ca->crlf_action == CRLF_TEXT)
-		ca->crlf_action = text_eol_is_crlf() ? CRLF_TEXT_CRLF : CRLF_TEXT_INPUT;
-	if (ca->crlf_action == CRLF_UNDEFINED && auto_crlf == AUTO_CRLF_FALSE)
+		ca->crlf_action = text_eol_is_crlf(repo) ?
+				  CRLF_TEXT_CRLF : CRLF_TEXT_INPUT;
+	if (ca->crlf_action == CRLF_UNDEFINED &&
+	    repo_auto_crlf(repo) == AUTO_CRLF_FALSE)
 		ca->crlf_action = CRLF_BINARY;
-	if (ca->crlf_action == CRLF_UNDEFINED && auto_crlf == AUTO_CRLF_TRUE)
+	if (ca->crlf_action == CRLF_UNDEFINED &&
+	    repo_auto_crlf(repo) == AUTO_CRLF_TRUE)
 		ca->crlf_action = CRLF_AUTO_CRLF;
-	if (ca->crlf_action == CRLF_UNDEFINED && auto_crlf == AUTO_CRLF_INPUT)
+	if (ca->crlf_action == CRLF_UNDEFINED &&
+	    repo_auto_crlf(repo) == AUTO_CRLF_INPUT)
 		ca->crlf_action = CRLF_AUTO_INPUT;
 }
 
@@ -1479,7 +1490,8 @@ void convert_to_git_filter_fd(struct index_state *istate,
 	ident_to_git(dst->buf, dst->len, dst, ca.ident);
 }
 
-static int convert_to_working_tree_ca_internal(const struct conv_attrs *ca,
+static int convert_to_working_tree_ca_internal(struct repository *repo,
+					       const struct conv_attrs *ca,
 					       const char *path, const char *src,
 					       size_t len, struct strbuf *dst,
 					       int normalizing,
@@ -1499,7 +1511,7 @@ static int convert_to_working_tree_ca_internal(const struct conv_attrs *ca,
 	 * support smudge).  The filters might expect CRLFs.
 	 */
 	if ((ca->drv && (ca->drv->smudge || ca->drv->process)) || !normalizing) {
-		ret |= crlf_to_worktree(src, len, dst, ca->crlf_action);
+		ret |= crlf_to_worktree(repo, src, len, dst, ca->crlf_action);
 		if (ret) {
 			src = dst->buf;
 			len = dst->len;
@@ -1520,25 +1532,25 @@ static int convert_to_working_tree_ca_internal(const struct conv_attrs *ca,
 	return ret | ret_filter;
 }
 
-int async_convert_to_working_tree_ca(struct repository *repo UNUSED,
+int async_convert_to_working_tree_ca(struct repository *repo,
 				     const struct conv_attrs *ca,
 				     const char *path, const char *src,
 				     size_t len, struct strbuf *dst,
 				     const struct checkout_metadata *meta,
 				     void *dco)
 {
-	return convert_to_working_tree_ca_internal(ca, path, src, len, dst, 0,
-						   meta, dco);
+	return convert_to_working_tree_ca_internal(repo, ca, path, src, len,
+						   dst, 0, meta, dco);
 }
 
-int convert_to_working_tree_ca(struct repository *repo UNUSED,
+int convert_to_working_tree_ca(struct repository *repo,
 			       const struct conv_attrs *ca,
 			       const char *path, const char *src,
 			       size_t len, struct strbuf *dst,
 			       const struct checkout_metadata *meta)
 {
-	return convert_to_working_tree_ca_internal(ca, path, src, len, dst, 0,
-						   meta, NULL);
+	return convert_to_working_tree_ca_internal(repo, ca, path, src, len,
+						   dst, 0, meta, NULL);
 }
 
 int convert_to_working_tree(struct index_state *istate,
@@ -1570,12 +1582,14 @@ int async_convert_to_working_tree(struct index_state *istate,
 int renormalize_buffer(struct index_state *istate, const char *path,
 		       const char *src, size_t len, struct strbuf *dst)
 {
+	struct repository *repo = istate && istate->repo ?
+				  istate->repo : the_repository;
 	struct conv_attrs ca;
 	int ret;
 
 	convert_attrs(istate, &ca, path);
-	ret = convert_to_working_tree_ca_internal(&ca, path, src, len, dst, 1,
-						  NULL, NULL);
+	ret = convert_to_working_tree_ca_internal(repo, &ca, path, src, len,
+						  dst, 1, NULL, NULL);
 	if (ret) {
 		src = dst->buf;
 		len = dst->len;
@@ -2009,7 +2023,7 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
  * Note that you would be crazy to set CRLF, smudge/clean or ident to a
  * large binary blob you would want us not to slurp into the memory!
  */
-struct stream_filter *get_stream_filter_ca(struct repository *repo UNUSED,
+struct stream_filter *get_stream_filter_ca(struct repository *repo,
 					   const struct conv_attrs *ca,
 					   const struct object_id *oid)
 {
@@ -2021,7 +2035,7 @@ struct stream_filter *get_stream_filter_ca(struct repository *repo UNUSED,
 	if (ca->ident)
 		filter = ident_filter(oid);
 
-	if (output_eol(ca->crlf_action) == EOL_CRLF)
+	if (output_eol(repo, ca->crlf_action) == EOL_CRLF)
 		filter = cascade_filter(filter, lf_to_crlf_filter());
 	else
 		filter = cascade_filter(filter, &null_filter_singleton);
diff --git a/convert.h b/convert.h
index 137fa1593a..dae11d372d 100644
--- a/convert.h
+++ b/convert.h
@@ -19,14 +19,6 @@ struct strbuf;
 
 extern int global_conv_flags_eol;
 
-enum auto_crlf {
-	AUTO_CRLF_FALSE = 0,
-	AUTO_CRLF_TRUE = 1,
-	AUTO_CRLF_INPUT = -1
-};
-
-extern enum auto_crlf auto_crlf;
-
 enum eol {
 	EOL_UNSET,
 	EOL_CRLF,
diff --git a/environment.c b/environment.c
index c83cf44839..bbac8ed8c9 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 auto_crlf auto_crlf = AUTO_CRLF_FALSE;
 enum eol core_eol = EOL_UNSET;
 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
 char *check_roundtrip_encoding;
@@ -152,6 +151,13 @@ int repo_has_symlinks(struct repository *repo)
 		: platform_has_symlinks();
 }
 
+enum auto_crlf repo_auto_crlf(struct repository *repo)
+{
+	return repo->initialized
+		? repo_config_values(repo)->auto_crlf
+		: AUTO_CRLF_FALSE;
+}
+
 const char *repo_excludes_file(struct repository *repo)
 {
 	struct repo_config_values *cfg = repo_config_values(repo);
@@ -420,10 +426,10 @@ int git_default_core_config(const char *var, const char *value,
 
 	if (!strcmp(var, "core.autocrlf")) {
 		if (value && !strcasecmp(value, "input")) {
-			auto_crlf = AUTO_CRLF_INPUT;
+			cfg->auto_crlf = AUTO_CRLF_INPUT;
 			return 0;
 		}
-		auto_crlf = git_config_bool(var, value);
+		cfg->auto_crlf = git_config_bool(var, value);
 		return 0;
 	}
 
@@ -777,6 +783,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
 	cfg->trust_executable_bit = 1;
 	cfg->has_symlinks = platform_has_symlinks();
 	cfg->use_nanosec = 0;
+	cfg->auto_crlf = AUTO_CRLF_FALSE;
 
 	/* section "sparse" config values */
 	cfg->sparse_expect_files_outside_of_patterns = 0;
diff --git a/environment.h b/environment.h
index 49c86e8879..872da3576b 100644
--- a/environment.h
+++ b/environment.h
@@ -123,6 +123,12 @@ enum object_creation_mode {
 	OBJECT_CREATION_USES_RENAMES = 1
 };
 
+enum auto_crlf {
+	AUTO_CRLF_FALSE = 0,
+	AUTO_CRLF_TRUE = 1,
+	AUTO_CRLF_INPUT = -1
+};
+
 struct repo_config_values {
 	/* section "core" config values */
 	char *attributes_file;
@@ -149,6 +155,7 @@ struct repo_config_values {
 	int trust_executable_bit;
 	int has_symlinks;
 	int use_nanosec;
+	enum auto_crlf auto_crlf;
 
 	/* section "sparse" config values */
 	int sparse_expect_files_outside_of_patterns;
@@ -203,6 +210,8 @@ int repo_trust_executable_bit(struct repository *repo);
 
 int repo_has_symlinks(struct repository *repo);
 
+enum auto_crlf repo_auto_crlf(struct repository *repo);
+
 const char *repo_excludes_file(struct repository *repo);
 
 void repo_config_values_init(struct repo_config_values *cfg);
-- 
2.43.0
Previous: Aniket GuptaNext: Aniket Gupta
Message 3 of 11 in “environment: move line ending config variables into repo_config_values”
  1. 0/4 environment: move line ending config variables into repo_config_valuesAniket Gupta, Oct 24, 2026
  2. 1/4 convert: pass 'repo' to the working tree conversion functionsAniket Gupta, Oct 24, 2026
  3. 2/4 environment: move auto_crlf into repo_config_valuesAniket Gupta, Oct 24, 2026
  4. 3/4 environment: move core_eol into repo_config_valuesAniket Gupta, Oct 24, 2026
  5. 4/4 environment: move global_conv_flags_eol into repo_config_valuesAniket Gupta, Oct 24, 2026
  6. Patrick SteinhardtOct 26, 2026
  7. Aniket GuptaOct 26, 2026
  8. Patrick SteinhardtOct 26, 2026
  9. Junio C HamanoOct 26, 2026
  10. Patrick SteinhardtNov 3, 2026
  11. Junio C HamanoNov 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.