git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Holtje <docwhat@gmail.com>
Cc: Alex Riesen <raa.lkml@gmail.com>, git@vger.kernel.org
Subject: [PATCH 3/5] checkdiff: pass diff_options to the callback
Date: Thu, 26 Jun 2008 15:36:34 -0700	[thread overview]
Message-ID: <7v63rvq0wd.fsf_-_@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vk5gbq10p.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Thu, 26 Jun 2008 15:33:58 -0700")

We could later use more information from the diff_options.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/diff.c b/diff.c
index 52a34ee..6bcbe20 100644
--- a/diff.c
+++ b/diff.c
@@ -1136,18 +1136,19 @@ static void free_diffstat_info(struct diffstat_t *diffstat)
 struct checkdiff_t {
 	struct xdiff_emit_state xm;
 	const char *filename;
-	int lineno, color_diff;
+	int lineno;
+	struct diff_options *o;
 	unsigned ws_rule;
 	unsigned status;
-	FILE *file;
 };
 
 static void checkdiff_consume(void *priv, char *line, unsigned long len)
 {
 	struct checkdiff_t *data = priv;
-	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);
+	int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF);
+	const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE);
+	const char *reset = diff_get_color(color_diff, DIFF_RESET);
+	const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
 	char *err;
 
 	if (line[0] == '+') {
@@ -1158,11 +1159,12 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
 			return;
 		data->status |= bad;
 		err = whitespace_error_string(bad);
-		fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
+		fprintf(data->o->file, "%s:%d: %s.\n",
+			data->filename, data->lineno, err);
 		free(err);
-		emit_line(data->file, set, reset, line, 1);
+		emit_line(data->o->file, set, reset, line, 1);
 		ws_check_emit(line + 1, len - 1, data->ws_rule,
-			      data->file, set, reset, ws);
+			      data->o->file, set, reset, ws);
 	} else if (line[0] == ' ')
 		data->lineno++;
 	else if (line[0] == '@') {
@@ -1557,9 +1559,8 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
 	data.xm.consume = checkdiff_consume;
 	data.filename = name_b ? name_b : name_a;
 	data.lineno = 0;
-	data.color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
+	data.o = o;
 	data.ws_rule = whitespace_rule(attr_path);
-	data.file = o->file;
 
 	if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
 		die("unable to read files to diff");
-- 
1.5.6.1.78.gde8d9

  parent reply	other threads:[~2008-06-26 22:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-24 19:21 [PATCH v2] pre-commit hook should ignore carriage returns at EOL Christian Holtje
2008-06-25 18:14 ` Alex Riesen
2008-06-25 18:47   ` Christian Holtje
2008-06-25 19:14     ` Junio C Hamano
2008-06-26  2:41       ` Christian Holtje
2008-06-26 22:33         ` Junio C Hamano
2008-06-26 22:34           ` [PATCH 1/5] diff --check: explain why we do not care whether old side is binary Junio C Hamano
2008-06-26 22:35           ` [PATCH 2/5] check_and_emit_line(): rename and refactor Junio C Hamano
2008-06-26 22:36           ` Junio C Hamano [this message]
2008-06-26 22:36           ` [PATCH 4/5] Teach "diff --check" about a new blank lines at end Junio C Hamano
2008-06-26 22:37           ` [PATCH 5/5] diff --check: detect leftover conflict markers Junio C Hamano
2008-06-26 23:01           ` [PATCH v2] pre-commit hook should ignore carriage returns at EOL Junio C Hamano
2008-06-26 23:06             ` Junio C Hamano
2008-06-27  4:24               ` Jeff King

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=7v63rvq0wd.fsf_-_@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=docwhat@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=raa.lkml@gmail.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).