Skip to content

Commit 56d5dde

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87abb96 commit 56d5dde

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Documentation/git-shortlog.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ Likewise, commits with multiple trailers (e.g., multiple signoffs) may
6464
be counted more than once (but only once per unique trailer value in
6565
that commit).
6666
+
67-
The contents of each trailer value are taken literally and completely.
68-
No mailmap is applied, and the `-e` option has no effect (if the trailer
69-
contains a username and email, they are both always shown).
67+
Shortlog will attempt to parse each trailer value as a `name <email>`
68+
identity. If successful, the mailmap is applied and the email is omitted
69+
unless the `--email` option is specified. If the value cannot be parsed
70+
as an identity, it will be taken literally and completely.
7071

7172
-c::
7273
--committer::

builtin/shortlog.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static void insert_records_from_trailers(struct shortlog *log,
228228
struct trailer_iterator iter;
229229
const char *commit_buffer, *body;
230230
struct strset dups = STRSET_INIT;
231+
struct strbuf ident = STRBUF_INIT;
231232

232233
/*
233234
* Using format_commit_message("%B") would be simpler here, but
@@ -245,12 +246,17 @@ static void insert_records_from_trailers(struct shortlog *log,
245246
if (strcasecmp(iter.key.buf, log->trailer))
246247
continue;
247248

249+
strbuf_reset(&ident);
250+
if (!parse_ident(log, &ident, value))
251+
value = ident.buf;
252+
248253
if (strset_check_and_add(&dups, value))
249254
continue;
250255
insert_one_record(log, value, oneline);
251256
}
252257
trailer_iterator_release(&iter);
253258

259+
strbuf_release(&ident);
254260
strset_clear(&dups);
255261
unuse_commit_buffer(commit, commit_buffer);
256262
}

t/t4201-shortlog.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,30 @@ test_expect_success 'shortlog --group=trailer:signed-off-by' '
230230
2 C O Mitter <[email protected]>
231231
1 SOB One <[email protected]>
232232
EOF
233+
git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
234+
test_cmp expect actual
235+
'
236+
237+
test_expect_success 'trailer idents are split' '
238+
cat >expect <<-\EOF &&
239+
2 C O Mitter
240+
1 SOB One
241+
EOF
233242
git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
234243
test_cmp expect actual
235244
'
236245

246+
test_expect_success 'trailer idents are mailmapped' '
247+
cat >expect <<-\EOF &&
248+
2 C O Mitter
249+
1 Another Name
250+
EOF
251+
echo "Another Name <[email protected]>" >mail.map &&
252+
git -c mailmap.file=mail.map shortlog -ns \
253+
--group=trailer:signed-off-by HEAD >actual &&
254+
test_cmp expect actual
255+
'
256+
237257
test_expect_success 'shortlog de-duplicates trailers in a single commit' '
238258
git commit --allow-empty -F - <<-\EOF &&
239259
subject one

0 commit comments

Comments
 (0)