Skip to content

Commit ffee36a

Browse files
committed
handle %(trailers:mailmap)
Signed-off-by: Jeff King <[email protected]>
1 parent 7c7698a commit ffee36a

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

pretty.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ int format_set_trailers_options(struct process_trailer_options *opts,
12961296
for (;;) {
12971297
const char *argval;
12981298
size_t arglen;
1299+
int bool_arg;
12991300

13001301
if (**arg == ')')
13011302
break;
@@ -1317,6 +1318,15 @@ int format_set_trailers_options(struct process_trailer_options *opts,
13171318
opts->separator = expand_string_arg(sepbuf, argval, arglen);
13181319
} else if (match_placeholder_arg_value(*arg, "key_value_separator", arg, &argval, &arglen)) {
13191320
opts->key_value_separator = expand_string_arg(kvsepbuf, argval, arglen);
1321+
} else if (match_placeholder_bool_arg(*arg, "mailmap", arg, &bool_arg)) {
1322+
if (bool_arg) {
1323+
/* yuck but this is how mailmap_name() above does it */
1324+
static struct string_list mailmap = STRING_LIST_INIT_DUP;
1325+
read_mailmap(&mailmap);
1326+
opts->mailmap = &mailmap;
1327+
} else {
1328+
opts->mailmap = NULL;
1329+
}
13201330
} else if (!match_placeholder_bool_arg(*arg, "only", arg, &opts->only_trailers) &&
13211331
!match_placeholder_bool_arg(*arg, "unfold", arg, &opts->unfold) &&
13221332
!match_placeholder_bool_arg(*arg, "keyonly", arg, &opts->key_only) &&

trailer.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "commit.h"
1010
#include "trailer.h"
1111
#include "list.h"
12+
#include "mailmap.h"
13+
#include "ident.h"
14+
1215
/*
1316
* Copyright (c) 2013, 2014 Christian Couder <[email protected]>
1417
*/
@@ -1107,6 +1110,29 @@ void trailer_block_release(struct trailer_block *trailer_block)
11071110
free(trailer_block);
11081111
}
11091112

1113+
static int mailmap_value(struct string_list *mailmap,
1114+
struct strbuf *out, const struct strbuf *in)
1115+
{
1116+
const char *mailbuf, *namebuf;
1117+
size_t namelen, maillen;
1118+
struct ident_split ident;
1119+
1120+
if (split_ident_line(&ident, in->buf, in->len))
1121+
return -1; /* not an ident */
1122+
1123+
namebuf = ident.name_begin;
1124+
namelen = ident.name_end - ident.name_begin;
1125+
mailbuf = ident.mail_begin;
1126+
maillen = ident.mail_end - ident.mail_begin;
1127+
1128+
map_user(mailmap, &mailbuf, &maillen, &namebuf, &namelen);
1129+
strbuf_add(out, namebuf, namelen);
1130+
strbuf_addstr(out, " <");
1131+
strbuf_add(out, mailbuf, maillen);
1132+
strbuf_addch(out, '>');
1133+
return 0;
1134+
}
1135+
11101136
void format_trailers(const struct process_trailer_options *opts,
11111137
struct list_head *trailers,
11121138
struct strbuf *out)
@@ -1148,8 +1174,11 @@ void format_trailers(const struct process_trailer_options *opts,
11481174
strbuf_addf(out, "%c ", separators[0]);
11491175
}
11501176
}
1151-
if (!opts->key_only)
1152-
strbuf_addbuf(out, &val);
1177+
if (!opts->key_only) {
1178+
if (!opts->mailmap ||
1179+
mailmap_value(opts->mailmap, out, &val) < 0)
1180+
strbuf_addbuf(out, &val);
1181+
}
11531182
if (!opts->separator)
11541183
strbuf_addch(out, '\n');
11551184
}
@@ -1179,7 +1208,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts,
11791208
/* If we want the whole block untouched, we can take the fast path. */
11801209
if (!opts->only_trailers && !opts->unfold && !opts->filter &&
11811210
!opts->separator && !opts->key_only && !opts->value_only &&
1182-
!opts->key_value_separator) {
1211+
!opts->key_value_separator && !opts->mailmap) {
11831212
strbuf_add(out, msg + trailer_block->start,
11841213
trailer_block->end - trailer_block->start);
11851214
} else

trailer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct process_trailer_options {
5555
int no_divider;
5656
int key_only;
5757
int value_only;
58+
struct string_list *mailmap;
5859
const struct strbuf *separator;
5960
const struct strbuf *key_value_separator;
6061
int (*filter)(const struct strbuf *, void *);

0 commit comments

Comments
 (0)