summaryrefslogtreecommitdiff
path: root/trailer.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2017-08-15 06:25:27 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-08-15 11:13:58 -0700
commit58311c66fd316dff8f2c68a634ca0cf968227870 (patch)
tree64097b270164843eab9b680239a74f83a0586e45 /trailer.c
parentt4205: refactor %(trailers) tests (diff)
downloadtgif-58311c66fd316dff8f2c68a634ca0cf968227870.tar.xz
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 07580af9c0..6ec5505dc4 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,