Skip to content

Commit fab600c

Browse files
committed
Merge branch 'js/maint-pretty-mailmap'
* js/maint-pretty-mailmap: Add pretty format %aN which gives the author name, respecting .mailmap
2 parents 28ed6e7 + e0cbc39 commit fab600c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Documentation/pretty-formats.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ The placeholders are:
101101
- '%P': parent hashes
102102
- '%p': abbreviated parent hashes
103103
- '%an': author name
104+
- '%aN': author name (respecting .mailmap)
104105
- '%ae': author email
105106
- '%ad': author date
106107
- '%aD': author date, RFC2822 style
107108
- '%ar': author date, relative
108109
- '%at': author date, UNIX timestamp
109110
- '%ai': author date, ISO 8601 format
110111
- '%cn': committer name
112+
- '%cN': committer name (respecting .mailmap)
111113
- '%ce': committer email
112114
- '%cd': committer date
113115
- '%cD': committer date, RFC2822 style

pretty.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "utf8.h"
44
#include "diff.h"
55
#include "revision.h"
6+
#include "path-list.h"
7+
#include "mailmap.h"
68

79
static char *user_format;
810

@@ -288,6 +290,25 @@ static char *logmsg_reencode(const struct commit *commit,
288290
return out;
289291
}
290292

293+
static int mailmap_name(struct strbuf *sb, const char *email)
294+
{
295+
static struct path_list *mail_map;
296+
char buffer[1024];
297+
298+
if (!mail_map) {
299+
mail_map = xcalloc(1, sizeof(*mail_map));
300+
read_mailmap(mail_map, ".mailmap", NULL);
301+
}
302+
303+
if (!mail_map->nr)
304+
return -1;
305+
306+
if (!map_email(mail_map, email, buffer, sizeof(buffer)))
307+
return -1;
308+
strbuf_addstr(sb, buffer);
309+
return 0;
310+
}
311+
291312
static size_t format_person_part(struct strbuf *sb, char part,
292313
const char *msg, int len)
293314
{
@@ -309,10 +330,12 @@ static size_t format_person_part(struct strbuf *sb, char part,
309330
if (end >= len - 2)
310331
goto skip;
311332

312-
if (part == 'n') { /* name */
333+
if (part == 'n' || part == 'N') { /* name */
313334
while (end > 0 && isspace(msg[end - 1]))
314335
end--;
315-
strbuf_add(sb, msg, end);
336+
if (part != 'N' || !msg[end] || !msg[end + 1] ||
337+
mailmap_name(sb, msg + end + 2) < 0)
338+
strbuf_add(sb, msg, end);
316339
return placeholder_len;
317340
}
318341
start = ++end; /* save email start position */

0 commit comments

Comments
 (0)