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

[PATCH v5 7/8] pretty: add pointer and tag options to %(decorate)

From
Andy Koppe <andy.koppe@gmail.com>
Date
Aug 20, 2023, 18:50 UTC
Message-ID
<20230820185009.20095-8-andy.koppe@gmail.com>
In-Reply-To
<20230820185009.20095-1-andy.koppe@gmail.com>

Add pointer and tag options to %(decorate) format, to allow to override the " -> " string used to show where HEAD points and the "tag: " string used to mark tags.

Document in pretty-formats.txt and test in t4205-log-pretty-formats.sh.
Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
---
 Documentation/pretty-formats.txt |  9 +++++++++
 log-tree.c                       | 12 +++++++++---
 log-tree.h                       |  2 ++
 pretty.c                         |  6 +++++-
 t/t4205-log-pretty-formats.sh    |  7 ++++++-
 5 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 709d85af21..d38b4ab566 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -233,6 +233,15 @@ parentheses (`%x29`), due to their role in the option syntax.
 ** 'prefix=<value>': Shown before the list of ref names.  Defaults to "{nbsp}`(`".
 ** 'suffix=<value>': Shown after the list of ref names.  Defaults to "`)`".
 ** 'separator=<value>': Shown between ref names.  Defaults to "`,`{nbsp}".
+** 'pointer=<value>': Shown between HEAD and the branch it points to, if any.
+		      Defaults to "{nbsp}`->`{nbsp}".
+** 'tag=<value>': Shown before tag names. Defaults to "`tag:`{nbsp}".
+
++
+For example, to produce decorations with no wrapping
+or tag annotations, and spaces as separators:
++
+`%(decorate:prefix=,suffix=,tag=,separator= )`
 
 '%(describe[:<options>])'::
 human-readable name, like linkgit:git-describe[1]; empty string for
diff --git a/log-tree.c b/log-tree.c
index 44f4693567..50b4850eda 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -317,6 +317,8 @@ void format_decorations(struct strbuf *sb,
 	const char *prefix = " (";
 	const char *suffix = ")";
 	const char *separator = ", ";
+	const char *pointer = " -> ";
+	const char *tag = "tag: ";
 
 	decoration = get_name_decoration(&commit->object);
 	if (!decoration)
@@ -329,6 +331,10 @@ void format_decorations(struct strbuf *sb,
 			suffix = opts->suffix;
 		if (opts->separator)
 			separator = opts->separator;
+		if (opts->pointer)
+			pointer = opts->pointer;
+		if (opts->tag)
+			tag = opts->tag;
 	}
 
 	color_commit = diff_get_color(use_color, DIFF_COMMIT);
@@ -351,9 +357,9 @@ void format_decorations(struct strbuf *sb,
 				strbuf_addstr(sb, color_reset);
 			}
 
-			if (decoration->type == DECORATION_REF_TAG) {
+			if (*tag && decoration->type == DECORATION_REF_TAG) {
 				strbuf_addstr(sb, color);
-				strbuf_addstr(sb, "tag: ");
+				strbuf_addstr(sb, tag);
 				strbuf_addstr(sb, color_reset);
 			}
 
@@ -364,7 +370,7 @@ void format_decorations(struct strbuf *sb,
 			if (current_and_HEAD &&
 			    decoration->type == DECORATION_REF_HEAD) {
 				strbuf_addstr(sb, color);
-				strbuf_addstr(sb, " -> ");
+				strbuf_addstr(sb, pointer);
 				strbuf_addstr(sb, color_reset);
 				strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
 				show_name(sb, current_and_HEAD);
diff --git a/log-tree.h b/log-tree.h
index 14898de8ac..41c776fea5 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -17,6 +17,8 @@ struct decoration_options {
 	char *prefix;
 	char *suffix;
 	char *separator;
+	char *pointer;
+	char *tag;
 };
 
 int parse_decorate_color_config(const char *var, const char *slot_name, const char *value);
diff --git a/pretty.c b/pretty.c
index 1639efe2f8..7f3abb676c 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1407,7 +1407,9 @@ static void parse_decoration_options(const char **arg,
 {
 	while (parse_decoration_option(arg, "prefix", &opts->prefix) ||
 	       parse_decoration_option(arg, "suffix", &opts->suffix) ||
-	       parse_decoration_option(arg, "separator", &opts->separator))
+	       parse_decoration_option(arg, "separator", &opts->separator) ||
+	       parse_decoration_option(arg, "pointer", &opts->pointer) ||
+	       parse_decoration_option(arg, "tag", &opts->tag))
 		;
 }
 
@@ -1416,6 +1418,8 @@ static void free_decoration_options(const struct decoration_options *opts)
 	free(opts->prefix);
 	free(opts->suffix);
 	free(opts->separator);
+	free(opts->pointer);
+	free(opts->tag);
 }
 
 static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 6ba399c5be..16626e4fe9 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -600,7 +600,12 @@ test_expect_success 'pretty format %decorate' '
 	echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 &&
 	git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \
 		-1 >actual4 &&
-	test_cmp expect4 actual4
+	test_cmp expect4 actual4 &&
+
+	echo "HEAD->foo bar qux" >expect5 &&
+	git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \
+		-1 >actual5 &&
+	test_cmp expect5 actual5
 '
 
 cat >trailers <<EOF
-- 
2.42.0-rc2
Previous: Andy KoppeNext: Junio C Hamano
Message 56 of 59 in “pretty: add %(decorate[:<options>]) format”
  1. pretty: add %(decorate[:<options>]) formatAndy Koppe, Jul 15, 2023
  2. pretty: add %(decorate[:<options>]) formatAndy Koppe, Jul 15, 2023
  3. Junio C HamanoJul 17, 2023
  4. Junio C HamanoJul 18, 2023
  5. Andy KoppeAug 11, 2023
  6. Glen ChooJul 19, 2023
  7. Phillip WoodJul 23, 2023
  8. Andy KoppeAug 11, 2023
  9. Junio C HamanoAug 11, 2023
  10. Andy KoppeAug 11, 2023
  11. Junio C HamanoAug 12, 2023
  12. Andy KoppeAug 11, 2023
  13. Junio C HamanoAug 15, 2023
  14. Andy KoppeAug 15, 2023
  15. Junio C HamanoAug 15, 2023
  16. main != master at github.com/git/gitAndy Koppe, Aug 15, 2023
  17. Taylor BlauAug 15, 2023
  18. Jeff KingAug 16, 2023
  19. rsbecker@nexbridge.comAug 16, 2023
  20. Junio C HamanoAug 18, 2023
  21. Johannes SchindelinAug 21, 2023
  22. Junio C HamanoAug 21, 2023
  23. ci: avoid building from the same commit in parallelJunio C Hamano, Aug 22, 2023
  24. Junio C HamanoAug 22, 2023
  25. Johannes SchindelinAug 22, 2023
  26. Junio C HamanoAug 22, 2023
  27. Johannes SchindelinAug 23, 2023
  28. Junio C HamanoAug 23, 2023
  29. Junio C HamanoAug 23, 2023
  30. Johannes SchindelinAug 25, 2023
  31. 1/7 pretty-formats: define "literal formatting code"Andy Koppe, Aug 10, 2023
  32. 2/7 pretty-formats: enclose options in angle bracketsAndy Koppe, Aug 10, 2023
  33. 4/7 decorate: avoid some unnecessary color overheadAndy Koppe, Aug 10, 2023
  34. 3/7 decorate: refactor format_decorations()Andy Koppe, Aug 10, 2023
  35. 6/7 pretty: add %(decorate[:<options>]) formatAndy Koppe, Aug 10, 2023
  36. 5/7 decorate: color each token separatelyAndy Koppe, Aug 10, 2023
  37. 7/7 pretty: add pointer and tag options to %(decorate)Andy Koppe, Aug 10, 2023
  38. Junio C HamanoAug 16, 2023
  39. 0/8 pretty: add %(decorate[:<options>]) formatAndy Koppe, Aug 20, 2023
  40. 1/8 pretty-formats: define "literal formatting code"Andy Koppe, Aug 20, 2023
  41. 2/8 pretty-formats: enclose options in angle bracketsAndy Koppe, Aug 20, 2023
  42. 5/8 decorate: color each token separatelyAndy Koppe, Aug 20, 2023
  43. 4/8 decorate: avoid some unnecessary color overheadAndy Koppe, Aug 20, 2023
  44. 3/8 decorate: refactor format_decorations()Andy Koppe, Aug 20, 2023
  45. 6/8 pretty: add %(decorate[:<options>]) formatAndy Koppe, Aug 20, 2023
  46. 7/8 pretty: add pointer and tag options to %(decorate)Andy Koppe, Aug 20, 2023
  47. 8/8 decorate: use commit color for HEAD arrowAndy Koppe, Aug 20, 2023
  48. 0/8 pretty: add %(decorate[:<options>]) formatAndy Koppe, Aug 20, 2023
  49. 1/8 pretty-formats: define "literal formatting code"Andy Koppe, Aug 20, 2023
  50. 2/8 pretty-formats: enclose options in angle bracketsAndy Koppe, Aug 20, 2023
  51. 4/8 decorate: avoid some unnecessary color overheadAndy Koppe, Aug 20, 2023
  52. 5/8 decorate: color each token separatelyAndy Koppe, Aug 20, 2023
  53. 3/8 decorate: refactor format_decorations()Andy Koppe, Aug 20, 2023
  54. 6/8 pretty: add %(decorate[:<options>]) formatAndy Koppe, Aug 20, 2023
  55. 8/8 decorate: use commit color for HEAD arrowAndy Koppe, Aug 20, 2023
  56. 7/8 pretty: add pointer and tag options to %(decorate)Andy Koppe, Aug 20, 2023
  57. Junio C HamanoAug 29, 2023
  58. Andy KoppeSep 1, 2023
  59. Junio C HamanoAug 21, 2023

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.