pretty, ref-filter: format %(trailers) with no_divider option
In both of these cases we know that we are feeding the trailer-parsing code a pure commit message. We should tell it so, which avoids false positives for a commit message that contains a "---" line. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1688c9a489
commit
e5fba5d558
3
pretty.c
3
pretty.c
@ -1304,6 +1304,9 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
|
|||||||
|
|
||||||
if (skip_prefix(placeholder, "(trailers", &arg)) {
|
if (skip_prefix(placeholder, "(trailers", &arg)) {
|
||||||
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
|
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
|
||||||
|
|
||||||
|
opts.no_divider = 1;
|
||||||
|
|
||||||
if (*arg == ':') {
|
if (*arg == ':') {
|
||||||
arg++;
|
arg++;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -223,6 +223,8 @@ static int trailers_atom_parser(const struct ref_format *format, struct used_ato
|
|||||||
struct string_list params = STRING_LIST_INIT_DUP;
|
struct string_list params = STRING_LIST_INIT_DUP;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
atom->u.contents.trailer_opts.no_divider = 1;
|
||||||
|
|
||||||
if (arg) {
|
if (arg) {
|
||||||
string_list_split(¶ms, arg, ',', -1);
|
string_list_split(¶ms, arg, ',', -1);
|
||||||
for (i = 0; i < params.nr; i++) {
|
for (i = 0; i < params.nr; i++) {
|
||||||
|
@ -598,4 +598,27 @@ test_expect_success ':only and :unfold work together' '
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'trailer parsing not fooled by --- line' '
|
||||||
|
git commit --allow-empty -F - <<-\EOF &&
|
||||||
|
this is the subject
|
||||||
|
|
||||||
|
This is the body. The message has a "---" line which would confuse a
|
||||||
|
message+patch parser. But here we know we have only a commit message,
|
||||||
|
so we get it right.
|
||||||
|
|
||||||
|
trailer: wrong
|
||||||
|
---
|
||||||
|
This is more body.
|
||||||
|
|
||||||
|
trailer: right
|
||||||
|
EOF
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "trailer: right" &&
|
||||||
|
echo
|
||||||
|
} >expect &&
|
||||||
|
git log --no-walk --format="%(trailers)" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
@ -715,6 +715,29 @@ test_expect_success 'basic atom: head contents:trailers' '
|
|||||||
test_cmp expect actual.clean
|
test_cmp expect actual.clean
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'trailer parsing not fooled by --- line' '
|
||||||
|
git commit --allow-empty -F - <<-\EOF &&
|
||||||
|
this is the subject
|
||||||
|
|
||||||
|
This is the body. The message has a "---" line which would confuse a
|
||||||
|
message+patch parser. But here we know we have only a commit message,
|
||||||
|
so we get it right.
|
||||||
|
|
||||||
|
trailer: wrong
|
||||||
|
---
|
||||||
|
This is more body.
|
||||||
|
|
||||||
|
trailer: right
|
||||||
|
EOF
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "trailer: right" &&
|
||||||
|
echo
|
||||||
|
} >expect &&
|
||||||
|
git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'Add symbolic ref for the following tests' '
|
test_expect_success 'Add symbolic ref for the following tests' '
|
||||||
git symbolic-ref refs/heads/sym refs/heads/master
|
git symbolic-ref refs/heads/sym refs/heads/master
|
||||||
'
|
'
|
||||||
|
Reference in New Issue
Block a user