git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Brian Downing <bdowning@lavos.net>
Subject: [PATCH 2/2] git-diff: complain about >=8 consecutive spaces in initial indent
Date: Fri, 02 Nov 2007 00:38:03 -0700	[thread overview]
Message-ID: <7vr6j95c84.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vwst15ceq.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Fri, 02 Nov 2007 00:34:05 -0700")

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>
---

 * Obviously, it is too late at night for me to do the same for
   git-apply, but it's Ok as I know there are capable interested
   parties on the list.  Hint, hint...

 cache.h  |    1 +
 config.c |    1 +
 diff.c   |   14 ++++++++++++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/cache.h b/cache.h
index a6e5988..3f42827 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 ffb418c..d5b9766 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 2112353..6bb902f 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);
-- 
1.5.3.5.1452.ga93d

  reply	other threads:[~2007-11-02  7:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-02  7:34 [PATCH 1/2] War on whitespace: first, a bit of retreat Junio C Hamano
2007-11-02  7:38 ` Junio C Hamano [this message]
2007-11-13 23:37   ` [PATCH 2/2] git-diff: complain about >=8 consecutive spaces in initial indent Josh Triplett
2007-11-14  0:46     ` Junio C Hamano
2007-11-02 10:14 ` [PATCH 1/2] War on whitespace: first, a bit of retreat David Symonds
2007-11-02 10:45   ` Andreas Ericsson
2007-11-02 11:50     ` David Symonds
2007-11-02 12:25       ` Jakub Narebski
2007-11-02 12:53         ` David Symonds
2007-11-02 13:26           ` David Symonds
2007-11-02 17:45 ` J. Bruce Fields
2007-11-03  2:45   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vr6j95c84.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=bdowning@lavos.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).