[PATCH v2] blame: correctly handle files regardless of autocrlf.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If a file contained CRLF line endings in a repository with
core.autocrlf=input, then blame always marked lines as "Not Committed Yet",
even if they were unmodified.  Don't attempt to convert the line endings
when creating the fake commit so that blame works correctly regardless of
the autocrlf setting.

Reported-by: Ephrim Khong <dr.khong@xxxxxxxxx>
Signed-off-by: brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx>
---
> On Tue, Apr 22, 2014 at 04:12:42PM -0700, Junio C Hamano wrote:
> >  I have a feeling that a fix for this should be fairly isolated and
> >  trivial (it should be just the matter of paying attention to the
> >  crlf settings when synthesizing the fake commit)---perhaps somebody
> >  can squash in a fix to this?
>
> Last time I looked at this, I couldn't come up with an obvious fix for
> the problem, or I would have included one.  I'll try to have another go
> at it this weekend.

This was actually a very helpful hint, Junio.  Thanks for the push in
the right direction.

This includes the suggestion by Torsten Bögershausen to use the git -c
for the blame command.

 builtin/blame.c               | 1 -
 t/t8003-blame-corner-cases.sh | 9 +++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 88cb799..eef3e86 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2088,7 +2088,6 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 		if (strbuf_read(&buf, 0, 0) < 0)
 			die_errno("failed to read from stdin");
 	}
-	convert_to_git(path, buf.buf, buf.len, &buf, 0);
 	origin->file.ptr = buf.buf;
 	origin->file.size = buf.len;
 	pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh
index e7cac1d..2a3469b 100755
--- a/t/t8003-blame-corner-cases.sh
+++ b/t/t8003-blame-corner-cases.sh
@@ -191,4 +191,13 @@ test_expect_success 'indent of line numbers, ten lines' '
 	test $(grep -c "  " actual) = 9
 '
 
+test_expect_success 'blaming files with CRLF newlines' '
+	git config core.autocrlf false &&
+	printf "testcase\r\n" >crlffile &&
+	git add crlffile &&
+	git commit -m testcase &&
+	git -c core.autocrlf=input blame crlffile >actual &&
+	grep "A U Thor" actual
+'
+
 test_done
-- 
2.0.0.rc0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]