summaryrefslogtreecommitdiff
path: root/trailer.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-08-15 10:25:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-08-15 18:13:58 (GMT)
commit58311c66fd316dff8f2c68a634ca0cf968227870 (patch)
tree64097b270164843eab9b680239a74f83a0586e45 /trailer.c
parentcc1735c4a3cf3377289640ce1af6b4c4523bee11 (diff)
downloadgit-58311c66fd316dff8f2c68a634ca0cf968227870.zip
git-58311c66fd316dff8f2c68a634ca0cf968227870.tar.gz
git-58311c66fd316dff8f2c68a634ca0cf968227870.tar.bz2
pretty: support normalization options for %(trailers)
The interpret-trailers command recently learned some options to make its output easier to parse (for a caller whose only interested in picking out the trailer values). But it's not very efficient for asking for the trailers of many commits in a single invocation. We already have "%(trailers)" to do that, but it doesn't know about unfolding or omitting non-trailers. Let's plumb those options through, so you can have the best of both. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'trailer.c')
-rw-r--r--trailer.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/trailer.c b/trailer.c
index 07580af..6ec5505 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1095,8 +1095,36 @@ static void format_trailer_info(struct strbuf *out,
const struct trailer_info *info,
const struct process_trailer_options *opts)
{
- strbuf_add(out, info->trailer_start,
- info->trailer_end - info->trailer_start);
+ int i;
+
+ /* If we want the whole block untouched, we can take the fast path. */
+ if (!opts->only_trailers && !opts->unfold) {
+ strbuf_add(out, info->trailer_start,
+ info->trailer_end - info->trailer_start);
+ return;
+ }
+
+ for (i = 0; i < info->trailer_nr; i++) {
+ char *trailer = info->trailers[i];
+ int separator_pos = find_separator(trailer, separators);
+
+ if (separator_pos >= 1) {
+ struct strbuf tok = STRBUF_INIT;
+ struct strbuf val = STRBUF_INIT;
+
+ parse_trailer(&tok, &val, NULL, trailer, separator_pos);
+ if (opts->unfold)
+ unfold_value(&val);
+
+ strbuf_addf(out, "%s: %s\n", tok.buf, val.buf);
+ strbuf_release(&tok);
+ strbuf_release(&val);
+
+ } else if (!opts->only_trailers) {
+ strbuf_addstr(out, trailer);
+ }
+ }
+
}
void format_trailers_from_commit(struct strbuf *out, const char *msg,