* git diff --check always shows line 1 for blank at EOF for new files @ 2010-10-06 9:27 Christoph Mallon 2010-10-07 9:32 ` Jonathan Nieder 0 siblings, 1 reply; 4+ messages in thread From: Christoph Mallon @ 2010-10-06 9:27 UTC (permalink / raw) To: git Hi, there seems to be a glitch in git diff --check for new files: If a new file has trailing empty lines, then the error message always refers to line 1. This happens with git 1.7.3.1. Here is a simple test case: git init test cd test printf 'a\nb\nc\n\n' > file git add -AN git diff --check The last command will show "file:1: new blank line at EOF.". It works fine, if the diff is not against /dev/null, e.g.: git init test cd test printf 'a\nb\nc\n' > file git add -A echo >> file git diff --check This correctly shows "file:4: new blank line at EOF.". ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: git diff --check always shows line 1 for blank at EOF for new files 2010-10-06 9:27 git diff --check always shows line 1 for blank at EOF for new files Christoph Mallon @ 2010-10-07 9:32 ` Jonathan Nieder 2010-10-07 12:33 ` Christoph Mallon 0 siblings, 1 reply; 4+ messages in thread From: Jonathan Nieder @ 2010-10-07 9:32 UTC (permalink / raw) To: Christoph Mallon; +Cc: git Hi Christoph, Christoph Mallon wrote: > git init test > cd test > printf 'a\nb\nc\n\n' > file > git add -AN > git diff --check > > The last command will show "file:1: new blank line at EOF.". > > It works fine, if the diff is not against /dev/null, e.g.: > git init test > cd test > printf 'a\nb\nc\n' > file > git add -A > echo >> file > git diff --check > > This correctly shows "file:4: new blank line at EOF.". Try this: git init test cd test printf 'a\nb\nc\n' > file git add -A echo hello >> file echo >> file git diff --check As you can see, it still returns line 4, which is the beginning of the hunk that adds the blank line. A change to make it print the line number of the blank line itself does not sound so bad, though. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: git diff --check always shows line 1 for blank at EOF for new files 2010-10-07 9:32 ` Jonathan Nieder @ 2010-10-07 12:33 ` Christoph Mallon 2010-10-10 10:46 ` Junio C Hamano 0 siblings, 1 reply; 4+ messages in thread From: Christoph Mallon @ 2010-10-07 12:33 UTC (permalink / raw) To: Jonathan Nieder; +Cc: git [-- Attachment #1: Type: text/plain, Size: 490 bytes --] On 07.10.2010 11:32, Jonathan Nieder wrote: > Try this: > > git init test > cd test > printf 'a\nb\nc\n'> file > git add -A > echo hello>> file > echo>> file > git diff --check > > As you can see, it still returns line 4, which is the beginning of the > hunk that adds the blank line. > > A change to make it print the line number of the blank line itself > does not sound so bad, though. You're right. I think, the attached patch corrects the issue. [-- Attachment #2: 0001-When-git-diff-check-detects-a-blank-line-at-EOF-show.patch --] [-- Type: text/plain, Size: 818 bytes --] >From 45eaa882dae35f2976e77cf0b6b06be78283c13f Mon Sep 17 00:00:00 2001 From: Christoph Mallon <christoph.mallon@gmx.de> Date: Thu, 7 Oct 2010 14:22:02 +0200 Subject: [PATCH] When git diff --check detects a blank line at EOF, show the line number of the empty line, not the line number of the beginning of the hunk. --- diff.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/diff.c b/diff.c index 71efa8e..452fdf4 100644 --- a/diff.c +++ b/diff.c @@ -2153,7 +2153,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, ecbdata.ws_rule = data.ws_rule; check_blank_at_eof(&mf1, &mf2, &ecbdata); - blank_at_eof = ecbdata.blank_at_eof_in_preimage; + blank_at_eof = ecbdata.blank_at_eof_in_postimage; if (blank_at_eof) { static char *err; -- 1.7.3 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: git diff --check always shows line 1 for blank at EOF for new files 2010-10-07 12:33 ` Christoph Mallon @ 2010-10-10 10:46 ` Junio C Hamano 0 siblings, 0 replies; 4+ messages in thread From: Junio C Hamano @ 2010-10-10 10:46 UTC (permalink / raw) To: Christoph Mallon; +Cc: Jonathan Nieder, git Christoph Mallon <christoph.mallon@gmx.de> writes: > On 07.10.2010 11:32, Jonathan Nieder wrote: >> Try this: >> >> git init test >> cd test >> printf 'a\nb\nc\n'> file >> git add -A >> echo hello>> file >> echo>> file >> git diff --check >> >> As you can see, it still returns line 4, which is the beginning of the >> hunk that adds the blank line. >> >> A change to make it print the line number of the blank line itself >> does not sound so bad, though. > > You're right. I think, the attached patch corrects the issue. > > From 45eaa882dae35f2976e77cf0b6b06be78283c13f Mon Sep 17 00:00:00 2001 > From: Christoph Mallon <christoph.mallon@gmx.de> > Date: Thu, 7 Oct 2010 14:22:02 +0200 > Subject: [PATCH] When git diff --check detects a blank line at EOF, show the line number of the empty line, not the line number of the beginning of the hunk. > > --- Could you check Documentation/SubmittingPatches, please? > diff.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/diff.c b/diff.c > index 71efa8e..452fdf4 100644 > --- a/diff.c > +++ b/diff.c > @@ -2153,7 +2153,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, > > ecbdata.ws_rule = data.ws_rule; > check_blank_at_eof(&mf1, &mf2, &ecbdata); > - blank_at_eof = ecbdata.blank_at_eof_in_preimage; > + blank_at_eof = ecbdata.blank_at_eof_in_postimage; Hmm, I am confused. Your subject line claims that for this patch: diff --git a/Makefile b/Makefile index 1f1ce04..90075e0 100644 --- a/Makefile +++ b/Makefile @@ -2375,3 +2375,8 @@ cover_db: coverage-report cover_db_html: cover_db cover -report html -outputdir cover_db_html cover_db + +new-rule: + echo here is a new rule + + the code used to diagnose the error by showing the first line of the hunk (2375 taken from either -2375 or +2375, it does not matter much). The claim is that your patch makes it to show the first line in the trailing blank line block (the line after "here is a new rule", i.e. line 2381 in the postimage). But my reading of the code is that it is showing (incorrectly) the first line of the trailing blank line block in the preimage (in this case, because our codebase is clean, there is zero line of trailing blank line block in the preimage, so it points at 2378. So the patch looks correct, but the diagnosis / description seems wrong. Since I am asking you to refer to SubmittingPatches to give a better subject line, patch description and a sign-off anyway,... Thanks. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-10 10:46 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-10-06 9:27 git diff --check always shows line 1 for blank at EOF for new files Christoph Mallon 2010-10-07 9:32 ` Jonathan Nieder 2010-10-07 12:33 ` Christoph Mallon 2010-10-10 10:46 ` Junio C Hamano
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).