Re: [PATCH v4 16/21] range-diff --dual-color: fix bogus white-space warning
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 23, 2018, 22:39 UTC
- Message-ID
- <xmqqtvop37c1.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <f4252f2b2198cf13d5b0a21c54098e2a1d8158dd.1532210683.git.gitgitgadget@gmail.com>
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 15 quoted lines
> @@ -177,8 +178,16 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
> if (trailing_whitespace == -1)
> trailing_whitespace = len;
>
> + if ((ws_rule & WS_IGNORE_FIRST_SPACE) && len && line[0] == ' ') {
> + if (stream)
> + fwrite(line, 1, 1, stream);
> + written++;
> + if (!trailing_whitespace)
> + trailing_whitespace++;
> + }
> +
> /* Check indentation */
> - for (i = 0; i < trailing_whitespace; i++) {
> + for (i = written; i < trailing_whitespace; i++) {It is pleasing to see that with a surprisingly clean and small change like this we can exempt the initial space byte from SP-before-HT check and from Indent-with-non-tab at the same time.
Very nice.
One reason why a surprisingly small special case is required is perhaps because we are blessed with the original code being clean [*1*], and the fact that a line[0] that is not ' ' will not trigger any indentation related whitespace errors without this special case, I guess.
> if (line[i] == ' ') > continue; > if (line[i] != '\t')
[Footnote]
*1* ws.c used to be almost all my code long time ago, but most of
the shape of the current whitespace_error checking code comes from
c1795bb08aa which is not mine, and I can say good things about it
without feeling embarrassingly boasty ;-)