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

Re: [PATCH] git-log: allow --decorate[=short|full]

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 18, 2009, 20:18 UTC
Message-ID
<7viqgkc1v4.fsf@alter.siamese.dyndns.org>
In-Reply-To
<8c5c35580908150723h6e4c8fcay43b708969a86ae27@mail.gmail.com>
Lars Hjemli <hjemli@gmail.com> writes:
Show 31 quoted lines
> diff --git a/builtin-log.c b/builtin-log.c
> index 3817bf1..1ed4c76 100644
> --- a/builtin-log.c
> +++ b/builtin-log.c
> @@ -61,8 +61,15 @@ static void cmd_log_init(int argc, const char
> **argv, const char *prefix,
>  	for (i = 1; i < argc; i++) {
>  		const char *arg = argv[i];
>  		if (!strcmp(arg, "--decorate")) {
> -			load_ref_decorations();
> -			rev->show_decorations = 1;
> +			rev->show_decorations = DECORATE_SHORT_REFS;
> +		} else if (!prefixcmp(arg, "--decorate=")) {
> +			const char *v = skip_prefix(arg, "--decorate=");
> +			if (!strcmp(v, "full"))
> +				rev->show_decorations = DECORATE_FULL_REFS;
> +			else if (!strcmp(v, "short"))
> +				rev->show_decorations = DECORATE_SHORT_REFS;
> +			else
> +				die("invalid --decorate option: %s", arg);
>  		} else if (!strcmp(arg, "--source")) {
>  			rev->show_source = 1;
>  		} else if (!strcmp(arg, "-h")) {
> @@ -70,6 +77,8 @@ static void cmd_log_init(int argc, const char
> **argv, const char *prefix,
>  		} else
>  			die("unrecognized argument: %s", arg);
>  	}
> +	if (rev->show_decorations)
> +		load_ref_decorations(rev->show_decorations);
>  }

If you are deciding whether full refs are given or short ones when you call load_ref_decorations(), I do not think there is any reason for you to change the type of rev->short_decorations from bool to enum. Shouldn't you maintain a local variable in this function and pass it down to this call instead?

That is, something like this on top (I had to fix the breakage your MUA has done to your patch, so there might be some fuzz around whitespace).

 builtin-log.c |   13 ++++++++-----
 log-tree.c    |    2 +-
 revision.h    |    2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 2a0f5f7..25e21ed 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -35,6 +35,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 		      struct rev_info *rev)
 {
 	int i;
+	int decoration_style = 0;
 
 	rev->abbrev = DEFAULT_ABBREV;
 	rev->commit_format = CMIT_FMT_DEFAULT;
@@ -61,13 +62,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 		if (!strcmp(arg, "--decorate")) {
-			rev->show_decorations = DECORATE_SHORT_REFS;
+			decoration_style = DECORATE_SHORT_REFS;
 		} else if (!prefixcmp(arg, "--decorate=")) {
 			const char *v = skip_prefix(arg, "--decorate=");
 			if (!strcmp(v, "full"))
-				rev->show_decorations = DECORATE_FULL_REFS;
+				decoration_style = DECORATE_FULL_REFS;
 			else if (!strcmp(v, "short"))
-				rev->show_decorations = DECORATE_SHORT_REFS;
+				decoration_style = DECORATE_SHORT_REFS;
 			else
 				die("invalid --decorate option: %s", arg);
 		} else if (!strcmp(arg, "--source")) {
@@ -77,8 +78,10 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 		} else
 			die("unrecognized argument: %s", arg);
 	}
-	if (rev->show_decorations)
-		load_ref_decorations(rev->show_decorations);
+	if (decoration_style) {
+		rev->show_decorations = 1;
+		load_ref_decorations(decoration_style);
+	}
 }
 
 /*
diff --git a/log-tree.c b/log-tree.c
index 1c767c9..1c9eefe 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -25,7 +25,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
 	struct object *obj = parse_object(sha1);
 	if (!obj)
 		return 0;
-	if (!cb_data || *(int *)cb_data & DECORATE_SHORT_REFS)
+	if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
 		refname = prettify_refname(refname);
 	add_name_decoration("", refname, obj);
 	while (obj->type == OBJ_TAG) {
diff --git a/revision.h b/revision.h
index 9a644ee..b10984b 100644
--- a/revision.h
+++ b/revision.h
@@ -59,6 +59,7 @@ struct rev_info {
 			rewrite_parents:1,
 			print_parents:1,
 			show_source:1,
+			show_decorations:1,
 			reverse:1,
 			reverse_output_stage:1,
 			cherry_pick:1,
@@ -98,7 +99,6 @@ struct rev_info {
 	const char	*subject_prefix;
 	int		no_inline;
 	int		show_log_size;
-	int		show_decorations;
 
 	/* Filter by commit log message */
 	struct grep_opt	grep_filter;
Previous: Jeff King
Message 6 of 6 in “git-log: allow --decorate[=short|full]”
  1. git-log: allow --decorate[=short|full]Lars Hjemli, Aug 15, 2009
  2. Lars HjemliAug 15, 2009
  3. Jeff KingAug 15, 2009
  4. Lars HjemliAug 15, 2009
  5. Jeff KingAug 18, 2009
  6. Junio C HamanoAug 18, 2009

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.