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

[PATCH] diff: handle lines containing only whitespace better

From
Kevin Ballard <kevin@sb.org>
Date
Oct 20, 2010, 04:46 UTC
Message-ID
<1287549978-54280-1-git-send-email-kevin@sb.org>

When a line contains nothing but whitespace and the core.whitespace config option contains blank-at-eol, the whitespace on the line is being printed twice, once unhighlighted (unless otherwise matched by one of the other core.whitespace values), and a second time highlighted for blank-at-eol.

Update the leading indentation check to stop checking when it reaches the trailing whitespace.

Signed-off-by: Kevin Ballard <kevin@sb.org>
---
 ws.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/ws.c b/ws.c
index d7b8c33..7302f8f 100644
--- a/ws.c
+++ b/ws.c
@@ -174,8 +174,11 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
 		}
 	}
 
+	if (trailing_whitespace == -1)
+		trailing_whitespace = len;
+
 	/* Check indentation */
-	for (i = 0; i < len; i++) {
+	for (i = 0; i < trailing_whitespace; i++) {
 		if (line[i] == ' ')
 			continue;
 		if (line[i] != '\t')
@@ -218,8 +221,6 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
 		 * Now the rest of the line starts at "written".
 		 * The non-highlighted part ends at "trailing_whitespace".
 		 */
-		if (trailing_whitespace == -1)
-			trailing_whitespace = len;
 
 		/* Emit non-highlighted (middle) segment. */
 		if (trailing_whitespace - written > 0) {
-- 
1.7.3.1.211.g81fee.dirty
Next: Junio C Hamano
Message 1 of 9 in “diff: handle lines containing only whitespace better”
  1. diff: handle lines containing only whitespace betterKevin Ballard, Oct 20, 2010
  2. Junio C HamanoOct 20, 2010
  3. Kevin BallardOct 20, 2010
  4. Nazri RamliyOct 20, 2010
  5. Junio C HamanoOct 20, 2010
  6. 1/2 test-lib: extend test_decode_color to handle more color codesKevin Ballard, Oct 20, 2010
  7. Junio C HamanoOct 20, 2010
  8. Kevin BallardOct 21, 2010
  9. 2/2 diff: handle lines containing only whitespace and tabs betterKevin Ballard, Oct 20, 2010

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.