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

Re: [PATCH] log --format: teach %C(auto,black) to paint it black only on terminals

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 17, 2012, 19:34 UTC
Message-ID
<7v4njkmq07.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20121217121354.GB21858@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 19 quoted lines
> On Mon, Dec 17, 2012 at 06:44:10PM +0700, Nguyen Thai Ngoc Duy wrote:
>
>> >                         if (!end)
>> >                                 return 0;
>> > -                       color_parse_mem(placeholder + 2,
>> > -                                       end - (placeholder + 2),
>> > +                       if (!memcmp(begin, "auto,", 5)) {
>> > +                               if (!want_color(-1))
>> > +                                       return end - placeholder + 1;
>> 
>> This want_color() checks color.ui and only when color.ui = auto, it
>> bothers to check if the output is tty. I think the document should say
>> that "auto," (or maybe another name because it's not really auto)
>> respects color.ui.
>
> Yeah, that should definitely be documented. I wonder if it should
> actually respect color.diff, which is what "log" usually uses (albeit
> mostly for the diff itself, we have always used it for the graph and for
> the "commit" header of each entry).

I actually do not like this patch very much. The original motive behind this "auto" thing was to relieve the script writers from the burden of having to write:

	if tty -s
        then
        	warn='%C(red)'
                reset='%C(reset)'
	else
        	warn= reset=
	fi
        fmt="${warn}WARNING: boo${reset} %s"
and instead let them write:
	fmt="%C(auto,red)WARNING: boo%C(auto,reset) %s"

but between the two, there is no $cmd.color configuration involved in the first place. I am not sure what $cmd.color configuration should take effect---perhaps for a "git frotz" script, we should allow the script writer to honor frotz.color=(auto,never,always) configuration, not just ui.color variable.

Also the patch as posted deliberately omits support to honor command line override --color=(auto,never,always), but it may be more natural to expect

    git show --format='%C(auto,red)%s%C(auto,reset)' --color=never
to defeat the "auto," part the script writer wrote.
Now, such a script would be run by its end users as
    $ git frotz --color=never

It has to do its own option parsing before running the underlying "git show" to decide if it passes "--color=never" from the command line for that to happen.

But at that point, we are back to the square one. Such a script would be doing something like:

	if cmdline_has_color_flag
        then
		use_color=... that flag ...
	elif git config --get-colorbool frotz.color
	then
		use_color=--color=always
	else
		use_color=--color=never
	fi

in its early part to decide $use_color, to be used in the call it makes to "git show" later on:

	git show --format="$fmt" $use_color

Adding the logic to decide if %C(...) should be added to $fmt no longer is an additional burden to the script writer, making the whole %C(auto,red) machinery of little use.

So...
Previous: Jeff KingNext: Jeff King
Message 10 of 18 in “FW: Git log --graph doesn't output color when redirected”
  1. Srb, MichalDec 12, 2012
  2. Jeff KingDec 13, 2012
  3. Srb, MichalDec 13, 2012
  4. Nguyen Thai Ngoc DuyDec 15, 2012
  5. Jeff KingDec 15, 2012
  6. Junio C HamanoDec 15, 2012
  7. log --format: teach %C(auto,black) to paint it black only on terminalsJunio C Hamano, Dec 17, 2012
  8. Nguyen Thai Ngoc DuyDec 17, 2012
  9. Jeff KingDec 17, 2012
  10. Junio C HamanoDec 17, 2012
  11. Jeff KingDec 17, 2012
  12. Junio C HamanoDec 17, 2012
  13. Jeff KingDec 17, 2012
  14. 1/2 t6006: clean up whitespaceJunio C Hamano, Dec 17, 2012
  15. Jeff KingDec 17, 2012
  16. 1/2 t6006: clean up whitespaceJeff King, Dec 17, 2012
  17. 2/2 log --format: teach %C(auto,black) to respect color configJeff King, Dec 17, 2012
  18. Jeff KingDec 17, 2012

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.