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

Subsystems: the rest

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:17

Steven Drake [off-list ref] writes:
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 <redacted>
---
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).
+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
quoted hunk
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"))

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

From: Steven Drake <hidden>
Date: 2016-06-15 22:48:17

On Tue, 16 Feb 2010, Junio C Hamano wrote:
This needs some test to make sure that it triggers when configuration is
set, it doesn't when configuration is not set [...]
Done get wat you mean?
[...] and it doesn't for commands
in log family when it shouldn't (most notably, format-patch).
Good point, and looking at the code "log.decorate" only has an affect after
cmd_log_init() is called, which is call by cmd_whatchanged(), cmd_show(), 
cmd_log_reflog() and cmd_log() so only those command are affected
(notably not format-patch).

However if thats not disirable, we could always add
'whatchanged.decorate', 'show.decorate' and reflog.decorate'. 
 
quoted
+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
I thought about that but did not want start adding git_config_XXX()
functions, but you want to add git_config_maybe_bool() then I would agree
with add your patch on top (and you should do so).

While on the subject of git_config I think die_bad_config() should be an
extern (i.e. decleared in cache.h and a static function) so that it could
be used in git_XXX_config functions for handling error.  Something like:
diff --git a/builtin-log.c b/builtin-log.c
index f096eea..a41a7bb 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -264,6 +264,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
 			decoration_style = DECORATE_FULL_REFS;
 		else if (!strcmp(value, "short"))
 			decoration_style = DECORATE_SHORT_REFS;
+		else
+			die_bad_config(var);
 		return 0;
 	}
 	if (!strcmp(var, "log.showroot")) {
-- 
Steven
UNIX is basically a simple operating system,
but you have to be a genius to understand the simplicity  --- dmr

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

From: Bert Wesarg <hidden>
Date: 2016-06-15 22:48:17

On Wed, Feb 17, 2010 at 02:08, Junio C Hamano [off-list ref] wrote:
quoted hunk
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);
 }
What happened with the is_bool parameter?

Bert
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help