All of lore.kernel.org
 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 4/4] environment: move global_conv_flags_eol into repo_config_values
Date: Sat, 24 Oct 2026 22:00:12 +0000	[thread overview]
Message-ID: <20261024220012.486-5-aniketgupta3001@gmail.com> (raw)
In-Reply-To: <20261024220012.486-1-aniketgupta3001@gmail.com>

The global variable 'global_conv_flags_eol' holds the value of the
'core.safecrlf' configuration, which controls whether Git warns or
refuses to proceed when converting line endings would not be
reversible. Move it into 'struct repo_config_values' to continue the
libification effort.

Initialize the per-repository value to its default in
'repo_config_values_init()', and modify the configuration parsing in
environment.c to update the per-repository structure directly.

To read the value, introduce the getter 'repo_global_conv_flags_eol()'
and update its users in diff.c, combine-diff.c and object-file.c. In
object-file.c, pass the index to get_conv_flags() so that it can find
the repository.

Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
 combine-diff.c |  4 +++-
 convert.h      |  2 --
 diff.c         |  2 +-
 environment.c  | 13 ++++++++++---
 environment.h  |  3 +++
 object-file.c  | 11 +++++++----
 6 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/combine-diff.c b/combine-diff.c
index 717d537688..c77990aacf 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1098,9 +1098,11 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 			/* If not a fake symlink, apply filters, e.g. autocrlf */
 			if (is_file) {
 				struct strbuf buf = STRBUF_INIT;
+				int conv_flags =
+					repo_global_conv_flags_eol(rev->diffopt.repo);
 
 				if (convert_to_git(rev->diffopt.repo->index,
-						   elem->path, result, len, &buf, global_conv_flags_eol)) {
+						   elem->path, result, len, &buf, conv_flags)) {
 					free(result);
 					result = strbuf_detach(&buf, &len);
 					result_size = len;
diff --git a/convert.h b/convert.h
index 3c51130177..18be39ca90 100644
--- a/convert.h
+++ b/convert.h
@@ -17,8 +17,6 @@ struct strbuf;
 #define CONV_EOL_KEEP_CRLF    (1<<3) /* Keep CRLF line endings as is */
 #define CONV_WRITE_OBJECT     (1<<4) /* Content is written to the index */
 
-extern int global_conv_flags_eol;
-
 enum ce_delay_state {
 	CE_NO_DELAY = 0,
 	CE_CAN_DELAY = 1,
diff --git a/diff.c b/diff.c
index b4ac17f8ef..7eb45160c2 100644
--- a/diff.c
+++ b/diff.c
@@ -4480,7 +4480,7 @@ int diff_populate_filespec(struct repository *r,
 	int size_only = options ? options->check_size_only : 0;
 	int check_binary = options ? options->check_binary : 0;
 	int err = 0;
-	int conv_flags = global_conv_flags_eol;
+	int conv_flags = repo_global_conv_flags_eol(r);
 	/*
 	 * demote FAIL to WARN to allow inspecting the situation
 	 * instead of refusing.
diff --git a/environment.c b/environment.c
index 6445994986..9b98b3b075 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;
-int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
 char *check_roundtrip_encoding;
 #ifndef OBJECT_CREATION_MODE
 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
@@ -164,6 +163,13 @@ enum eol repo_core_eol(struct repository *repo)
 		: EOL_UNSET;
 }
 
+int repo_global_conv_flags_eol(struct repository *repo)
+{
+	return repo->initialized
+		? repo_config_values(repo)->global_conv_flags_eol
+		: CONV_EOL_RNDTRP_WARN;
+}
+
 const char *repo_excludes_file(struct repository *repo)
 {
 	struct repo_config_values *cfg = repo_config_values(repo);
@@ -442,11 +448,11 @@ int git_default_core_config(const char *var, const char *value,
 	if (!strcmp(var, "core.safecrlf")) {
 		int eol_rndtrp_die;
 		if (value && !strcasecmp(value, "warn")) {
-			global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
+			cfg->global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
 			return 0;
 		}
 		eol_rndtrp_die = git_config_bool(var, value);
-		global_conv_flags_eol = eol_rndtrp_die ?
+		cfg->global_conv_flags_eol = eol_rndtrp_die ?
 			CONV_EOL_RNDTRP_DIE : 0;
 		return 0;
 	}
@@ -791,6 +797,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
 	cfg->use_nanosec = 0;
 	cfg->auto_crlf = AUTO_CRLF_FALSE;
 	cfg->core_eol = EOL_UNSET;
+	cfg->global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
 
 	/* section "sparse" config values */
 	cfg->sparse_expect_files_outside_of_patterns = 0;
diff --git a/environment.h b/environment.h
index bf6701560d..47d7a9792d 100644
--- a/environment.h
+++ b/environment.h
@@ -168,6 +168,7 @@ struct repo_config_values {
 	int use_nanosec;
 	enum auto_crlf auto_crlf;
 	enum eol core_eol;
+	int global_conv_flags_eol;
 
 	/* section "sparse" config values */
 	int sparse_expect_files_outside_of_patterns;
@@ -226,6 +227,8 @@ enum auto_crlf repo_auto_crlf(struct repository *repo);
 
 enum eol repo_core_eol(struct repository *repo);
 
+int repo_global_conv_flags_eol(struct repository *repo);
+
 const char *repo_excludes_file(struct repository *repo);
 
 void repo_config_values_init(struct repo_config_values *cfg);
diff --git a/object-file.c b/object-file.c
index c049bf13f7..b3ab8f5bcb 100644
--- a/object-file.c
+++ b/object-file.c
@@ -33,12 +33,15 @@
 #include "tempfile.h"
 #include "tmp-objdir.h"
 
-static int get_conv_flags(unsigned flags)
+static int get_conv_flags(struct index_state *istate, unsigned flags)
 {
+	struct repository *repo = istate && istate->repo ?
+				  istate->repo : the_repository;
+
 	if (flags & INDEX_RENORMALIZE)
 		return CONV_EOL_RENORMALIZE;
 	else if (flags & INDEX_WRITE_OBJECT)
-		return global_conv_flags_eol | CONV_WRITE_OBJECT;
+		return repo_global_conv_flags_eol(repo) | CONV_WRITE_OBJECT;
 	else
 		return 0;
 }
@@ -576,7 +579,7 @@ static int index_mem(struct index_state *istate,
 	 */
 	if ((type == OBJ_BLOB) && path) {
 		if (convert_to_git(istate, path, buf, size, &nbuf,
-				   get_conv_flags(flags))) {
+				   get_conv_flags(istate, flags))) {
 			buf = nbuf.buf;
 			size = nbuf.len;
 		}
@@ -615,7 +618,7 @@ static int index_stream_convert_blob(struct index_state *istate,
 	ASSERT(would_convert_to_git_filter_fd(istate, path));
 
 	convert_to_git_filter_fd(istate, path, fd, &sbuf,
-				 get_conv_flags(flags));
+				 get_conv_flags(istate, flags));
 
 	if (write_object)
 		ret = odb_write_object(istate->repo->objects, sbuf.buf, sbuf.len, OBJ_BLOB,
-- 
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 ` [PATCH 2/4] environment: move auto_crlf into repo_config_values Aniket Gupta
2026-10-24 22:00 ` [PATCH 3/4] environment: move core_eol " Aniket Gupta
2026-10-24 22:00 ` Aniket Gupta [this message]
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-5-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.