Re: [PATCH 2/2] expand --pretty=format color options

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jeff King
Date: Sunday, January 18, 2009 - 12:43 pm

On Sun, Jan 18, 2009 at 12:37:53PM -0500, Jeff King wrote:


Here is a patch that seems to work. It predicates pretty format colors
on diff colors, which is the same way the yellow commit header works in
log-tree. I don't know if it makes more sense to introduce yet another
color config option.

And I say "seems to work" because I remember there being some trickery
with color flags sometimes not getting set properly. However, since this
is the same flag as the yellow commit header, and called around the same
time, I think it should be fine.

One final note: if you are writing "generic" format strings, you
probably don't want to say "yellow". You want to say "whatever the user
has configured for color.diff.commit". I don't know if %C should be
overloaded for that or not (i.e., %C(commit) would be a valid color).

-- >8 --
respect color settings for --pretty=format colors

Previously, we would unconditionally print any colors the
user put into the --pretty=format specifier, regardless of
the setting of color configuration. This is not a problem if
the user writes a custom string each time git-log is
invoked. However, it makes use in scripts unnecessarily
complex, since they would have to change the format string
based on user preferences (and whether output is going to a
tty).

This patch will ignore any colors in --pretty=format if diff
colors are not turned on (they will still be parsed and
treated as placeholders, but no color will be output). This
matches the color.diff.commit colorization, which depends on
diff coloring even though it is not technically part of a
diff.
---
 pretty.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/pretty.c b/pretty.c
index b1b8620..fe606c5 100644
--- a/pretty.c
+++ b/pretty.c
@@ -563,20 +563,25 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 			color_parse_mem(placeholder + 2,
 					end - (placeholder + 2),
 					"--pretty format", color);
-			strbuf_addstr(sb, color);
+			if (diff_use_color_default)
+				strbuf_addstr(sb, color);
 			return end - placeholder + 1;
 		}
 		if (!prefixcmp(placeholder + 1, "red")) {
-			strbuf_addstr(sb, "\033[31m");
+			if (diff_use_color_default)
+				strbuf_addstr(sb, "\033[31m");
 			return 4;
 		} else if (!prefixcmp(placeholder + 1, "green")) {
-			strbuf_addstr(sb, "\033[32m");
+			if (diff_use_color_default)
+				strbuf_addstr(sb, "\033[32m");
 			return 6;
 		} else if (!prefixcmp(placeholder + 1, "blue")) {
-			strbuf_addstr(sb, "\033[34m");
+			if (diff_use_color_default)
+				strbuf_addstr(sb, "\033[34m");
 			return 5;
 		} else if (!prefixcmp(placeholder + 1, "reset")) {
-			strbuf_addstr(sb, "\033[m");
+			if (diff_use_color_default)
+				strbuf_addstr(sb, "\033[m");
 			return 6;
 		} else
 			return 0;
-- 
1.6.1.151.g5a7da.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 3/3] Adds a #!bash to the top of bash completio ..., Markus Heidelberg, (Sat Jan 17, 5:37 am)
[PATCH 2/2] expand --pretty=format color options, Jeff King, (Sat Jan 17, 8:38 am)
Cyellow, was Re: [a way-too-long line], Johannes Schindelin, (Sat Jan 17, 8:39 am)
Re: Cyellow, was Re: [a way-too-long line], Jeff King, (Sat Jan 17, 8:40 am)
Re: Cyellow, was Re: [a way-too-long line], Johannes Schindelin, (Sat Jan 17, 8:46 am)
Re: [PATCH 2/2] expand --pretty=format color options, René Scharfe, (Sun Jan 18, 10:13 am)
Re: [PATCH 2/2] expand --pretty=format color options, Jeff King, (Sun Jan 18, 10:37 am)
Re: [PATCH 2/2] expand --pretty=format color options, Jeff King, (Sun Jan 18, 12:43 pm)
Re: [PATCH 2/2] expand --pretty=format color options, Jeff King, (Sun Jan 18, 12:53 pm)
[PATCH 1/2] handle color.ui at a central place, Markus Heidelberg, (Sun Jan 18, 1:37 pm)
[PATCH 2/2] move the color variables to color.c, Markus Heidelberg, (Sun Jan 18, 1:39 pm)
Re: [PATCH 2/2] expand --pretty=format color options, Junio C Hamano, (Mon Jan 19, 4:10 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Jeff King, (Mon Jan 19, 9:04 pm)
Re: [PATCH 2/2] expand --pretty=format color options, Johannes Schindelin, (Tue Jan 20, 3:27 am)
Re: [PATCH 2/2] expand --pretty=format color options, Johannes Schindelin, (Tue Jan 20, 3:36 am)
Re: [PATCH 2/2] expand --pretty=format color options, Johannes Schindelin, (Tue Jan 20, 7:58 am)
Re: [PATCH 2/2] expand --pretty=format color options, Jeff King, (Tue Jan 20, 12:21 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Markus Heidelberg, (Wed Jan 21, 3:35 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Jeff King, (Wed Jan 21, 5:00 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Markus Heidelberg, (Wed Jan 21, 5:13 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Junio C Hamano, (Thu Jan 22, 11:13 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Markus Heidelberg, (Sat Jan 24, 4:28 am)
Re: [PATCH 1/2] handle color.ui at a central place, Johannes Schindelin, (Sat Jan 24, 7:14 am)
Re: [PATCH 1/2] handle color.ui at a central place, Markus Heidelberg, (Sat Jan 24, 7:23 am)
Re: [PATCH 1/2] handle color.ui at a central place, Junio C Hamano, (Sat Jan 24, 11:36 am)
Re: [PATCH 1/2] handle color.ui at a central place, Jeff King, (Sat Jan 24, 12:17 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Junio C Hamano, (Sat Jan 24, 1:26 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Jeff King, (Sat Jan 24, 1:45 pm)
Re: [PATCH 1/2] handle color.ui at a central place, Markus Heidelberg, (Sun Jan 25, 7:15 am)