summaryrefslogtreecommitdiff
path: root/ws.c
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2010-10-20 15:17:26 -0700
committerJunio C Hamano <gitster@pobox.com>2010-10-20 16:10:15 -0700
commitcfd1a9849cdb4b9c7fcd0cb71a28cbdbc3494329 (patch)
tree7db093285bb283c71812edad1e49942e5b996c03 /ws.c
parenta471833d51b0902d68f9190157bf1421d19a951a (diff)
downloadgit-cfd1a9849cdb4b9c7fcd0cb71a28cbdbc3494329.tar.gz
diff: handle lines containing only whitespace and tabs better
When a line contains nothing but whitespace with at least one tab 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ws.c')
-rw-r--r--ws.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ws.c b/ws.c
index d7b8c33f14..7302f8f5a2 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) {