Thread (1 message) 1 message, 1 author, 2018-07-23

Re: [PATCH v4 16/21] range-diff --dual-color: fix bogus white-space warning

From: Junio C Hamano <hidden>
Date: 2018-07-23 22:39:32

"Johannes Schindelin via GitGitGadget" [off-list ref]
writes:
quoted hunk
@@ -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 ;-)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help