Re: FW: Git log --graph doesn't output color when redirected

2012-12-15 Thread Junio C Hamano
Jeff King p...@peff.net writes:

 On Sat, Dec 15, 2012 at 10:23:10AM +0700, Nguyen Thai Ngoc Duy wrote:

 On Thu, Dec 13, 2012 at 8:13 PM, Jeff King p...@peff.net wrote:
  If you are using --format=%C(red) or similar placeholders,
  they are the odd duck by not respecting the auto-color mode.
 
 But they should, shouldn't they? Just asking. I may do it to when I
 revive nd/pretty-placeholder-with-color-option.

 If I were designing --format today, I would certainly say so. The only
 thing holding me back would be backwards compatibility. We could get
 around that by introducing a new placeholder like %c(color) that behaves
 like %C(color), except respects the --color flag.

I think the %c(color) thing is a good way to go if we want to pursue
this.

Another possibility without wasting one more special letter would be
to allow %C(auto,red), perhaps like this (untested):

 pretty.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git i/pretty.c w/pretty.c
index dba6828..77cf826 100644
--- i/pretty.c
+++ w/pretty.c
@@ -960,12 +960,19 @@ static size_t format_commit_one(struct strbuf *sb, const 
char *placeholder,
switch (placeholder[0]) {
case 'C':
if (placeholder[1] == '(') {
-   const char *end = strchr(placeholder + 2, ')');
+   const char *begin = placeholder + 2;
+   const char *end = strchr(begin, ')');
char color[COLOR_MAXLEN];
+
if (!end)
return 0;
-   color_parse_mem(placeholder + 2,
-   end - (placeholder + 2),
+   if (!memcmp(begin, auto,, 5)) {
+   if (!want_color(GIT_COLOR_AUTO))
+   return 0;
+   begin += 5;
+   }
+   color_parse_mem(begin,
+   end - begin,
--pretty format, color);
strbuf_addstr(sb, color);
return end - placeholder + 1;
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: FW: Git log --graph doesn't output color when redirected

2012-12-14 Thread Nguyen Thai Ngoc Duy
On Thu, Dec 13, 2012 at 8:13 PM, Jeff King p...@peff.net wrote:
 If you are using --format=%C(red) or similar placeholders,
 they are the odd duck by not respecting the auto-color mode.

But they should, shouldn't they? Just asking. I may do it to when I
revive nd/pretty-placeholder-with-color-option.
-- 
Duy
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: FW: Git log --graph doesn't output color when redirected

2012-12-13 Thread Jeff King
On Wed, Dec 12, 2012 at 05:35:17PM +, Srb, Michal wrote:

 Unlike --pretty-format, --graph doesn’t output colors when the git log output
 is redirected.

I do not think it has anything to do with --graph in particular, but
rather that when colorization is set to the auto mode, it is enabled
only when stdout is a tty. Diff coloring, for example, follows the same
rules.  If you are using --format=%C(red) or similar placeholders,
they are the odd duck by not respecting the auto-color mode.

 Is there a setting somewhere in config to change this?

Yes. If you use --color on the command line, that means
unconditionally use color. If you set color.ui (or any other color
config option) to always, then you will always get color (and you can
disable it for a particular run with --no-color). Setting a color
config option to true is the same as auto, which gets you the auto
mode.

-Peff
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: FW: Git log --graph doesn't output color when redirected

2012-12-13 Thread Srb, Michal
From: Jeff King [p...@peff.net]
Sent: Thursday, December 13, 2012 1:13 PM

 Is there a setting somewhere in config to change this?

 Yes. If you use --color on the command line, that means
 unconditionally use color. If you set color.ui (or any other
 color config option) to always, then you will always get color (and
 you can disable it for a particular run with --no-color). Setting a color
 config option to true is the same as auto, which gets you 
 the auto mode.
 
Setting color in gitconfig didn't work for me on msys, but --color 
works like magic, thanks!--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html