git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Nguyen Thai Ngoc Duy <pclouds@gmail.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>,
	"Srb, Michal" <michal.srb11@imperial.ac.uk>
Subject: Re: [PATCH] log --format: teach %C(auto,black) to paint it black only on terminals
Date: Mon, 17 Dec 2012 14:49:26 -0500	[thread overview]
Message-ID: <20121217194926.GA5209@sigill.intra.peff.net> (raw)
In-Reply-To: <7v4njkmq07.fsf@alter.siamese.dyndns.org>

On Mon, Dec 17, 2012 at 11:34:48AM -0800, Junio C Hamano wrote:

> > 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.

Since this is by definition just talking about the log traversal, I
think it makes sense to respect the log traversal option by default
(which is confusingly color.diff, of course, but that is a separate
issue). That means that scripts which just wrap a regular traversal will
do what the user is accustomed to.

If "git frotz" wants to have a separate "color.frotz" option to override
that, then they would need to implement that themselves either with or
without your patch. I do not think its presence makes things any harder.

> 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.

Yeah, _if_ it does not just pass its options directly to git-log. Which
I think a reasonable number of scripts do, as well as pretty.* aliases
(which are not really scripts, but have the same relationship with
respect to this feature). For example, "git stash list" does not use
color in its output, but could be improved to do so after your patch.

So no, I do not think you can cover every conceivable case. But having
git-log respect --color and the usual color.* variables for this feature
seems like the only sane default. It makes the easy cases just work, and
the hard cases are not any worse off (and they may even be better off,
since the script can manipulate --color instead of rewriting their
format strings, but that is a minor difference).

-Peff

  reply	other threads:[~2012-12-17 19:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <72BB37CB88C48F4B925365539F1EE46C182613A9@icexch-m3.ic.ac.uk>
2012-12-12 17:35 ` FW: Git log --graph doesn't output color when redirected Srb, Michal
2012-12-13 13:13   ` Jeff King
2012-12-13 15:34     ` Srb, Michal
2012-12-15  3:23     ` Nguyen Thai Ngoc Duy
2012-12-15 10:16       ` Jeff King
2012-12-15 18:30         ` Junio C Hamano
2012-12-17  8:40           ` [PATCH] log --format: teach %C(auto,black) to paint it black only on terminals Junio C Hamano
2012-12-17 11:44             ` Nguyen Thai Ngoc Duy
2012-12-17 12:13               ` Jeff King
2012-12-17 19:34                 ` Junio C Hamano
2012-12-17 19:49                   ` Jeff King [this message]
2012-12-17 20:03                     ` Junio C Hamano
2012-12-17 22:55                       ` Jeff King
2012-12-17 22:55                         ` [PATCH 1/2] t6006: clean up whitespace Junio C Hamano
2012-12-17 22:59                           ` Jeff King
2012-12-17 22:56                         ` Jeff King
2012-12-17 22:56                         ` [PATCH 2/2] log --format: teach %C(auto,black) to respect color config Jeff King
2012-12-17 12:40             ` [PATCH] log --format: teach %C(auto,black) to paint it black only on terminals 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=20121217194926.GA5209@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=michal.srb11@imperial.ac.uk \
    --cc=pclouds@gmail.com \
    /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).