add '%d' pretty format specifier to show decoration
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Sep 4, 2008 at 23:40 UTC
3b3d443feb1e7464c81e9a29c9b237cd6fa01fe5
2 files changed
+22
Documentation/pretty-formats.txt
+1
@@ -116,6 +116,7 @@ The placeholders are:
116
- '%cr': committer date, relative
117
- '%ct': committer date, UNIX timestamp
118
- '%ci': committer date, ISO 8601 format
119
+- '%d': ref names, like the --decorate option of linkgit:git-log[1]
120
- '%e': encoding
121
- '%s': subject
122
- '%b': body
pretty.c
+21
@@ -5,6 +5,7 @@
5
#include "revision.h"
6
#include "string-list.h"
7
#include "mailmap.h"
8
+#include "log-tree.h"
9
10
static char *user_format;
11
@@ -481,6 +482,23 @@ static void parse_commit_header(struct format_commit_context *context)
482
context->commit_header_parsed = 1;
483
}
484
485
+static void format_decoration(struct strbuf *sb, const struct commit *commit)
486
+{
487
+ struct name_decoration *d;
488
+ const char *prefix = " (";
489
+
490
+ load_ref_decorations();
491
+ d = lookup_decoration(&name_decoration, &commit->object);
492
+ while (d) {
493
+ strbuf_addstr(sb, prefix);
494
+ prefix = ", ";
495
+ strbuf_addstr(sb, d->name);
496
+ d = d->next;
497
+ }
498
+ if (prefix[0] == ',')
499
+ strbuf_addch(sb, ')');
500
+}
501
+
502
static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
503
void *context)
504
{
@@ -573,6 +591,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
591
? '<'
592
: '>');
593
return 1;
594
+ case 'd':
595
+ format_decoration(sb, commit);
596
+ return 1;
597
}
598
599
/* For the rest we have to parse the commit header. */