diff --check is stupid about blank lines

Subsystems: the rest

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

diff --check is stupid about blank lines

From: Björn Steinbrink <hidden>
Date: 2016-06-15 22:45:11

Hi,

diff --check triggers not only for blank lines at the end of the file,
but also at the end of the changes. That seems broken to me, unless you
really dislike empty lines.

For example:
git (master) $ git diff
diff --git a/git.c b/git.c
index 37b1d76..3fa1aeb 100644
--- a/git.c
+++ b/git.c
@@ -9,6 +9,8 @@ const char git_usage_string[] =
 const char git_more_info_string[] =
        "See 'git help COMMAND' for more information on a specific command.";
 
+int new_var = 0;
+
 static int use_pager = -1;
 struct pager_config {
        const char *cmd;
git (master) $ git diff --check
git.c:13: ends with blank lines.

But that blank line was of course intentional.

I'm not quite sure why that happens though. The code in
checkdiff_consume seems to reset the flag when it sees context lines,
but apparently that does not work for some reason.

git version 1.6.0.36.g3814c

Björn

Re: diff --check is stupid about blank lines

From: Jeff King <hidden>
Date: 2016-06-15 22:45:11

On Wed, Aug 20, 2008 at 04:05:17PM +0200, Björn Steinbrink wrote:
diff --check triggers not only for blank lines at the end of the file,
but also at the end of the changes. That seems broken to me, unless you
really dislike empty lines.
Hmm, yes, that seems wrong. The problem seems to be the conditional at
diff.c:1622:

        if ((data.ws_rule & WS_TRAILING_SPACE) &&
            data.trailing_blanks_start) {
                fprintf(o->file, "%s:%d: ends with blank lines.\n",
                        data.filename, data.trailing_blanks_start);
                data.status = 1; /* report errors */
        }

that should probably be "if we care about trailing space, and the last
thing we saw was a trailing blank, _and_ the last hunk adds to
end-of-file, then...". However, I'm not sure what is the best way to get
that information out of xdiff. Is there a "this hunk hits eof" signal
anywhere? Is there a definitive line count we could use to calculate
that it is in the chunk of final lines in the file?

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help