aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-10-02 18:00:27 -0700
committerJunio C Hamano <gitster@pobox.com>2007-11-02 17:58:09 -0700
commit459fa6d0fe6a45b8b120463b56a68e943e3a8101 (patch)
tree0ff76965a659fb45c0ec917ffffee0418796fd25
parenta9cc857ada7c57069ff00eed8d0addcf55849f39 (diff)
downloadgit-459fa6d0fe6a45b8b120463b56a68e943e3a8101.tar.gz
git-459fa6d0fe6a45b8b120463b56a68e943e3a8101.tar.xz
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>
-rw-r--r--cache.h1
-rw-r--r--config.c1
-rw-r--r--diff.c14
3 files changed, 14 insertions, 2 deletions
diff --git a/cache.h b/cache.h
index a6e5988f0..3f4282795 100644
--- a/cache.h
+++ b/cache.h
@@ -608,6 +608,7 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i
*/
#define WS_TRAILING_SPACE 01
#define WS_SPACE_BEFORE_TAB 02
+#define WS_INDENT_WITH_NON_TAB 04
#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB)
extern unsigned whitespace_rule;
diff --git a/config.c b/config.c
index ffb418ccf..d5b976696 100644
--- a/config.c
+++ b/config.c
@@ -252,6 +252,7 @@ static struct whitespace_rule {
} whitespace_rule_names[] = {
{ "trailing-space", WS_TRAILING_SPACE },
{ "space-before-tab", WS_SPACE_BEFORE_TAB },
+ { "indent-with-non-tab", WS_INDENT_WITH_NON_TAB },
};
static unsigned parse_whitespace_rule(const char *string)
diff --git a/diff.c b/diff.c
index 211235376..6bb902f4a 100644
--- a/diff.c
+++ b/diff.c
@@ -502,8 +502,11 @@ static void emit_line_with_ws(int nparents,
int i;
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.
+ /*
+ * The line is a newly added line. Does it have funny leading
+ * whitespaces? In indent, SP should never precede a TAB. In
+ * addition, under "indent with non tab" rule, there should not
+ * be more than 8 consecutive spaces.
*/
for (i = col0; i < len; i++) {
if (line[i] == '\t') {
@@ -517,6 +520,13 @@ static void emit_line_with_ws(int nparents,
else
break;
}
+ if ((whitespace_rule & WS_INDENT_WITH_NON_TAB) &&
+ 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);