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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steven Drake <sdrake@xxxxxxxxxx> 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 <sdrake@xxxxxxxxxx>
> ---

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

> 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"))
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]