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

[PATCH (BUGFIX)] Respect core.autocrlf in combined diff

From
Alexander Gavrilov <angavrilov@gmail.com>
Date
Aug 23, 2008, 19:21 UTC
Message-ID
<200808232321.21795.angavrilov@gmail.com>

Fix git-diff to make it produce useful 3-way diffs for merge conflicts in repositories with autocrlf enabled. Otherwise it always reports that the whole file was changed.

Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com>
---
	I noticed that combined diffs, which are shown by git-diff for files
	with conflicts, are unusable on repositories with autocrlf=true. 
	Steps to reproduce:
		git init
		echo foo > file
		git add file
		git commit -m init
		git checkout -b a
		git checkout -b b
		echo bbb >> file
		git add file
		git commit -m bbb
		git checkout a
		echo aaa >> file
		git add file
		git commit -m aaa
		git config core.autocrlf true
		git merge b
	Then look at the output of git diff.
	-- Alexander
 combine-diff.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/combine-diff.c b/combine-diff.c
index 9f80a1c..da1ca99 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -727,6 +727,18 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 				die("early EOF '%s'", elem->path);
 
 			result[len] = 0;
+
+			/* If not a fake symlink, apply filters, e.g. autocrlf */
+			if (is_file) {
+				struct strbuf buf;
+				
+				strbuf_init(&buf, 0);
+				if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {
+					free(result);
+					result = strbuf_detach(&buf, &len);
+					result_size = len;
+				}
+			}
 		}
 		else {
 		deleted_file:
-- 
1.6.0.rc2
Next: Junio C Hamano
Message 1 of 4 in “Respect core.autocrlf in combined diff”
  1. Respect core.autocrlf in combined diffAlexander Gavrilov, Aug 23, 2008
  2. Junio C HamanoAug 24, 2008
  3. Junio C HamanoAug 24, 2008
  4. Alexander GavrilovAug 24, 2008

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.