shortlog: parse trailer idents
Trailers don't necessarily contain name/email identity values, so shortlog has so far treated them as opaque strings. However, since many trailers do contain identities, it's useful to treat them as such when they can be parsed. That lets "-e" work as usual, as well as mailmap. When they can't be parsed, we'll continue with the old behavior of treating them as a single string (there's no new test for that here, since the existing tests cover a trailer like this). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
87abb96222
commit
56d5dde752
@ -64,9 +64,10 @@ Likewise, commits with multiple trailers (e.g., multiple signoffs) may
|
|||||||
be counted more than once (but only once per unique trailer value in
|
be counted more than once (but only once per unique trailer value in
|
||||||
that commit).
|
that commit).
|
||||||
+
|
+
|
||||||
The contents of each trailer value are taken literally and completely.
|
Shortlog will attempt to parse each trailer value as a `name <email>`
|
||||||
No mailmap is applied, and the `-e` option has no effect (if the trailer
|
identity. If successful, the mailmap is applied and the email is omitted
|
||||||
contains a username and email, they are both always shown).
|
unless the `--email` option is specified. If the value cannot be parsed
|
||||||
|
as an identity, it will be taken literally and completely.
|
||||||
|
|
||||||
-c::
|
-c::
|
||||||
--committer::
|
--committer::
|
||||||
|
@ -228,6 +228,7 @@ static void insert_records_from_trailers(struct shortlog *log,
|
|||||||
struct trailer_iterator iter;
|
struct trailer_iterator iter;
|
||||||
const char *commit_buffer, *body;
|
const char *commit_buffer, *body;
|
||||||
struct strset dups = STRSET_INIT;
|
struct strset dups = STRSET_INIT;
|
||||||
|
struct strbuf ident = STRBUF_INIT;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Using format_commit_message("%B") would be simpler here, but
|
* Using format_commit_message("%B") would be simpler here, but
|
||||||
@ -245,12 +246,17 @@ static void insert_records_from_trailers(struct shortlog *log,
|
|||||||
if (strcasecmp(iter.key.buf, log->trailer))
|
if (strcasecmp(iter.key.buf, log->trailer))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
strbuf_reset(&ident);
|
||||||
|
if (!parse_ident(log, &ident, value))
|
||||||
|
value = ident.buf;
|
||||||
|
|
||||||
if (strset_check_and_add(&dups, value))
|
if (strset_check_and_add(&dups, value))
|
||||||
continue;
|
continue;
|
||||||
insert_one_record(log, value, oneline);
|
insert_one_record(log, value, oneline);
|
||||||
}
|
}
|
||||||
trailer_iterator_release(&iter);
|
trailer_iterator_release(&iter);
|
||||||
|
|
||||||
|
strbuf_release(&ident);
|
||||||
strset_clear(&dups);
|
strset_clear(&dups);
|
||||||
unuse_commit_buffer(commit, commit_buffer);
|
unuse_commit_buffer(commit, commit_buffer);
|
||||||
}
|
}
|
||||||
|
@ -230,10 +230,30 @@ test_expect_success 'shortlog --group=trailer:signed-off-by' '
|
|||||||
2 C O Mitter <committer@example.com>
|
2 C O Mitter <committer@example.com>
|
||||||
1 SOB One <sob@example.com>
|
1 SOB One <sob@example.com>
|
||||||
EOF
|
EOF
|
||||||
|
git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'trailer idents are split' '
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
2 C O Mitter
|
||||||
|
1 SOB One
|
||||||
|
EOF
|
||||||
git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
|
git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'trailer idents are mailmapped' '
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
2 C O Mitter
|
||||||
|
1 Another Name
|
||||||
|
EOF
|
||||||
|
echo "Another Name <sob@example.com>" >mail.map &&
|
||||||
|
git -c mailmap.file=mail.map shortlog -ns \
|
||||||
|
--group=trailer:signed-off-by HEAD >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'shortlog de-duplicates trailers in a single commit' '
|
test_expect_success 'shortlog de-duplicates trailers in a single commit' '
|
||||||
git commit --allow-empty -F - <<-\EOF &&
|
git commit --allow-empty -F - <<-\EOF &&
|
||||||
subject one
|
subject one
|
||||||
|
Loading…
Reference in New Issue
Block a user