From: brian m. carlson Date: Sat, 26 Apr 2014 23:10:40 GMT Subject: [PATCH v2] blame: correctly handle files regardless of autocrlf. Message-ID: <1398553840-279066-1-git-send-email-sandals@crustytoothpaste.net> In-Reply-To: <20140425150726.GA234593@vauxhall.crustytoothpaste.net> 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 Signed-off-by: brian m. carlson --- > 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