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>
Jeff King committed
Sep 27, 2020 at 04:40 UTC
56d5dde7526e725a9e590f32fe38ce6b3391bc36
3 files changed
+30
-3
Documentation/git-shortlog.txt
+4
-3
@@ -64,9 +64,10 @@ Likewise, commits with multiple trailers (e.g., multiple signoffs) may
64
be counted more than once (but only once per unique trailer value in
65
that commit).
66
+
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.
71
72
-c::
73
--committer::
builtin/shortlog.c
+6
@@ -228,6 +228,7 @@ static void insert_records_from_trailers(struct shortlog *log,
228
struct trailer_iterator iter;
229
const char *commit_buffer, *body;
230
struct strset dups = STRSET_INIT;
231
+ struct strbuf ident = STRBUF_INIT;
232
233
/*
234
* Using format_commit_message("%B") would be simpler here, but
@@ -245,12 +246,17 @@ static void insert_records_from_trailers(struct shortlog *log,
246
if (strcasecmp(iter.key.buf, log->trailer))
247
continue;
248
249
+ strbuf_reset(&ident);
250
+ if (!parse_ident(log, &ident, value))
251
+ value = ident.buf;
252
+
253
if (strset_check_and_add(&dups, value))
254
continue;
255
insert_one_record(log, value, oneline);
256
}
257
trailer_iterator_release(&iter);
258
259
+ strbuf_release(&ident);
260
strset_clear(&dups);
261
unuse_commit_buffer(commit, commit_buffer);
262
}
t/t4201-shortlog.sh
+20
@@ -230,10 +230,30 @@ test_expect_success 'shortlog --group=trailer:signed-off-by' '
230
2 C O Mitter <committer@example.com>
231
1 SOB One <sob@example.com>
232
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
242
git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
243
test_cmp expect actual
244
'
245
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 <sob@example.com>" >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
+
257
test_expect_success 'shortlog de-duplicates trailers in a single commit' '
258
git commit --allow-empty -F - <<-\EOF &&
259
subject one