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

[RFC PATCH] git log: support "auto" decorations

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
May 29, 2014, 22:31 UTC
Message-ID
<alpine.LFD.2.11.1405291523520.8270@i7.linux-foundation.org>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Thu, 29 May 2014 15:19:40 -0700
Subject: [RFC PATCH] git log: support "auto" decorations

This works kind of like "--color=auto" - add decorations for interactive use, but do not change defaults when scripting or when piping the output to anything but a terminal.

You can use either
    [log]
         decorate=auto

in the git config files, or the "--decorate=auto" command line option to choose this behavior.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

I actually like seeing decorations by default, but I do *not* think our current "log.decorate" options make sense, since they will change any random use of "git log" to have decorations. I much prefer the "ui.color=auto" behavior that we have for coloration. This is a trivial patch that tries to approximate that.

It's marked with RFC because
 (a) that "isatty(1) || pager_in_use()" test is kind of hacky, maybe we 
     would be better off sharing something with the auto-coloration?
 (b) I also think it would be nice to have the equivalent for 
     "--show-signature", but there we don't have any preexisting config 
     file option.
 (c) maybe somebody would like a way to combine "auto" and "full", 
     although personally that doesn't seem to strike me as all that useful 
     (would you really want to see the full refname when not scripting it)
but the patch is certainly simple and seems to work. Comments?
 builtin/log.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index 39e883635279..df6396c9c3d9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -63,6 +63,8 @@ static int parse_decoration_style(const char *var, const char *value)
 		return DECORATE_FULL_REFS;
 	else if (!strcmp(value, "short"))
 		return DECORATE_SHORT_REFS;
+	else if (!strcmp(value, "auto"))
+		return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
 	return -1;
 }
 
-- 
2.0.0.1.g5beb60c
Next: Jeff King
Message 1 of 13 in “git log: support "auto" decorations”
  1. git log: support "auto" decorationsLinus Torvalds, May 29, 2014
  2. Jeff KingMay 30, 2014
  3. Linus TorvaldsMay 30, 2014
  4. Jeff KingMay 30, 2014
  5. Junio C HamanoMay 30, 2014
  6. Jeff KingMay 30, 2014
  7. Junio C HamanoMay 30, 2014
  8. Jeff KingMay 30, 2014
  9. Jeff KingMay 30, 2014
  10. Junio C HamanoMay 30, 2014
  11. Jeff KingMay 30, 2014
  12. Junio C HamanoMay 30, 2014
  13. Junio C HamanoMay 30, 2014

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.