From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>
Cc: Duy Nguyen <pclouds@gmail.com>, Tom Hale <tom@hale.ee>,
git <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] pretty: respect color settings for %C placeholders
Date: Mon, 10 Oct 2016 21:59:17 +0200 [thread overview]
Message-ID: <19e59db7-f3dd-35ec-8cf1-b070b1c05abe@web.de> (raw)
In-Reply-To: <20161010174257.b4uxplavefjyr6rl@sigill.intra.peff.net>
Am 10.10.2016 um 19:42 schrieb Jeff King:
> On Mon, Oct 10, 2016 at 07:09:12PM +0200, René Scharfe wrote:
>
>>> 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;
>>> }
>>
>> Shouldn't we have an "else" here?
>
> I'm not sure what you mean; can you write it out?
> - if (skip_prefix(begin, "auto,", &begin)) {
> +
> + if (!skip_prefix(begin, "always,", &begin)) {
> if (!want_color(c->pretty_ctx->color))
> return end - placeholder + 1;
> }
else { /* here */
> + /* this is a historical noop */
> + skip_prefix(begin, "auto,", &begin);
}
Otherwise "always,auto," would be allowed and mean the same as
"always,", which just seems wrong. Not a biggie.
>>> - 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);
>>> - else if (skip_prefix(placeholder + 1, "green", &rest))
>>> + else if (skip_prefix(placeholder + 1, "green", &rest) &&
>>> + want_color(c->pretty_ctx->color))
>>> strbuf_addstr(sb, GIT_COLOR_GREEN);
>>> - else if (skip_prefix(placeholder + 1, "blue", &rest))
>>> + else if (skip_prefix(placeholder + 1, "blue", &rest) &&
>>> + want_color(c->pretty_ctx->color))
>>> strbuf_addstr(sb, GIT_COLOR_BLUE);
>>> - else if (skip_prefix(placeholder + 1, "reset", &rest))
>>> + else if (skip_prefix(placeholder + 1, "reset", &rest) &&
>>> + want_color(c->pretty_ctx->color))
>>> strbuf_addstr(sb, GIT_COLOR_RESET);
>>> return rest - placeholder;
>>> }
>>
>> Perhaps it's a funtion like add_color(sb, ctx, color) or similar would be
>> nice?
>
> I actually wrote it that way first (I called it "maybe_add_color()"),
> but it felt a little funny to have a separate function that people might
> be tempted to reuse (the right solution is generally to check
> want_color() early as above, but we can't do that here because we have
> to find the end of each placeholder).
OK. A variable then? Lazy pseudo-code:
if (RED)
color = red;
else if (GREEN)
...
if (want_color())
strbuf_addstr(sb, color);
> What I have here is a little funny, too, though, as it keeps trying
> other color names if it finds "red" but want_color() returns 0.
Oh, missed that somehow.. O_o
next prev parent reply other threads:[~2016-10-10 19:59 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 [this message]
2016-10-10 20:04 ` Jeff King
2016-10-10 18:52 ` Junio C Hamano
2016-10-10 18:59 ` Jeff King
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=19e59db7-f3dd-35ec-8cf1-b070b1c05abe@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--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).