git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Egerer <thomas.egerer@secunet.com>
To: git@vger.kernel.org
Subject: [PATCH] pretty.c: Make user defined format honor color option
Date: Thu, 17 Mar 2011 09:33:05 +0100	[thread overview]
Message-ID: <4D81C741.8060108@secunet.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 295 bytes --]


This patch fixes that the pretty-formats tformat and format ignore
git's color option.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
---
 commit.h   |    1 +
 log-tree.c |    1 +
 pretty.c   |   29 +++++++++++++++++------------
 3 files changed, 19 insertions(+), 12 deletions(-)



[-- Attachment #2: 0001-pretty.c-Make-user-defined-format-honor-color-option.patch --]
[-- Type: text/x-patch, Size: 2480 bytes --]

diff --git a/commit.h b/commit.h
index 659c87c..d23bf99 100644
--- a/commit.h
+++ b/commit.h
@@ -78,6 +78,7 @@ struct pretty_print_context
 	int show_notes;
 	struct reflog_walk_info *reflog_info;
 	const char *output_encoding;
+	unsigned colorize:1;
 };
 
 struct userformat_want {
diff --git a/log-tree.c b/log-tree.c
index b46ed3b..63017d2 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -505,6 +505,7 @@ void show_log(struct rev_info *opt)
 	ctx.abbrev = opt->diffopt.abbrev;
 	ctx.after_subject = extra_headers;
 	ctx.reflog_info = opt->reflog_info;
+	ctx.colorize = (DIFF_OPT_TST(&opt->diffopt, COLOR_DIFF) != 0);
 	pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);
 
 	if (opt->add_signoff)
diff --git a/pretty.c b/pretty.c
index 8549934..3c3467f 100644
--- a/pretty.c
+++ b/pretty.c
@@ -743,7 +743,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
 	struct format_commit_context *c = context;
 	const struct commit *commit = c->commit;
 	const char *msg = c->message;
+	char cbuf[COLOR_MAXLEN];
 	struct commit_list *p;
+	size_t consumed = 0;
+	char *color = NULL;
 	int h1, h2;
 
 	/* these are independent of the commit */
@@ -751,29 +754,31 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
 	case 'C':
 		if (placeholder[1] == '(') {
 			const char *end = strchr(placeholder + 2, ')');
-			char color[COLOR_MAXLEN];
 			if (!end)
 				return 0;
 			color_parse_mem(placeholder + 2,
 					end - (placeholder + 2),
-					"--pretty format", color);
-			strbuf_addstr(sb, color);
-			return end - placeholder + 1;
+					"--pretty format", cbuf);
+			consumed = end - placeholder + 1;
+			color = cbuf;
 		}
 		if (!prefixcmp(placeholder + 1, "red")) {
-			strbuf_addstr(sb, GIT_COLOR_RED);
-			return 4;
+			color = GIT_COLOR_RED;
+			consumed = 4;
 		} else if (!prefixcmp(placeholder + 1, "green")) {
-			strbuf_addstr(sb, GIT_COLOR_GREEN);
-			return 6;
+			color = GIT_COLOR_GREEN;
+			consumed = 6;
 		} else if (!prefixcmp(placeholder + 1, "blue")) {
-			strbuf_addstr(sb, GIT_COLOR_BLUE);
-			return 5;
+			color = GIT_COLOR_BLUE;
+			consumed = 5;
 		} else if (!prefixcmp(placeholder + 1, "reset")) {
-			strbuf_addstr(sb, GIT_COLOR_RESET);
-			return 6;
+			color = GIT_COLOR_RESET;
+			consumed = 6;
 		} else
 			return 0;
+		if (color && (c->pretty_ctx->colorize == 1))
+			strbuf_addstr(sb, color);
+		return consumed;
 	case 'n':		/* newline */
 		strbuf_addch(sb, '\n');
 		return 1;


             reply	other threads:[~2011-03-17  8:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-17  8:33 Thomas Egerer [this message]
2011-03-17  9:39 ` [PATCH] pretty.c: Make user defined format honor color option Will Palmer
2011-03-17 12:02   ` Thomas Egerer
2011-03-17 12:59     ` Will Palmer
2011-03-17 19:49       ` Jeff King
2011-03-17 13:46   ` Thomas Egerer

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=4D81C741.8060108@secunet.com \
    --to=thomas.egerer@secunet.com \
    --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).