33#include "utf8.h"
44#include "diff.h"
55#include "revision.h"
6+ #include "path-list.h"
7+ #include "mailmap.h"
68
79static 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+
291312static 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