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

[PATCH 2/2] pretty=format: Add %d to show decoration

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 7, 2008, 13:41 UTC
Message-ID
<alpine.DEB.1.00.0804071441040.430@eeepc-johanness>
In-Reply-To
<alpine.DEB.1.00.0804071439480.430@eeepc-johanness>

With this patch, "git log --decorate --pretty=format:%d", shows the name decoration (i.e. whenever a commit matches a ref, that ref's name is shown).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	Maybe %d should expand to " (<name decoration>)" instead of
	"<name decoration>"?
 Documentation/pretty-formats.txt |    1 +
 pretty.c                         |    9 +++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index e8bea3e..9d8a8d4 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -117,6 +117,7 @@ The placeholders are:
 - '%e': encoding
 - '%s': subject
 - '%b': body
+- '%d': decoration (needs --decorate)
 - '%Cred': switch color to red
 - '%Cgreen': switch color to green
 - '%Cblue': switch color to blue
diff --git a/pretty.c b/pretty.c
index 6c04176..37f7c3e 100644
--- a/pretty.c
+++ b/pretty.c
@@ -489,6 +489,15 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 			return 3;
 		} else
 			return 0;
+	case 'd':
+		{
+			struct name_decoration *decoration =
+				lookup_decoration(&name_decoration,
+				&commit->object);
+			if (decoration)
+				strbuf_addstr(sb, decoration->name);
+			return 1;
+		}
 	}
 
 	/* these depend on the commit */
-- 
1.5.5.rc0.208.g1d50
Previous: Johannes SchindelinNext: René Scharfe
Message 2 of 4 in “decorate: use "const struct object"”
  1. 1/2 decorate: use "const struct object"Johannes Schindelin, Apr 7, 2008
  2. 2/2 pretty=format: Add %d to show decorationJohannes Schindelin, Apr 7, 2008
  3. René ScharfeApr 9, 2008
  4. Junio C HamanoApr 10, 2008

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.