All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wincent Colaiuta <win@wincent.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Wincent Colaiuta <win@wincent.com>
Subject: [PATCH 1/4] Fix "diff --check" whitespace detection
Date: Wed, 12 Dec 2007 17:22:59 +0100	[thread overview]
Message-ID: <1197476582-18956-2-git-send-email-win@wincent.com> (raw)
In-Reply-To: <1197476582-18956-1-git-send-email-win@wincent.com>

"diff --check" would only detect spaces before tabs if a tab was the
last character in the leading indent. Fix that and add a test case to
make sure the bug doesn't regress in the future.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
---

Although this patch is made to apply on top of the topic I posted
earlier, it can be applied to master with a couple of tweaks. Let
me know if you want me to send such a patch.

In any case, [2/4] and [3/4] factor away the code that had the bug
in it anyway...

 diff.c                     |   13 ++++++++++---
 t/t4015-diff-whitespace.sh |    8 ++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index e89c7ce..c9b3884 100644
--- a/diff.c
+++ b/diff.c
@@ -1010,11 +1010,18 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
 		int i, spaces = 0, space_before_tab = 0, white_space_at_end = 0;
 
 		/* check space before tab */
-		for (i = 1; i < len && (line[i] == ' ' || line[i] == '\t'); i++)
+		for (i = 1; i < len; i++) {
 			if (line[i] == ' ')
 				spaces++;
-		if (line[i - 1] == '\t' && spaces)
-			space_before_tab = 1;
+			else if (line[i] == '\t') {
+				if (spaces) {
+					space_before_tab = 1;
+					break;
+				}
+			}
+			else
+				break;
+		}
 
 		/* check whitespace at line end */
 		if (line[len - 1] == '\n')
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 5aaf2db..ff77a16 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -248,4 +248,12 @@ test_expect_failure 'check with space before tab in indent (diff-tree)' '
 
 '
 
+# was a bug: space before tab only caught if tab was last in the indent
+test_expect_failure 'check mixed spaces and tabs in indent' '
+
+	echo " 	 foo();" > x &&
+	git diff --check
+
+'
+
 test_done
-- 
1.5.3.7.1159.g2f071-dirty

  reply	other threads:[~2007-12-12 16:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-12 16:22 [PATCH 0/4] Refactoring for apply and diff Wincent Colaiuta
2007-12-12 16:22 ` Wincent Colaiuta [this message]
2007-12-12 16:23   ` [PATCH 2/4] Extract and improve whitespace check from "git apply" Wincent Colaiuta
2007-12-12 16:23     ` [PATCH 3/3] Make "diff --check" use shared whitespace functions Wincent Colaiuta
2007-12-12 16:23       ` [PATCH 4/4] Add tests for "git diff --check" with core.whitespace options Wincent Colaiuta
2007-12-12 19:39     ` [PATCH 2/4] Extract and improve whitespace check from "git apply" Junio C Hamano
2007-12-12 22:50       ` Wincent Colaiuta

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=1197476582-18956-2-git-send-email-win@wincent.com \
    --to=win@wincent.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.