* diff --check is stupid about blank lines @ 2008-08-20 14:05 Björn Steinbrink 2008-08-20 17:28 ` Jeff King 0 siblings, 1 reply; 7+ messages in thread From: Björn Steinbrink @ 2008-08-20 14:05 UTC (permalink / raw) To: Junio C Hamano; +Cc: git 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 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: diff --check is stupid about blank lines 2008-08-20 14:05 diff --check is stupid about blank lines Björn Steinbrink @ 2008-08-20 17:28 ` Jeff King 2008-08-20 18:13 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Jeff King @ 2008-08-20 17:28 UTC (permalink / raw) To: Björn Steinbrink; +Cc: Junio C Hamano, git 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: diff --check is stupid about blank lines 2008-08-20 17:28 ` Jeff King @ 2008-08-20 18:13 ` Junio C Hamano 2008-08-20 18:42 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2008-08-20 18:13 UTC (permalink / raw) To: Jeff King; +Cc: Björn Steinbrink, git Jeff King <peff@peff.net> writes: > ... 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...". Instead, data.trailing_blanks_start is supposed to be reset to 0 every time we see non-blank newline, a copied context line, or new hunk. So if this triggers with -U0 I'd understand, but otherwise I do not see how. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: diff --check is stupid about blank lines 2008-08-20 18:13 ` Junio C Hamano @ 2008-08-20 18:42 ` Junio C Hamano 2008-08-20 20:02 ` Björn Steinbrink 2008-08-20 22:20 ` Jeff King 0 siblings, 2 replies; 7+ messages in thread From: Junio C Hamano @ 2008-08-20 18:42 UTC (permalink / raw) To: Jeff King; +Cc: Björn Steinbrink, git Junio C Hamano <gitster@pobox.com> writes: > Jeff King <peff@peff.net> writes: > >> ... 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...". > > Instead, data.trailing_blanks_start is supposed to be reset to 0 every > time we see non-blank newline, a copied context line, or new hunk. > > So if this triggers with -U0 I'd understand, but otherwise I do not see > how. Ahhh, what idiot wrote the logic for checking trailing blank lines in checkdiff_consume(). It does not ask for any context lines. Sheesh. This should fix it. diff --git i/diff.c w/diff.c index 10d5440..5923fe2 100644 --- i/diff.c +++ w/diff.c @@ -1628,6 +1628,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, xdemitcb_t ecb; memset(&xecfg, 0, sizeof(xecfg)); + xecfg.ctxlen = 1; /* at least one context line */ xpp.flags = XDF_NEED_MINIMAL; xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data, &xpp, &xecfg, &ecb); ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: diff --check is stupid about blank lines 2008-08-20 18:42 ` Junio C Hamano @ 2008-08-20 20:02 ` Björn Steinbrink 2008-08-20 22:20 ` Jeff King 1 sibling, 0 replies; 7+ messages in thread From: Björn Steinbrink @ 2008-08-20 20:02 UTC (permalink / raw) To: Junio C Hamano; +Cc: Jeff King, git On 2008.08.20 11:42:34 -0700, Junio C Hamano wrote: > Junio C Hamano <gitster@pobox.com> writes: > > Instead, data.trailing_blanks_start is supposed to be reset to 0 every > > time we see non-blank newline, a copied context line, or new hunk. > > > > So if this triggers with -U0 I'd understand, but otherwise I do not see > > how. > > Ahhh, what idiot wrote the logic for checking trailing blank lines in > checkdiff_consume(). > > It does not ask for any context lines. Sheesh. > > This should fix it. Thanks, works for me :-) Björn ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: diff --check is stupid about blank lines 2008-08-20 18:42 ` Junio C Hamano 2008-08-20 20:02 ` Björn Steinbrink @ 2008-08-20 22:20 ` Jeff King 2008-08-20 22:39 ` Junio C Hamano 1 sibling, 1 reply; 7+ messages in thread From: Jeff King @ 2008-08-20 22:20 UTC (permalink / raw) To: Junio C Hamano; +Cc: Björn Steinbrink, git On Wed, Aug 20, 2008 at 11:42:34AM -0700, Junio C Hamano wrote: > Ahhh, what idiot wrote the logic for checking trailing blank lines in > checkdiff_consume(). > > It does not ask for any context lines. Sheesh. > > This should fix it. Ah, that was much easier than I expected. ;) Maybe this should be squashed in? --- diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 6110566..974efd0 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -341,4 +341,13 @@ test_expect_success 'checkdiff detects trailing blank lines' ' git diff --check | grep "ends with blank" ' +test_expect_success 'checkdiff does not mistake trailing blank lines in hunk' ' + echo content >x && + git add x && + echo "" >x && + echo content >>x && + git diff --check >out && + ! grep "ends with blank" out +' + test_done ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: diff --check is stupid about blank lines 2008-08-20 22:20 ` Jeff King @ 2008-08-20 22:39 ` Junio C Hamano 0 siblings, 0 replies; 7+ messages in thread From: Junio C Hamano @ 2008-08-20 22:39 UTC (permalink / raw) To: Jeff King; +Cc: Björn Steinbrink, git Jeff King <peff@peff.net> writes: > On Wed, Aug 20, 2008 at 11:42:34AM -0700, Junio C Hamano wrote: > >> Ahhh, what idiot wrote the logic for checking trailing blank lines in >> checkdiff_consume(). >> >> It does not ask for any context lines. Sheesh. >> >> This should fix it. > > Ah, that was much easier than I expected. ;) > > Maybe this should be squashed in? Thanks but I've done that myself already. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-08-20 22:40 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-08-20 14:05 diff --check is stupid about blank lines Björn Steinbrink 2008-08-20 17:28 ` Jeff King 2008-08-20 18:13 ` Junio C Hamano 2008-08-20 18:42 ` Junio C Hamano 2008-08-20 20:02 ` Björn Steinbrink 2008-08-20 22:20 ` Jeff King 2008-08-20 22:39 ` 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).