summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-01-05 23:41:57 -0800
committerJunio C Hamano <gitster@pobox.com>2013-01-05 23:41:57 -0800
commit946a5aee3e896aa12cb9d4d21079c6e299baad81 (patch)
tree86bc33d1262dfec0a36bbca5b0825298189bb710 /pretty.c
parentd2638e1561012e0f5b473ab43ef76c4ff0d12a9f (diff)
parent30825178fb72e3664bd1bda7c02c62e300e2e5ce (diff)
downloadgit-946a5aee3e896aa12cb9d4d21079c6e299baad81.tar.gz
Merge branch 'jc/format-color-auto'
Introduce "log --format=%C(auto,blue)Foo%C(auto,reset)" that does not color its output when writing to a non-terminal. * jc/format-color-auto: log --format: teach %C(auto,black) to respect color config t6006: clean up whitespace
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/pretty.c b/pretty.c
index 91bb2d3ef6..92c839fe64 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;