From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Michael Dressel <MichaelTiloDressel@t-online.de>
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org
Subject: [PATCH 3/3] add '%d' pretty format specifier to show decoration
Date: Thu, 04 Sep 2008 23:40:03 +0200 [thread overview]
Message-ID: <48C055B3.3030204@lsrfire.ath.cx> (raw)
In-Reply-To: <48C002FB.9010401@lsrfire.ath.cx>
Add a new format placeholder, %d, which expands to a ref name decoration
(think git log --decorate). It expands to an empty string if the commit
has no decoration, or otherwise to a comma (and space) separated list of
decorations, surrounded by parentheses and a leading space.
Michael Dressel implemented an initial version and chose the letter d,
Junio suggested to add a leading space and parentheses.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
Documentation/pretty-formats.txt | 1 +
pretty.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 388d492..f18d33e 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': ref names, like the --decorate option of linkgit:git-log[1]
- '%e': encoding
- '%s': subject
- '%b': body
diff --git a/pretty.c b/pretty.c
index a29c290..8beafa0 100644
--- a/pretty.c
+++ b/pretty.c
@@ -5,6 +5,7 @@
#include "revision.h"
#include "string-list.h"
#include "mailmap.h"
+#include "log-tree.h"
static char *user_format;
@@ -481,6 +482,23 @@ static void parse_commit_header(struct format_commit_context *context)
context->commit_header_parsed = 1;
}
+static void format_decoration(struct strbuf *sb, const struct commit *commit)
+{
+ struct name_decoration *d;
+ const char *prefix = " (";
+
+ load_ref_decorations();
+ d = lookup_decoration(&name_decoration, &commit->object);
+ while (d) {
+ strbuf_addstr(sb, prefix);
+ prefix = ", ";
+ strbuf_addstr(sb, d->name);
+ d = d->next;
+ }
+ if (prefix[0] == ',')
+ strbuf_addch(sb, ')');
+}
+
static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
void *context)
{
@@ -573,6 +591,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
? '<'
: '>');
return 1;
+ case 'd':
+ format_decoration(sb, commit);
+ return 1;
}
/* For the rest we have to parse the commit header. */
--
1.6.0.1.161.g7f314
next prev parent reply other threads:[~2008-09-04 21:41 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-03 18:40 [PATCH 1/2] add '%d' pretty format specifier to show decoration Michael Dressel
2008-09-03 19:12 ` Jeff King
2008-09-03 20:10 ` Junio C Hamano
2008-09-03 20:36 ` Jeff King
2008-09-03 20:59 ` Junio C Hamano
2008-09-03 21:04 ` Jeff King
2008-09-03 22:06 ` René Scharfe
2008-09-04 3:51 ` Jeff King
2008-09-04 15:47 ` René Scharfe
2008-09-04 21:38 ` [PATCH 1/3] log: add load_ref_decorations() René Scharfe
2008-09-04 21:39 ` [PATCH 2/3] move load_ref_decorations() to log-tree.c and export it René Scharfe
2008-09-04 21:40 ` René Scharfe [this message]
2008-09-05 0:11 ` [PATCH 3/3] add '%d' pretty format specifier to show decoration Jeff King
2008-09-05 0:28 ` Junio C Hamano
2008-09-05 0:37 ` Jeff King
2008-09-05 0:41 ` Junio C Hamano
2008-09-05 18:38 ` Michael Dressel
2008-09-09 17:33 ` Michael Dressel
2008-09-09 20:15 ` René Scharfe
2008-09-05 16:14 ` René Scharfe
2008-09-03 19:17 ` [PATCH 1/2] " Jeff King
2008-09-03 20:06 ` Michael Dressel
2008-09-03 20:33 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48C055B3.3030204@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=MichaelTiloDressel@t-online.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).