git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] pretty: respect color settings for %C placeholders

From
René Scharfe <l.s.r@web.de>
Date
Oct 10, 2016, 19:59 UTC
Message-ID
<19e59db7-f3dd-35ec-8cf1-b070b1c05abe@web.de>
In-Reply-To
<20161010174257.b4uxplavefjyr6rl@sigill.intra.peff.net>
Am 10.10.2016 um 19:42 schrieb Jeff King:
Show 20 quoted lines
> 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.

Show 27 quoted lines
>>> -	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
Previous: Jeff KingNext: Jeff King
Message 11 of 23 in “%C(auto) not working as expected”
  1. Tom HaleOct 9, 2016
  2. René ScharfeOct 9, 2016
  3. Tom HaleOct 9, 2016
  4. René ScharfeOct 9, 2016
  5. Jeff KingOct 9, 2016
  6. Duy NguyenOct 10, 2016
  7. Jeff KingOct 10, 2016
  8. pretty: respect color settings for %C placeholdersJeff King, Oct 10, 2016
  9. René ScharfeOct 10, 2016
  10. Jeff KingOct 10, 2016
  11. René ScharfeOct 10, 2016
  12. Jeff KingOct 10, 2016
  13. Junio C HamanoOct 10, 2016
  14. Jeff KingOct 10, 2016
  15. Jeff KingOct 10, 2016
  16. Duy NguyenOct 11, 2016
  17. Duy NguyenOct 25, 2016
  18. Jeff KingOct 25, 2016
  19. Duy NguyenOct 25, 2016
  20. René ScharfeOct 10, 2016
  21. Jeff KingOct 10, 2016
  22. pretty: fix document link for color specificationRené Scharfe, Oct 11, 2016
  23. Jeff KingOct 11, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.