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

[PATCH 2/2] allow '%d' pretty format specifier to show decoration

From
Jeff King <peff@peff.net>
Date
Aug 20, 2008, 18:00 UTC
Message-ID
<20080820180034.GB32005@sigill.intra.peff.net>
In-Reply-To
<20080820175325.GD27773@sigill.intra.peff.net>
Previously, specifying
  git log --pretty=format:'%H %s' --decorate

would calculate decorations, but not show them. You can now do:

  git log --pretty=format:'%H (%d) %s' --decorate
to see them.
Signed-off-by: Jeff King <peff@peff.net>
---
There is a lot of room for discussion here.
For example:
  - what should %d show? Right now it shows each decoration, split by
    commas. It doesn't show the enclosing parentheses automatically.
    Is this too strict? Should there be some way of pulling out
    individual decorations from the list, or specifying a different
    delimiter? If so, probably that should be part of a general
    improvement in the format expansion macro language.
    Is it too loose? Perhaps the enclosing parentheses should be
    automatic, so that %d expands to nothing if there is no decoration,
    or the whole thing otherwise. Right now you are stuck with empty ()
    if there is no decoration. Alternatively, we could support some kind
    of conditional expansion in the formatting language (but I don't
    know how crazy we want to get wit new formatting features).
  - should this turn on --decorate automatically? If you use '%d'
    without --decorate, you will just get no decorations. I think that
    makes sense, though, since that opens room for specifying other
    types of decorations (e.g., there could be a --decorate-tags that
    only looks at tags).
 Documentation/pretty-formats.txt |    1 +
 pretty.c                         |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index c11d495..55a5954 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -116,6 +116,7 @@ The placeholders are:
 - '%cr': committer date, relative
 - '%ct': committer date, UNIX timestamp
 - '%ci': committer date, ISO 8601 format
+- '%d': decoration (if you specified --decorate)
 - '%e': encoding
 - '%s': subject
 - '%b': body
diff --git a/pretty.c b/pretty.c
index 33ef34a..00f19e1 100644
--- a/pretty.c
+++ b/pretty.c
@@ -519,6 +519,21 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 			return 3;
 		} else
 			return 0;
+	case 'd':
+		{
+			struct name_decoration *d;
+			const char *prefix = "";
+			d = lookup_decoration(&name_decoration,
+					&commit->object);
+			while (d) {
+				strbuf_addstr(sb, prefix);
+				prefix = ", ";
+				strbuf_addstr(sb, d->name);
+				d = d->next;
+			}
+		}
+		return 1;
+
 	}
 
 	/* these depend on the commit */
-- 
1.6.0.90.g00a5c.dirty
Previous: Jeff KingNext: Junio C Hamano
Message 4 of 14 in “[BUG?] git log does not decorate when custom format is used”
  1. MichaelTiloDressel@t-online.deAug 20, 2008
  2. Jeff KingAug 20, 2008
  3. 1/2 decorate: allow const objects to be decoratedJeff King, Aug 20, 2008
  4. 2/2 allow '%d' pretty format specifier to show decorationJeff King, Aug 20, 2008
  5. Junio C HamanoAug 20, 2008
  6. Johannes SchindelinAug 20, 2008
  7. Junio C HamanoAug 20, 2008
  8. Johannes SchindelinAug 20, 2008
  9. Jeff KingSep 3, 2008
  10. Michael DresselAug 20, 2008
  11. Junio C HamanoAug 20, 2008
  12. Michael DresselAug 20, 2008
  13. "log --pretty=format:" languageTeemu Likonen, Aug 21, 2008
  14. Jakub NarebskiAug 24, 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.