{"thread":{"id":"26760","subject":"[PATCH] pretty.c: Make user defined format honor color option","startedAt":"2011-03-17T08:33:05Z","lastAt":"2011-03-17T19:49:53Z","messageCount":6,"participants":["Thomas Egerer","Will Palmer","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"163542","messageId":"4D81C741.8060108@secunet.com","threadId":"26760","inReplyTo":null,"subject":"[PATCH] pretty.c: Make user defined format honor color option","fromName":"Thomas Egerer","fromEmail":"thomas.egerer@secunet.com","sentAt":"2011-03-17T08:33:05Z","receivedAt":"2011-03-17T08:33:05Z","isPatch":true,"sender":{"key":"thomas.egerer@secunet.com","avatar":null},"body":"\nThis patch fixes that the pretty-formats tformat and format ignore\ngit's color option.\n\nSigned-off-by: Thomas Egerer <thomas.egerer@secunet.com>\n---\n commit.h   |    1 +\n log-tree.c |    1 +\n pretty.c   |   29 +++++++++++++++++------------\n 3 files changed, 19 insertions(+), 12 deletions(-)\n\n\n\n\ndiff --git a/commit.h b/commit.h\nindex 659c87c..d23bf99 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -78,6 +78,7 @@ struct pretty_print_context\n \tint show_notes;\n \tstruct reflog_walk_info *reflog_info;\n \tconst char *output_encoding;\n+\tunsigned colorize:1;\n };\n \n struct userformat_want {\ndiff --git a/log-tree.c b/log-tree.c\nindex b46ed3b..63017d2 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -505,6 +505,7 @@ void show_log(struct rev_info *opt)\n \tctx.abbrev = opt->diffopt.abbrev;\n \tctx.after_subject = extra_headers;\n \tctx.reflog_info = opt->reflog_info;\n+\tctx.colorize = (DIFF_OPT_TST(&opt->diffopt, COLOR_DIFF) != 0);\n \tpretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);\n \n \tif (opt->add_signoff)\ndiff --git a/pretty.c b/pretty.c\nindex 8549934..3c3467f 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -743,7 +743,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \tstruct format_commit_context *c = context;\n \tconst struct commit *commit = c->commit;\n \tconst char *msg = c->message;\n+\tchar cbuf[COLOR_MAXLEN];\n \tstruct commit_list *p;\n+\tsize_t consumed = 0;\n+\tchar *color = NULL;\n \tint h1, h2;\n \n \t/* these are independent of the commit */\n@@ -751,29 +754,31 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \tcase 'C':\n \t\tif (placeholder[1] == '(') {\n \t\t\tconst char *end = strchr(placeholder + 2, ')');\n-\t\t\tchar color[COLOR_MAXLEN];\n \t\t\tif (!end)\n \t\t\t\treturn 0;\n \t\t\tcolor_parse_mem(placeholder + 2,\n \t\t\t\t\tend - (placeholder + 2),\n-\t\t\t\t\t\"--pretty format\", color);\n-\t\t\tstrbuf_addstr(sb, color);\n-\t\t\treturn end - placeholder + 1;\n+\t\t\t\t\t\"--pretty format\", cbuf);\n+\t\t\tconsumed = end - placeholder + 1;\n+\t\t\tcolor = cbuf;\n \t\t}\n \t\tif (!prefixcmp(placeholder + 1, \"red\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RED);\n-\t\t\treturn 4;\n+\t\t\tcolor = GIT_COLOR_RED;\n+\t\t\tconsumed = 4;\n \t\t} else if (!prefixcmp(placeholder + 1, \"green\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_GREEN);\n-\t\t\treturn 6;\n+\t\t\tcolor = GIT_COLOR_GREEN;\n+\t\t\tconsumed = 6;\n \t\t} else if (!prefixcmp(placeholder + 1, \"blue\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_BLUE);\n-\t\t\treturn 5;\n+\t\t\tcolor = GIT_COLOR_BLUE;\n+\t\t\tconsumed = 5;\n \t\t} else if (!prefixcmp(placeholder + 1, \"reset\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n-\t\t\treturn 6;\n+\t\t\tcolor = GIT_COLOR_RESET;\n+\t\t\tconsumed = 6;\n \t\t} else\n \t\t\treturn 0;\n+\t\tif (color && (c->pretty_ctx->colorize == 1))\n+\t\t\tstrbuf_addstr(sb, color);\n+\t\treturn consumed;\n \tcase 'n':\t\t/* newline */\n \t\tstrbuf_addch(sb, '\\n');\n \t\treturn 1;\n\n"},{"id":"163544","messageId":"1300354791.3269.19.camel@wpalmer.simply-domain","threadId":"26760","inReplyTo":"4D81C741.8060108@secunet.com","subject":"Re: [PATCH] pretty.c: Make user defined format honor color option","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2011-03-17T09:39:51Z","receivedAt":"2011-03-17T09:39:51Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Thu, 2011-03-17 at 09:33 +0100, Thomas Egerer wrote:\n> This patch fixes that the pretty-formats tformat and format ignore\n> git's color option.\n\nIt is my understanding that this is intentional, the logic being: If you\nnormally don't want color, but have specified it directly on the\ncommand-line, you probably want color.\n\nIt is arguable that this logic does not hold for format aliases, of\ncourse. (and personally I've never agreed with the above logic anyway)\n\niirc, there are a couple of other places beyond log-tree.c which need to\npropagate COLOR_DIFF into the pretty context if you want to respect the\ncolour option in user-specified formats. Skimming my own diffs:\nrev-list.c and shortlog.c\n\nOf course, explicitly propagating \"diff_opts\" settings like this just\nshows off how poorly named these things are if we're going to use them\nfor this sort of thing. That's probably a place for another patch,\nthough.\n\nI've got a patch to add support for conditional formats, including such\nthings as: %(opt-color: %Cred%h%Creset, %h). I'm currently in the\nprocess of re-rolling just the \"long options\" part of that into\nsomething more-manageable, but honestly that's the bulk of the change,\nso if that gets accepted then adding %(opt-color...) would be pretty\ntrivial.\n\n--Will\n"},{"id":"163557","messageId":"4D81F860.2070703@secunet.com","threadId":"26760","inReplyTo":"1300354791.3269.19.camel@wpalmer.simply-domain","subject":"Re: [PATCH] pretty.c: Make user defined format honor color option","fromName":"Thomas Egerer","fromEmail":"thomas.egerer@secunet.com","sentAt":"2011-03-17T12:02:40Z","receivedAt":"2011-03-17T12:02:40Z","isPatch":true,"sender":{"key":"thomas.egerer@secunet.com","avatar":null},"body":"On 03/17/2011 10:39 AM, Will Palmer schrobtete:\n> On Thu, 2011-03-17 at 09:33 +0100, Thomas Egerer wrote:\n>> This patch fixes that the pretty-formats tformat and format ignore\n>> git's color option.\n> \n> It is my understanding that this is intentional, the logic being: If you\n> normally don't want color, but have specified it directly on the\n> command-line, you probably want color.\nI'm using the pretty format in the context of an alias. My global setting\nfor colors is auto. I would expect git to not disregard this options. I\nusually use the alias to display a git log in a modified way, but I also\ndo sometimes pipe it to grep. If there was a way to suppress output\ncolorization (let's say by not using global options but the command line\nswitch --color=never) that would work for me. But there is no wa and I\nfind it inconvinient to have two different aliases doing the same thing\none with color and one without while there would be a much simpler way.\n\n> iirc, there are a couple of other places beyond log-tree.c which need to\n> propagate COLOR_DIFF into the pretty context if you want to respect the\n> colour option in user-specified formats. Skimming my own diffs:\n> rev-list.c and shortlog.c\nYou're right. If there's a chance to bring this upstream, I would include\nit in a revised versoin of my patch.\n\nThomas\n"},{"id":"163558","messageId":"1300366792.3269.24.camel@wpalmer.simply-domain","threadId":"26760","inReplyTo":"4D81F860.2070703@secunet.com","subject":"Re: [PATCH] pretty.c: Make user defined format honor color option","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2011-03-17T12:59:52Z","receivedAt":"2011-03-17T12:59:52Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Thu, 2011-03-17 at 13:02 +0100, Thomas Egerer wrote:\n> On 03/17/2011 10:39 AM, Will Palmer schrobtete:\n> > On Thu, 2011-03-17 at 09:33 +0100, Thomas Egerer wrote:\n> >> This patch fixes that the pretty-formats tformat and format ignore\n> >> git's color option.\n> > \n> > It is my understanding that this is intentional, the logic being: If you\n> > normally don't want color, but have specified it directly on the\n> > command-line, you probably want color.\n> I'm using the pretty format in the context of an alias. My global setting\n> for colors is auto. I would expect git to not disregard this options. I\n> usually use the alias to display a git log in a modified way, but I also\n> do sometimes pipe it to grep. If there was a way to suppress output\n> colorization (let's say by not using global options but the command line\n> switch --color=never) that would work for me. But there is no wa and I\n> find it inconvinient to have two different aliases doing the same thing\n> one with color and one without while there would be a much simpler way.\n...snip\n> Thomas\n\nPerhaps --color=auto, specified on the command-line, should behave\ndifferently to the various color options specified via config. That\nmight make both sides happy, as one could always specify --color=auto to\nexplicitly tell git to only color if it thinks it should.\n\nCan anyone else refresh my memory regarding the use-case where\nhand-specified colors really should have an effect even with\n--color=never?\n"},{"id":"163559","messageId":"4D8210B8.804@secunet.com","threadId":"26760","inReplyTo":"1300354791.3269.19.camel@wpalmer.simply-domain","subject":"Re: [PATCH] pretty.c: Make user defined format honor color option","fromName":"Thomas Egerer","fromEmail":"thomas.egerer@secunet.com","sentAt":"2011-03-17T13:46:32Z","receivedAt":"2011-03-17T13:46:32Z","isPatch":true,"sender":{"key":"thomas.egerer@secunet.com","avatar":null},"body":"\nThis patch fixes that the pretty-formats tformat and format ignore\ngit's color option.\n\nSigned-off-by: Thomas Egerer <thomas.egerer@secunet.com>\n---\n builtin/log.c      |    2 +-\n builtin/rev-list.c |    1 +\n builtin/shortlog.c |    5 +++--\n commit.h           |    1 +\n log-tree.c         |    1 +\n pretty.c           |   29 +++++++++++++++++------------\n shortlog.h         |    2 +-\n 7 files changed, 25 insertions(+), 16 deletions(-)\n\n\n\n0001-pretty.c-Make-user-defined-format-honor-color-option.patch\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex f5ed690..d65d268 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -780,7 +780,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \tlog.in1 = 2;\n \tlog.in2 = 4;\n \tfor (i = 0; i < nr; i++)\n-\t\tshortlog_add_commit(&log, list[i]);\n+\t\tshortlog_add_commit(rev, &log, list[i]);\n\n \tshortlog_output(&log);\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex ba27d39..7dcd659 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -108,6 +108,7 @@ static void show_commit(struct commit *commit, void *data)\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.abbrev = revs->abbrev;\n \t\tctx.date_mode = revs->date_mode;\n+\t\tctx.colorize = (DIFF_OPT_TST(&revs->diffopt, COLOR_DIFF) != 0);\n \t\tpretty_print_commit(revs->commit_format, commit, &buf, &ctx);\n \t\tif (revs->graph) {\n \t\t\tif (buf.len) {\ndiff --git a/builtin/shortlog.c b/builtin/shortlog.c\nindex 1a21e4b..401525e 100644\n--- a/builtin/shortlog.c\n+++ b/builtin/shortlog.c\n@@ -136,7 +136,7 @@ static void read_from_stdin(struct shortlog *log)\n \t}\n }\n\n-void shortlog_add_commit(struct shortlog *log, struct commit *commit)\n+void shortlog_add_commit(struct rev_info * rev, struct shortlog *log, struct commit *commit)\n {\n \tconst char *author = NULL, *buffer;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -166,6 +166,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)\n \t\tctx.subject = \"\";\n \t\tctx.after_subject = \"\";\n \t\tctx.date_mode = DATE_NORMAL;\n+\t\tctx.colorize = (DIFF_OPT_TST(&rev->diffopt, COLOR_DIFF) != 0);\n \t\tpretty_print_commit(CMIT_FMT_USERFORMAT, commit, &ufbuf, &ctx);\n \t\tbuffer = ufbuf.buf;\n \t} else if (*buffer) {\n@@ -183,7 +184,7 @@ static void get_from_rev(struct rev_info *rev, struct shortlog *log)\n \tif (prepare_revision_walk(rev))\n \t\tdie(\"revision walk setup failed\");\n \twhile ((commit = get_revision(rev)) != NULL)\n-\t\tshortlog_add_commit(log, commit);\n+\t\tshortlog_add_commit(rev, log, commit);\n }\n\n static int parse_uint(char const **arg, int comma, int defval)\ndiff --git a/commit.h b/commit.h\nindex 659c87c..d23bf99 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -78,6 +78,7 @@ struct pretty_print_context\n \tint show_notes;\n \tstruct reflog_walk_info *reflog_info;\n \tconst char *output_encoding;\n+\tunsigned colorize:1;\n };\n\n struct userformat_want {\ndiff --git a/log-tree.c b/log-tree.c\nindex b46ed3b..63017d2 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -505,6 +505,7 @@ void show_log(struct rev_info *opt)\n \tctx.abbrev = opt->diffopt.abbrev;\n \tctx.after_subject = extra_headers;\n \tctx.reflog_info = opt->reflog_info;\n+\tctx.colorize = (DIFF_OPT_TST(&opt->diffopt, COLOR_DIFF) != 0);\n \tpretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);\n\n \tif (opt->add_signoff)This patch fixes that the pretty-formats tformat and format ignore\ngit's color option.\n\nSigned-off-by: Thomas Egerer <thomas.egerer@secunet.com>\n---\n builtin/log.c      |    2 +-\n builtin/rev-list.c |    1 +\n builtin/shortlog.c |    5 +++--\n commit.h           |    1 +\n log-tree.c         |    1 +\n pretty.c           |   29 +++++++++++++++++------------\n shortlog.h         |    2 +-\n 7 files changed, 25 insertions(+), 16 deletions(-)\n\n\n\n0001-pretty.c-Make-user-defined-format-honor-color-option.patch\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex f5ed690..d65d268 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -780,7 +780,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \tlog.in1 = 2;\n \tlog.in2 = 4;\n \tfor (i = 0; i < nr; i++)\n-\t\tshortlog_add_commit(&log, list[i]);\n+\t\tshortlog_add_commit(rev, &log, list[i]);\n\n \tshortlog_output(&log);\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex ba27d39..7dcd659 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -108,6 +108,7 @@ static void show_commit(struct commit *commit, void *data)\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.abbrev = revs->abbrev;\n \t\tctx.date_mode = revs->date_mode;\n+\t\tctx.colorize = (DIFF_OPT_TST(&revs->diffopt, COLOR_DIFF) != 0);\n \t\tpretty_print_commit(revs->commit_format, commit, &buf, &ctx);\n \t\tif (revs->graph) {\n \t\t\tif (buf.len) {\ndiff --git a/builtin/shortlog.c b/builtin/shortlog.c\nindex 1a21e4b..401525e 100644\n--- a/builtin/shortlog.c\n+++ b/builtin/shortlog.c\n@@ -136,7 +136,7 @@ static void read_from_stdin(struct shortlog *log)\n \t}\n }\n\n-void shortlog_add_commit(struct shortlog *log, struct commit *commit)\n+void shortlog_add_commit(struct rev_info * rev, struct shortlog *log, struct commit *commit)\n {\n \tconst char *author = NULL, *buffer;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -166,6 +166,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)\n \t\tctx.subject = \"\";\n \t\tctx.after_subject = \"\";\n \t\tctx.date_mode = DATE_NORMAL;\n+\t\tctx.colorize = (DIFF_OPT_TST(&rev->diffopt, COLOR_DIFF) != 0);\n \t\tpretty_print_commit(CMIT_FMT_USERFORMAT, commit, &ufbuf, &ctx);\n \t\tbuffer = ufbuf.buf;\n \t} else if (*buffer) {\n@@ -183,7 +184,7 @@ static void get_from_rev(struct rev_info *rev, struct shortlog *log)\n \tif (prepare_revision_walk(rev))\n \t\tdie(\"revision walk setup failed\");\n \twhile ((commit = get_revision(rev)) != NULL)\n-\t\tshortlog_add_commit(log, commit);\n+\t\tshortlog_add_commit(rev, log, commit);\n }\n\n static int parse_uint(char const **arg, int comma, int defval)\ndiff --git a/commit.h b/commit.h\nindex 659c87c..d23bf99 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -78,6 +78,7 @@ struct pretty_print_context\n \tint show_notes;\n \tstruct reflog_walk_info *reflog_info;\n \tconst char *output_encoding;\n+\tunsigned colorize:1;\n };\n\n struct userformat_want {\ndiff --git a/log-tree.c b/log-tree.c\nindex b46ed3b..63017d2 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -505,6 +505,7 @@ void show_log(struct rev_info *opt)\n \tctx.abbrev = opt->diffopt.abbrev;\n \tctx.after_subject = extra_headers;\n \tctx.reflog_info = opt->reflog_info;\n+\tctx.colorize = (DIFF_OPT_TST(&opt->diffopt, COLOR_DIFF) != 0);\n \tpretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);\n\n \tif (opt->add_signoff)\ndiff --git a/pretty.c b/pretty.c\nindex 8549934..3c3467f 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -743,7 +743,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \tstruct format_commit_context *c = context;\n \tconst struct commit *commit = c->commit;\n \tconst char *msg = c->message;\n+\tchar cbuf[COLOR_MAXLEN];\n \tstruct commit_list *p;\n+\tsize_t consumed = 0;\n+\tchar *color = NULL;\n \tint h1, h2;\n\n \t/* these are independent of the commit */\n@@ -751,29 +754,31 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \tcase 'C':\n \t\tif (placeholder[1] == '(') {\n \t\t\tconst char *end = strchr(placeholder + 2, ')');\n-\t\t\tchar color[COLOR_MAXLEN];\n \t\t\tif (!end)\n \t\t\t\treturn 0;\n \t\t\tcolor_parse_mem(placeholder + 2,\n \t\t\t\t\tend - (placeholder + 2),\n-\t\t\t\t\t\"--pretty format\", color);\n-\t\t\tstrbuf_addstr(sb, color);\n-\t\t\treturn end - placeholder + 1;\n+\t\t\t\t\t\"--pretty format\", cbuf);\n+\t\t\tconsumed = end - placeholder + 1;\n+\t\t\tcolor = cbuf;\n \t\t}\n \t\tif (!prefixcmp(placeholder + 1, \"red\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RED);\n-\t\t\treturn 4;\n+\t\t\tcolor = GIT_COLOR_RED;\n+\t\t\tconsumed = 4;\n \t\t} else if (!prefixcmp(placeholder + 1, \"green\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_GREEN);\n-\t\t\treturn 6;\n+\t\t\tcolor = GIT_COLOR_GREEN;\n+\t\t\tconsumed = 6;\n \t\t} else if (!prefixcmp(placeholder + 1, \"blue\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_BLUE);\n-\t\t\treturn 5;\n+\t\t\tcolor = GIT_COLOR_BLUE;\n+\t\t\tconsumed = 5;\n \t\t} else if (!prefixcmp(placeholder + 1, \"reset\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n-\t\t\treturn 6;\n+\t\t\tcolor = GIT_COLOR_RESET;\n+\t\t\tconsumed = 6;\n \t\t} else\n \t\t\treturn 0;\n+\t\tif (color && (c->pretty_ctx->colorize == 1))\n+\t\t\tstrbuf_addstr(sb, color);\n+\t\treturn consumed;\n \tcase 'n':\t\t/* newline */\n \t\tstrbuf_addch(sb, '\\n');\n \t\treturn 1;\ndiff --git a/shortlog.h b/shortlog.h\nindex de4f86f..0da5f97 100644\n--- a/shortlog.h\n+++ b/shortlog.h\n@@ -21,7 +21,7 @@ struct shortlog {\n\n void shortlog_init(struct shortlog *log);\n\n-void shortlog_add_commit(struct shortlog *log, struct commit *commit);\n+void shortlog_add_commit(struct rev_info *rev, struct shortlog *log, struct commit *commit);\n\n void shortlog_output(struct shortlog *log);\n\n\ndiff --git a/pretty.c b/pretty.c\nindex 8549934..3c3467f 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -743,7 +743,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \tstruct format_commit_context *c = context;\n \tconst struct commit *commit = c->commit;\n \tconst char *msg = c->message;\n+\tchar cbuf[COLOR_MAXLEN];\n \tstruct commit_list *p;\n+\tsize_t consumed = 0;\n+\tchar *color = NULL;\n \tint h1, h2;\n\n \t/* these are independent of the commit */\n@@ -751,29 +754,31 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \tcase 'C':\n \t\tif (placeholder[1] == '(') {\n \t\t\tconst char *end = strchr(placeholder + 2, ')');\n-\t\t\tchar color[COLOR_MAXLEN];\n \t\t\tif (!end)\n \t\t\t\treturn 0;\n \t\t\tcolor_parse_mem(placeholder + 2,\n \t\t\t\t\tend - (placeholder + 2),\n-\t\t\t\t\t\"--pretty format\", color);\n-\t\t\tstrbuf_addstr(sb, color);\n-\t\t\treturn end - placeholder + 1;\n+\t\t\t\t\t\"--pretty format\", cbuf);\n+\t\t\tconsumed = end - placeholder + 1;\n+\t\t\tcolor = cbuf;\n \t\t}\n \t\tif (!prefixcmp(placeholder + 1, \"red\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RED);\n-\t\t\treturn 4;\n+\t\t\tcolor = GIT_COLOR_RED;\n+\t\t\tconsumed = 4;\n \t\t} else if (!prefixcmp(placeholder + 1, \"green\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_GREEN);\n-\t\t\treturn 6;\n+\t\t\tcolor = GIT_COLOR_GREEN;\n+\t\t\tconsumed = 6;\n \t\t} else if (!prefixcmp(placeholder + 1, \"blue\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_BLUE);\n-\t\t\treturn 5;\n+\t\t\tcolor = GIT_COLOR_BLUE;\n+\t\t\tconsumed = 5;\n \t\t} else if (!prefixcmp(placeholder + 1, \"reset\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n-\t\t\treturn 6;\n+\t\t\tcolor = GIT_COLOR_RESET;\n+\t\t\tconsumed = 6;\n \t\t} else\n \t\t\treturn 0;\n+\t\tif (color && (c->pretty_ctx->colorize == 1))\n+\t\t\tstrbuf_addstr(sb, color);\n+\t\treturn consumed;\n \tcase 'n':\t\t/* newline */\n \t\tstrbuf_addch(sb, '\\n');\n \t\treturn 1;\ndiff --git a/shortlog.h b/shortlog.h\nindex de4f86f..0da5f97 100644\n--- a/shortlog.h\n+++ b/shortlog.h\n@@ -21,7 +21,7 @@ struct shortlog {\n\n void shortlog_init(struct shortlog *log);\n\n-void shortlog_add_commit(struct shortlog *log, struct commit *commit);\n+void shortlog_add_commit(struct rev_info *rev, struct shortlog *log, struct commit *commit);\n\n void shortlog_output(struct shortlog *log);\n"},{"id":"163584","messageId":"20110317194952.GF20508@sigill.intra.peff.net","threadId":"26760","inReplyTo":"1300366792.3269.24.camel@wpalmer.simply-domain","subject":"Re: [PATCH] pretty.c: Make user defined format honor color option","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-03-17T19:49:53Z","receivedAt":"2011-03-17T19:49:53Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 17, 2011 at 12:59:52PM +0000, Will Palmer wrote:\n\n> Perhaps --color=auto, specified on the command-line, should behave\n> differently to the various color options specified via config. That\n> might make both sides happy, as one could always specify --color=auto to\n> explicitly tell git to only color if it thinks it should.\n> \n> Can anyone else refresh my memory regarding the use-case where\n> hand-specified colors really should have an effect even with\n> --color=never?\n\nWithout doing any digging on the list and just from the top of my head,\nI don't think it was ever really an intentional feature that format\nshould ignore color settings. It simply wasn't bothered with because in\nthe beginning, the only way to specify a format was on the command line.\nNow as we see them used in aliases, it probably makes sense to respect\nthe color setting. If one wants the current behavior, they can always\nuse --color=always.\n\nSo I think the intent of Thomas' patch is a good change, though I\nhaven't really looked closely at the patch itself.\n\n-Peff\n"}]}