From 30825178fb72e3664bd1bda7c02c62e300e2e5ce Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Dec 2012 17:56:49 -0500 Subject: log --format: teach %C(auto,black) to respect color config Traditionally, %C(color attr) always emitted the ANSI color sequence; it was up to the scripts that wanted to conditionally color their output to omit %C(...) specifier when they do not want colors. Optionally allow "auto," to be prefixed to the color, so that the output is colored iff we would color regular "log" output (e.g., taking into account color.* and --color command line options). Tests and pretty_context bits by Jeff King . Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- pretty.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index dba682828..63350af61 100644 --- a/pretty.c +++ b/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(c->pretty_ctx->color)) + return end - placeholder + 1; + begin += 5; + } + color_parse_mem(begin, + end - begin, "--pretty format", color); strbuf_addstr(sb, color); return end - placeholder + 1; -- cgit v1.2.1