git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/maint] diff: Fix miscounting of --check output

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 16, 2008, 04:30 UTC
Message-ID
<7vk5l5frqq.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<76718490802151218s62c4f884u39353b66540b347a@mail.gmail.com>
"Jay Soffian" <jaysoffian@gmail.com> writes:
> Apparently somewhere in the bowels of the "Crazy xdl interfaces", empty
> lines are skipped over, thus the line number counting in
> checkdiff_consume() is off? I dunno, I briefly looked into fixing it but
> it didn't seem like a quick fix.
Good catch, thanks.

This is not xdl interface, but simply a miscounting by the user of xdl interface. Here is a fix.

-- >8 -- diff: Fix miscounting of --check output

c1795bb (Unify whitespace checking) incorrectly made the checking function return without incrementing the line numbers when there is no whitespace problem is found on a '+' line.

This resurrects the earlier behaviour.
Noticed and reported by Jay Soffian.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index 047310f..90af600 100644
--- a/diff.c
+++ b/diff.c
@@ -1021,6 +1021,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
 	char *err;
 
 	if (line[0] == '+') {
+		data->lineno++;
 		data->status = check_and_emit_line(line + 1, len - 1,
 		    data->ws_rule, NULL, NULL, NULL, NULL);
 		if (!data->status)
@@ -1031,13 +1032,12 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
 		emit_line(set, reset, line, 1);
 		(void)check_and_emit_line(line + 1, len - 1, data->ws_rule,
 		    stdout, set, reset, ws);
-		data->lineno++;
 	} else if (line[0] == ' ')
 		data->lineno++;
 	else if (line[0] == '@') {
 		char *plus = strchr(line, '+');
 		if (plus)
-			data->lineno = strtol(plus, NULL, 10);
+			data->lineno = strtol(plus, NULL, 10) - 1;
 		else
 			die("invalid diff");
 	}
Previous: Jay Soffian
Message 2 of 2 in “diff --check line number bug”
  1. Jay SoffianFeb 15, 2008
  2. diff: Fix miscounting of --check outputJunio C Hamano, Feb 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.