|
9 | 9 | #include "commit.h" |
10 | 10 | #include "trailer.h" |
11 | 11 | #include "list.h" |
| 12 | +#include "mailmap.h" |
| 13 | +#include "ident.h" |
| 14 | + |
12 | 15 | /* |
13 | 16 | * Copyright (c) 2013, 2014 Christian Couder <[email protected]> |
14 | 17 | */ |
@@ -1107,6 +1110,29 @@ void trailer_block_release(struct trailer_block *trailer_block) |
1107 | 1110 | free(trailer_block); |
1108 | 1111 | } |
1109 | 1112 |
|
| 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 | + |
1110 | 1136 | void format_trailers(const struct process_trailer_options *opts, |
1111 | 1137 | struct list_head *trailers, |
1112 | 1138 | struct strbuf *out) |
@@ -1148,8 +1174,11 @@ void format_trailers(const struct process_trailer_options *opts, |
1148 | 1174 | strbuf_addf(out, "%c ", separators[0]); |
1149 | 1175 | } |
1150 | 1176 | } |
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 | + } |
1153 | 1182 | if (!opts->separator) |
1154 | 1183 | strbuf_addch(out, '\n'); |
1155 | 1184 | } |
@@ -1179,7 +1208,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, |
1179 | 1208 | /* If we want the whole block untouched, we can take the fast path. */ |
1180 | 1209 | if (!opts->only_trailers && !opts->unfold && !opts->filter && |
1181 | 1210 | !opts->separator && !opts->key_only && !opts->value_only && |
1182 | | - !opts->key_value_separator) { |
| 1211 | + !opts->key_value_separator && !opts->mailmap) { |
1183 | 1212 | strbuf_add(out, msg + trailer_block->start, |
1184 | 1213 | trailer_block->end - trailer_block->start); |
1185 | 1214 | } else |
|
0 commit comments