[PATCH 2/2] git-diff: Respect core.whitespace.{space-indent,space-before-tab,trailing}.
Signed-off-by: David Symonds <dsymonds@gmail.com>
---
diff.c | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/diff.c b/diff.c
index a6aaaf7..aa86fa1 100644
--- a/diff.c
+++ b/diff.c
@@ -503,12 +503,15 @@ static void emit_line_with_ws(int nparents,
int tail = len;
int need_highlight_leading_space = 0;
/* The line is a newly added line. Does it have funny leading
- * whitespaces? In indent, SP should never precede a TAB.
+ * whitespaces? In indent, SP should never precede a TAB. In
+ * addition, under "indent with non tab" rule, there should not
+ * be 8 or more consecutive spaces.
*/
for (i = col0; i < len; i++) {
if (line[i] == '\t') {
last_tab_in_indent = i;
- if (0 <= last_space_in_indent)
+ if ((ws_mode_space_before_tab != WS_OKAY) &&
+ (0 <= last_space_in_indent))
need_highlight_leading_space = 1;
}
else if (line[i] == ' ')
@@ -516,6 +519,13 @@ static void emit_line_with_ws(int nparents,
else
break;
}
+ if ((ws_mode_space_indent != WS_OKAY) &&
+ (0 <= last_space_in_indent) &&
+ (last_tab_in_indent < 0) &&
+ (8 <= (i - col0))) {
+ last_tab_in_indent = i;
+ need_highlight_leading_space = 1;
+ }
fputs(set, stdout);
fwrite(line, col0, 1, stdout);
fputs(reset, stdout);
@@ -540,10 +550,12 @@ static void emit_line_with_ws(int nparents,
tail = len - 1;
if (line[tail] == '\n' && i < tail)
tail--;
- while (i < tail) {
- if (!isspace(line[tail]))
- break;
- tail--;
+ if (ws_mode_trailing != WS_OKAY) {
+ while (i < tail) {
+ if (!isspace(line[tail]))
+ break;
+ tail--;
+ }
}
if ((i < tail && line[tail + 1] != '\n')) {
/* This has whitespace between tail+1..len */
--
1.5.3.1