git.vger.kernel.org archive mirror
 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 3/3] Make "diff --check" use shared whitespace functions
Date: Wed, 12 Dec 2007 17:23:01 +0100	[thread overview]
Message-ID: <1197476582-18956-4-git-send-email-win@wincent.com> (raw)
In-Reply-To: <1197476582-18956-3-git-send-email-win@wincent.com>

Use the logic refactored into ws.c rather than duplicating it.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
---
 diff.c |   49 +++++++++++--------------------------------------
 1 files changed, 11 insertions(+), 38 deletions(-)

diff --git a/diff.c b/diff.c
index c9b3884..7ad3c63 100644
--- a/diff.c
+++ b/diff.c
@@ -996,7 +996,7 @@ struct checkdiff_t {
 	const char *filename;
 	int lineno, color_diff;
 	unsigned ws_rule;
-	int status;
+	unsigned status;
 };
 
 static void checkdiff_consume(void *priv, char *line, unsigned long len)
@@ -1005,45 +1005,18 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
 	const char *ws = diff_get_color(data->color_diff, DIFF_WHITESPACE);
 	const char *reset = diff_get_color(data->color_diff, DIFF_RESET);
 	const char *set = diff_get_color(data->color_diff, DIFF_FILE_NEW);
+	char *err;
 
 	if (line[0] == '+') {
-		int i, spaces = 0, space_before_tab = 0, white_space_at_end = 0;
-
-		/* check space before tab */
-		for (i = 1; i < len; i++) {
-			if (line[i] == ' ')
-				spaces++;
-			else if (line[i] == '\t') {
-				if (spaces) {
-					space_before_tab = 1;
-					break;
-				}
-			}
-			else
-				break;
-		}
-
-		/* check whitespace at line end */
-		if (line[len - 1] == '\n')
-			len--;
-		if (isspace(line[len - 1]))
-			white_space_at_end = 1;
-
-		if (space_before_tab || white_space_at_end) {
-			data->status = 1;
-			printf("%s:%d: %s", data->filename, data->lineno, ws);
-			if (space_before_tab) {
-				printf("space before tab");
-				if (white_space_at_end)
-					putchar(',');
-			}
-			if (white_space_at_end)
-				printf("whitespace at end");
-			printf(":%s ", reset);
-			emit_line_with_ws(1, set, reset, ws, line, len,
-					  data->ws_rule);
-		}
-
+		data->status = check_whitespace(line, len, data->ws_rule);
+		if (!data->status)
+			return;
+		err = whitespace_error_string(data->status);
+		printf("%s:%d: %s%s:%s ", data->filename, data->lineno,
+		    ws, err, reset);
+		free(err);
+		emit_line_with_ws(1, set, reset, ws, line, len,
+		    data->ws_rule);
 		data->lineno++;
 	} else if (line[0] == ' ')
 		data->lineno++;
-- 
1.5.3.7.1159.g2f071-dirty

  reply	other threads:[~2007-12-12 16:25 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 ` [PATCH 1/4] Fix "diff --check" whitespace detection Wincent Colaiuta
2007-12-12 16:23   ` [PATCH 2/4] Extract and improve whitespace check from "git apply" Wincent Colaiuta
2007-12-12 16:23     ` Wincent Colaiuta [this message]
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-4-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 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).