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

[PATCH] log: if --decorate is not given, default to --decorate=auto

From
Alex Henrie <alexhenrie24@gmail.com>
Date
Mar 21, 2017, 05:52 UTC
Message-ID
<20170321055203.26488-1-alexhenrie24@gmail.com>

Git's branching and merging system can be confusing, especially to new users. When teaching people Git, I tell them to set log.decorate=auto. This preference greatly improves the user's awareness of the local and remote branches. So for the sake of user friendliness, I'd like to change the default from log.decorate=no to log.decorate=auto.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 builtin/log.c  | 9 ++++++++-
 t/t4202-log.sh | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 281af8c1e..ddb4515dc 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -52,6 +52,11 @@ struct line_opt_callback_data {
 	struct string_list args;
 };
 
+static int auto_decoration_style()
+{
+	return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
+}
+
 static int parse_decoration_style(const char *var, const char *value)
 {
 	switch (git_config_maybe_bool(var, value)) {
@@ -67,7 +72,7 @@ static int parse_decoration_style(const char *var, const char *value)
 	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 auto_decoration_style();
 	return -1;
 }
 
@@ -405,6 +410,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
 		if (decoration_style < 0)
 			decoration_style = 0; /* maybe warn? */
 		return 0;
+	} else {
+		decoration_style = auto_decoration_style();
 	}
 	if (!strcmp(var, "log.showroot")) {
 		default_show_root = git_config_bool(var, value);
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 48b55bfd2..3aa8daba3 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -520,7 +520,7 @@ test_expect_success 'log --graph with merge' '
 '
 
 test_expect_success 'log.decorate configuration' '
-	git log --oneline >expect.none &&
+	git log --oneline --no-decorate >expect.none &&
 	git log --oneline --decorate >expect.short &&
 	git log --oneline --decorate=full >expect.full &&
 
-- 
2.12.0
Next: Junio C Hamano
Message 1 of 13 in “log: if --decorate is not given, default to --decorate=auto”
  1. log: if --decorate is not given, default to --decorate=autoAlex Henrie, Mar 21, 2017
  2. Junio C HamanoMar 21, 2017
  3. Junio C HamanoMar 21, 2017
  4. Alex HenrieMar 22, 2017
  5. Junio C HamanoMar 22, 2017
  6. Alex HenrieMar 23, 2017
  7. Junio C HamanoMar 23, 2017
  8. Alex HenrieMar 23, 2017
  9. Junio C HamanoMar 23, 2017
  10. Alex HenrieMar 24, 2017
  11. Jeff KingMar 24, 2017
  12. pager_in_use: use git_env_bool()Jeff King, Mar 24, 2017
  13. Junio C HamanoMar 24, 2017

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.