{"thread":{"id":"12118","subject":"diff --check line number bug","startedAt":"2008-02-15T20:18:45Z","lastAt":"2008-02-16T04:30:05Z","messageCount":2,"participants":["Jay Soffian","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"68837","messageId":"76718490802151218s62c4f884u39353b66540b347a@mail.gmail.com","threadId":"12118","inReplyTo":null,"subject":"diff --check line number bug","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-15T20:18:45Z","receivedAt":"2008-02-15T20:18:45Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"% mkdir git-ws\n% cd git-ws\n% git init\n% touch foo\n% git add foo\n% printf '\\n\\nline 3 \\n\\nline 5 \\nline 6\\n' > foo\n% cat -n foo\n     1\t\n     2\t\n     3\tline 3\n     4\t\n     5\tline 5\n     6\tline 6\n% sed -ne l foo\n$\n$\nline 3 $\n$\nline 5 $\nline 6$\n% git diff --check foo\nfoo:1: trailing whitespace.\n+line 3\nfoo:2: trailing whitespace.\n+line 5\n% git version\ngit version 1.5.4.1.1281.g75df\n\nApparently somewhere in the bowels of the \"Crazy xdl interfaces\", empty\nlines are skipped over, thus the line number counting in\ncheckdiff_consume() is off? I dunno, I briefly looked into fixing it but\nit didn't seem like a quick fix.\n\nj.\n"},{"id":"68863","messageId":"7vk5l5frqq.fsf@gitster.siamese.dyndns.org","threadId":"12118","inReplyTo":"76718490802151218s62c4f884u39353b66540b347a@mail.gmail.com","subject":"[PATCH/maint] diff: Fix miscounting of --check output","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-16T04:30:05Z","receivedAt":"2008-02-16T04:30:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Jay Soffian\" <jaysoffian@gmail.com> writes:\n\n> Apparently somewhere in the bowels of the \"Crazy xdl interfaces\", empty\n> lines are skipped over, thus the line number counting in\n> checkdiff_consume() is off? I dunno, I briefly looked into fixing it but\n> it didn't seem like a quick fix.\n\nGood catch, thanks.\n\nThis is not xdl interface, but simply a miscounting by the user\nof xdl interface.  Here is a fix.\n\n-- >8 --\ndiff: Fix miscounting of --check output\n\nc1795bb (Unify whitespace checking) incorrectly made the\nchecking function return without incrementing the line numbers\nwhen there is no whitespace problem is found on a '+' line.\n\nThis resurrects the earlier behaviour.\n\nNoticed and reported by Jay Soffian.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n diff.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 047310f..90af600 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1021,6 +1021,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)\n \tchar *err;\n \n \tif (line[0] == '+') {\n+\t\tdata->lineno++;\n \t\tdata->status = check_and_emit_line(line + 1, len - 1,\n \t\t    data->ws_rule, NULL, NULL, NULL, NULL);\n \t\tif (!data->status)\n@@ -1031,13 +1032,12 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)\n \t\temit_line(set, reset, line, 1);\n \t\t(void)check_and_emit_line(line + 1, len - 1, data->ws_rule,\n \t\t    stdout, set, reset, ws);\n-\t\tdata->lineno++;\n \t} else if (line[0] == ' ')\n \t\tdata->lineno++;\n \telse if (line[0] == '@') {\n \t\tchar *plus = strchr(line, '+');\n \t\tif (plus)\n-\t\t\tdata->lineno = strtol(plus, NULL, 10);\n+\t\t\tdata->lineno = strtol(plus, NULL, 10) - 1;\n \t\telse\n \t\t\tdie(\"invalid diff\");\n \t}\n"}]}