@matheusbsbs / matheus-bagliano / commits / 459fa6d0fe
Fork 0

git-diff: complain about >=8 consecutive spaces in initial indent

This introduces a new whitespace error type, "indent-with-non-tab". The error is about starting a line with 8 or more SP, instead of indenting it with a HT. This is not enabled by default, as some projects employ an indenting policy to use only SPs and no HTs. The kernel folks and git contributors may want to enable this detection with: [core] whitespace = indent-with-non-tab Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 2, 2007 at 18:00 UTC 459fa6d0fe6a45b8b120463b56a68e943e3a8101
3 files changed +14 -2
cache.h
+1
@@ -608,6 +608,7 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i
608 */
609 #define WS_TRAILING_SPACE 01
610 #define WS_SPACE_BEFORE_TAB 02
611 +#define WS_INDENT_WITH_NON_TAB 04
612 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB)
613 extern unsigned whitespace_rule;
614
config.c
+1
@@ -252,6 +252,7 @@ static struct whitespace_rule {
252 } whitespace_rule_names[] = {
253 { "trailing-space", WS_TRAILING_SPACE },
254 { "space-before-tab", WS_SPACE_BEFORE_TAB },
255 + { "indent-with-non-tab", WS_INDENT_WITH_NON_TAB },
256 };
257
258 static unsigned parse_whitespace_rule(const char *string)
diff.c
+12 -2
@@ -502,8 +502,11 @@ static void emit_line_with_ws(int nparents,
502 int i;
503 int tail = len;
504 int need_highlight_leading_space = 0;
505 - /* The line is a newly added line. Does it have funny leading
506 - * whitespaces? In indent, SP should never precede a TAB.
505 + /*
506 + * The line is a newly added line. Does it have funny leading
507 + * whitespaces? In indent, SP should never precede a TAB. In
508 + * addition, under "indent with non tab" rule, there should not
509 + * be more than 8 consecutive spaces.
510 */
511 for (i = col0; i < len; i++) {
512 if (line[i] == '\t') {
@@ -517,6 +520,13 @@ static void emit_line_with_ws(int nparents,
520 else
521 break;
522 }
523 + if ((whitespace_rule & WS_INDENT_WITH_NON_TAB) &&
524 + 0 <= last_space_in_indent &&
525 + last_tab_in_indent < 0 &&
526 + 8 <= (i - col0)) {
527 + last_tab_in_indent = i;
528 + need_highlight_leading_space = 1;
529 + }
530 fputs(set, stdout);
531 fwrite(line, col0, 1, stdout);
532 fputs(reset, stdout);