Re: FW: Git log --graph doesn't output color when redirected
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:55:31
Jeff King [off-list ref] writes:
On Sat, Dec 15, 2012 at 10:23:10AM +0700, Nguyen Thai Ngoc Duy wrote:quoted
On Thu, Dec 13, 2012 at 8:13 PM, Jeff King [off-list ref] wrote:quoted
If you are using --format="%C(red)" or similar placeholders, they are the odd duck by not respecting the auto-color mode.But they should, shouldn't they? Just asking. I may do it to when I revive nd/pretty-placeholder-with-color-option.If I were designing --format today, I would certainly say so. The only thing holding me back would be backwards compatibility. We could get around that by introducing a new placeholder like %c(color) that behaves like %C(color), except respects the --color flag.
I think the %c(color) thing is a good way to go if we want to pursue this. Another possibility without wasting one more special letter would be to allow %C(auto,red), perhaps like this (untested): pretty.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git i/pretty.c w/pretty.c
index dba6828..77cf826 100644
--- i/pretty.c
+++ w/pretty.c@@ -960,12 +960,19 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, switch (placeholder[0]) { case 'C': if (placeholder[1] == '(') { - const char *end = strchr(placeholder + 2, ')'); + const char *begin = placeholder + 2; + const char *end = strchr(begin, ')'); char color[COLOR_MAXLEN]; + if (!end) return 0; - color_parse_mem(placeholder + 2, - end - (placeholder + 2), + if (!memcmp(begin, "auto,", 5)) { + if (!want_color(GIT_COLOR_AUTO)) + return 0; + begin += 5; + } + color_parse_mem(begin, + end - begin, "--pretty format", color); strbuf_addstr(sb, color); return end - placeholder + 1;