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

Re: [PATCH] Add `log.decorate' configuration variable.

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 17, 2010, 01:08 UTC
Message-ID
<7vljespt2l.fsf@alter.siamese.dyndns.org>
In-Reply-To
<alpine.LNX.2.00.1002171239430.2477@vqena.qenxr.bet.am>
Steven Drake <sdrake@xnet.co.nz> writes:
Show 5 quoted lines
> This alows the 'git-log --decorate' to be enabled by default so that normal
> log outout contains ant ref names of commits that are shown.
>
> Signed-off-by: Steven Drake <sdrake@xnet.co.nz>
> ---
Thanks.

This needs some test to make sure that it triggers when configuration is set, it doesn't when configuration is not set, and it doesn't for commands in log family when it shouldn't (most notably, format-patch).

Show 6 quoted lines
> +log.decorate::
> +	Print out the ref names of any commits that are shown by the log
> +	command. If 'short' is specified, the ref name prefixes 'refs/heads/',
> +	'refs/tags/' and 'refs/remotes/' will not be printed. If 'full' is
> +	specified, the full ref name (including prefix) will be printed.
> +	This is the same as the log commands '--decorate' option.

This should be the same as --decorate option, so it should be possible to set it as a boolean true to mean "short", i.e.

	[log]
        	decorate
		decorate = true
should be treated exactly the same way as
	[log]
        	decorate = short
Show 14 quoted lines
> diff --git a/builtin-log.c b/builtin-log.c
> index 89f8d60..cd6158c 100644
> --- a/builtin-log.c
> +++ b/builtin-log.c
> @@ -249,6 +249,13 @@ static int git_log_config(const char *var, const char *value, void *cb)
>  		return git_config_string(&fmt_patch_subject_prefix, var, value);
>  	if (!strcmp(var, "log.date"))
>  		return git_config_string(&default_date_mode, var, value);
> +	if (!strcmp(var, "log.decorate")) {
> +		if (!strcmp(value, "full"))
> +			decoration_style = DECORATE_FULL_REFS;
> +		else if (!strcmp(value, "short"))
> +			decoration_style = DECORATE_SHORT_REFS;
> +		return 0;

Hence you need to be prepared to see (value == NULL) here without segfaulting. Perhaps something like this patch on top of yours.

 cache.h       |    1 +
 config.c      |   12 +++++++++---
 builtin-log.c |   11 +++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index d478eff..24addea 100644
--- a/cache.h
+++ b/cache.h
@@ -923,6 +923,7 @@ extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_config_int(const char *, const char *);
 extern unsigned long git_config_ulong(const char *, const char *);
 extern int git_config_bool_or_int(const char *, const char *, int *);
+extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
diff --git a/config.c b/config.c
index 6963fbe..6642d30 100644
--- a/config.c
+++ b/config.c
@@ -322,9 +322,8 @@ unsigned long git_config_ulong(const char *name, const char *value)
 	return ret;
 }
 
-int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+int git_config_maybe_bool(const char *name, const char *value)
 {
-	*is_bool = 1;
 	if (!value)
 		return 1;
 	if (!*value)
@@ -333,7 +332,14 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
 		return 1;
 	if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
 		return 0;
-	*is_bool = 0;
+	return -1;
+}
+
+int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+{
+	int v = git_config_maybe_bool(name, value);
+	if (0 <= v)
+		return v;
 	return git_config_int(name, value);
 }
 
diff --git a/builtin-log.c b/builtin-log.c
index 3100dc0..23c00f0 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -253,6 +253,16 @@ static int git_log_config(const char *var, const char *value, void *cb)
 	if (!strcmp(var, "log.date"))
 		return git_config_string(&default_date_mode, var, value);
 	if (!strcmp(var, "log.decorate")) {
+		switch (git_config_maybe_bool(var, value)) {
+		case 0:
+			decoration_style = 0;
+			return 0;
+		case 1:
+			decoration_style = DECORATE_SHORT_REFS;
+			return 0;
+		default:
+			break;
+		}
 		if (!strcmp(value, "full"))
 			decoration_style = DECORATE_FULL_REFS;
 		else if (!strcmp(value, "short"))
Previous: Steven DrakeNext: Steven Drake
Message 2 of 9 in “Add `log.decorate' configuration variable.”
  1. Add `log.decorate' configuration variable.Steven Drake, Feb 16, 2010
  2. Junio C HamanoFeb 17, 2010
  3. Steven DrakeFeb 17, 2010
  4. Junio C HamanoFeb 17, 2010
  5. Steven DrakeFeb 17, 2010
  6. Junio C HamanoFeb 17, 2010
  7. Bert WesargFeb 17, 2010
  8. Re* [PATCH] Add `log.decorate' configuration variable.Junio C Hamano, Feb 17, 2010
  9. Heiko VoigtFeb 17, 2010

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.