Git development
 help / color / mirror / Atom feed
From: Aniket Gupta <aniketgupta3001@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, christian.couder@gmail.com, cat@malon.dev,
	belkid98@gmail.com, ps@pks.im, phillip.wood123@gmail.com
Subject: [PATCH 2/4] environment: move auto_crlf into repo_config_values
Date: Sat, 24 Oct 2026 22:00:10 +0000	[thread overview]
Message-ID: <20261024220012.486-3-aniketgupta3001@gmail.com> (raw)
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


  parent reply	other threads:[~2026-10-24 22:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24 22:00 [PATCH 0/4] environment: move line ending config variables into repo_config_values Aniket Gupta
2026-10-24 22:00 ` [PATCH 1/4] convert: pass 'repo' to the working tree conversion functions Aniket Gupta
2026-10-24 22:00 ` Aniket Gupta [this message]
2026-10-24 22:00 ` [PATCH 3/4] environment: move core_eol into repo_config_values Aniket Gupta
2026-10-24 22:00 ` [PATCH 4/4] environment: move global_conv_flags_eol " Aniket Gupta
2026-10-26 12:27 ` [PATCH 0/4] environment: move line ending config variables " Patrick Steinhardt
2026-10-26 13:10   ` Aniket Gupta
2026-10-26 13:25     ` Patrick Steinhardt
2026-10-26 15:53   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261024220012.486-3-aniketgupta3001@gmail.com \
    --to=aniketgupta3001@gmail.com \
    --cc=belkid98@gmail.com \
    --cc=cat@malon.dev \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood123@gmail.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox