From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Duy Nguyen" <pclouds@gmail.com>, "René Scharfe" <l.s.r@web.de>,
"Tom Hale" <tom@hale.ee>, git <git@vger.kernel.org>
Subject: Re: [PATCH] pretty: respect color settings for %C placeholders
Date: Mon, 10 Oct 2016 14:59:36 -0400 [thread overview]
Message-ID: <20161010185935.r3wnfglpi7hjjpdk@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqq1szof34x.fsf@gitster.mtv.corp.google.com>
On Mon, Oct 10, 2016 at 11:52:14AM -0700, Junio C Hamano wrote:
> > + By default, colors are shown only when enabled for log output (by
> > + `color.diff`, `color.ui`, or `--color`, and respecting the `auto`
> > + settings of the former if we are going to a terminal). `%C(auto,...)`
> > + is accepted as a historical synonym for the default. Specifying
> > + `%C(always,...) will show the colors always, even when colors are not
> > + otherwise enabled (to enable this behavior for the whole format, use
> > + `--color=always`).
>
> It is not just "for the whole format", but also affects other parts
> of the output, no? I am thinking about "git log -p --format=...".
True. I consider that a feature and more likely to be pointing the user
in the right direction, but it should probably be s/format/output/ in
the last sentence.
> > diff --git a/pretty.c b/pretty.c
> > index 25efbca..73e58b5 100644
> > --- a/pretty.c
> > +++ b/pretty.c
> > @@ -965,22 +965,31 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
> >
> > if (!end)
> > return 0;
> > - if (skip_prefix(begin, "auto,", &begin)) {
> > +
> > + if (!skip_prefix(begin, "always,", &begin)) {
> > if (!want_color(c->pretty_ctx->color))
> > return end - placeholder + 1;
> > }
>
> As a way to say "when color is not enabled, ignore everything unless
> it begins with 'always,'", this was a bit hard to read. Perhaps an
> in-code comment is in order?
I'll see what I can do. The most readable one is probably:
if (skip_prefix(begin, "auto,", &begin)) {
if (!want_color(c->pretty_ctx->color))
return end - placeholder + 1;
} else if (skip_prefix(begin, "always,", &begin)) {
/* nothing to do; we do not respect want_color at all */
} else {
/* the default is now the same as "auto" */
if (!want_color(c->pretty_ctx->color))
return end - placeholder + 1;
}
I avoided that because of the repetition, but it probably is not too
bad.
> > - if (skip_prefix(placeholder + 1, "red", &rest))
> > + if (skip_prefix(placeholder + 1, "red", &rest) &&
> > + want_color(c->pretty_ctx->color))
> > strbuf_addstr(sb, GIT_COLOR_RED);
>
> Hmm. If we are in "no I do not want color" mode and "always,red"
> was given, we countermanded !want_color() check up above and come
> here. Then we check want_color() again and refuse to paint it red?
>
> I must be reading the patch incorrectly, but I cannot quite tell
> where I want astray...
No, we don't come here from %C() at all. This is for bare "%Cred", which
cannot have "always" (or "auto"), as there is no syntactic spot for it.
It is mostly historical (it _only_ supports red, green, and blue). We
could actually leave this as-is to show the colors unconditionally. I
changed it to keep the new behavior consistent, but I doubt anybody
cares much either way.
-Peff
next prev parent reply other threads:[~2016-10-10 19:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-09 5:43 %C(auto) not working as expected Tom Hale
2016-10-09 6:47 ` René Scharfe
2016-10-09 10:04 ` Tom Hale
2016-10-09 13:24 ` René Scharfe
2016-10-09 23:46 ` Jeff King
2016-10-10 9:26 ` Duy Nguyen
2016-10-10 14:28 ` Jeff King
2016-10-10 15:15 ` [PATCH] pretty: respect color settings for %C placeholders Jeff King
2016-10-10 17:09 ` René Scharfe
2016-10-10 17:42 ` Jeff King
2016-10-10 19:59 ` René Scharfe
2016-10-10 20:04 ` Jeff King
2016-10-10 18:52 ` Junio C Hamano
2016-10-10 18:59 ` Jeff King [this message]
2016-10-10 20:54 ` Jeff King
2016-10-11 10:59 ` Duy Nguyen
2016-10-25 12:52 ` %C(auto) not working as expected Duy Nguyen
2016-10-25 12:58 ` Jeff King
2016-10-25 13:02 ` Duy Nguyen
2016-10-10 20:52 ` René Scharfe
2016-10-10 20:55 ` Jeff King
2016-10-11 3:41 ` [PATCH v2] pretty: fix document link for color specification René Scharfe
2016-10-11 4:45 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161010185935.r3wnfglpi7hjjpdk@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=pclouds@gmail.com \
--cc=tom@hale.ee \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).