summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorJacob Keller <jacob.keller@gmail.com>2016-11-19 00:58:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-12-11 21:58:41 (GMT)
commitd9f31fbfe98e0e363a3c69aaf6badecc746afe6b (patch)
treee8aeacdbd2aae73e2ffc4f9497c19e321e1548e3 /pretty.c
parent967dfd4d568c2b102281de8cc22ee35f7558358b (diff)
downloadgit-d9f31fbfe98e0e363a3c69aaf6badecc746afe6b.zip
git-d9f31fbfe98e0e363a3c69aaf6badecc746afe6b.tar.gz
git-d9f31fbfe98e0e363a3c69aaf6badecc746afe6b.tar.bz2
pretty: add %(trailers) format for displaying trailers of a commit message
Recent patches have expanded on the trailers.c code and we have the builtin commant git-interpret-trailers which can be used to add or modify trailer lines. However, there is no easy way to simply display the trailers of a commit message. Add support for %(trailers) format modifier which will use the trailer_info_get() calls to read trailers in an identical way as git interpret-trailers does. Use a long format option instead of a short name so that future work can more easily unify ref-filter and pretty formats. Add documentation and tests for the same. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/pretty.c b/pretty.c
index 37b2c3b..5e68383 100644
--- a/pretty.c
+++ b/pretty.c
@@ -10,6 +10,7 @@
#include "color.h"
#include "reflog-walk.h"
#include "gpg-interface.h"
+#include "trailer.h"
static char *user_format;
static struct cmt_fmt_map {
@@ -889,6 +890,16 @@ const char *format_subject(struct strbuf *sb, const char *msg,
return msg;
}
+static void format_trailers(struct strbuf *sb, const char *msg)
+{
+ struct trailer_info info;
+
+ trailer_info_get(&info, msg);
+ strbuf_add(sb, info.trailer_start,
+ info.trailer_end - info.trailer_start);
+ trailer_info_release(&info);
+}
+
static void parse_commit_message(struct format_commit_context *c)
{
const char *msg = c->message + c->message_off;
@@ -1292,6 +1303,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
strbuf_addstr(sb, msg + c->body_off);
return 1;
}
+
+ if (starts_with(placeholder, "(trailers)")) {
+ format_trailers(sb, msg + c->subject_off);
+ return strlen("(trailers)");
+ }
+
return 0; /* unknown placeholder */
}