Add pretty format %aN which gives the author name, respecting .mailmap
The pretty format %an does not respect .mailmap, but gives the exact author name recorded in the commit. Sometimes it is more desirable, however, to look if the email has another name mapped to it in .mailmap. This commit adds %aN (and %cN for the committer name) to do exactly that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jul 12, 2008 at 00:28 UTC
e0cbc39768884a1e7edcf2dbf6e6825c4b23485a
2 files changed
+27
-2
Documentation/pretty-formats.txt
+2
@@ -101,6 +101,7 @@ The placeholders are:
101
- '%P': parent hashes
102
- '%p': abbreviated parent hashes
103
- '%an': author name
104
+- '%aN': author name (respecting .mailmap)
105
- '%ae': author email
106
- '%ad': author date
107
- '%aD': author date, RFC2822 style
@@ -108,6 +109,7 @@ The placeholders are:
109
- '%at': author date, UNIX timestamp
110
- '%ai': author date, ISO 8601 format
111
- '%cn': committer name
112
+- '%cN': committer name (respecting .mailmap)
113
- '%ce': committer email
114
- '%cd': committer date
115
- '%cD': committer date, RFC2822 style
pretty.c
+25
-2
@@ -3,6 +3,8 @@
3
#include "utf8.h"
4
#include "diff.h"
5
#include "revision.h"
6
+#include "path-list.h"
7
+#include "mailmap.h"
8
9
static char *user_format;
10
@@ -288,6 +290,25 @@ static char *logmsg_reencode(const struct commit *commit,
290
return out;
291
}
292
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
+
312
static size_t format_person_part(struct strbuf *sb, char part,
313
const char *msg, int len)
314
{
@@ -309,10 +330,12 @@ static size_t format_person_part(struct strbuf *sb, char part,
330
if (end >= len - 2)
331
goto skip;
332
312
- if (part == 'n') { /* name */
333
+ if (part == 'n' || part == 'N') { /* name */
334
while (end > 0 && isspace(msg[end - 1]))
335
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);
339
return placeholder_len;
340
}
341
start = ++end; /* save email start position */