@@ -216,6 +216,8 @@ endif::git-rev-list[]
** 'key=<K>': only show trailers with specified key. Matching is
done case-insensitively and trailing colon is optional. If option
is given multiple times only last one is used.
+ ** 'valueonly': skip over the key part of the trailer and only show
+ the its value part.
** Examples: `%(trailers:only,unfold)` unfolds and shows all trailer
lines, `%(trailers:key=Reviewed-by,unfold)` unfolds and shows
trailer lines with key `Reviewed-by`.
@@ -1335,6 +1335,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
opts.only_trailers = 1;
else if (match_placeholder_arg(arg, "unfold", &arg))
opts.unfold = 1;
+ else if (match_placeholder_arg(arg, "valueonly", &arg))
+ opts.value_only = 1;
else if (skip_prefix(arg, "key=", &arg)) {
const char *end = arg + strcspn(arg, ",)");
@@ -634,6 +634,12 @@ test_expect_success '%(trailers:key=foo,unfold) properly unfolds' '
test_cmp expect actual
'
+test_expect_success '%(trailers:key=foo,valueonly) shows only value' '
+ git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual &&
+ echo "A U Thor <author@example.com>" >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'trailer parsing not fooled by --- line' '
git commit --allow-empty -F - <<-\EOF &&
this is the subject
@@ -1150,8 +1150,10 @@ static void format_trailer_info(struct strbuf *out,
if (!opts->filter || opts->filter(&tok, opts->filter_data)) {
if (opts->unfold)
unfold_value(&val);
-
- strbuf_addf(out, "%s: %s\n", tok.buf, val.buf);
+ if (!opts->value_only)
+ strbuf_addf(out, "%s: ", tok.buf);
+ strbuf_addbuf(out, &val);
+ strbuf_addch(out, '\n');
}
strbuf_release(&tok);
strbuf_release(&val);
@@ -72,6 +72,7 @@ struct process_trailer_options {
int only_input;
int unfold;
int no_divider;
+ int value_only;
int (*filter)(const struct strbuf *, void *);
void *filter_data;
};