Skip to content

Commit

Permalink
Add pretty format %aN which gives the author name, respecting .mailmap
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jul 12, 2008
1 parent e09c4e7 commit e0cbc39
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Documentation/pretty-formats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ The placeholders are:
- '%P': parent hashes
- '%p': abbreviated parent hashes
- '%an': author name
- '%aN': author name (respecting .mailmap)
- '%ae': author email
- '%ad': author date
- '%aD': author date, RFC2822 style
- '%ar': author date, relative
- '%at': author date, UNIX timestamp
- '%ai': author date, ISO 8601 format
- '%cn': committer name
- '%cN': committer name (respecting .mailmap)
- '%ce': committer email
- '%cd': committer date
- '%cD': committer date, RFC2822 style
Expand Down
27 changes: 25 additions & 2 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "utf8.h"
#include "diff.h"
#include "revision.h"
#include "path-list.h"
#include "mailmap.h"

static char *user_format;

Expand Down Expand Up @@ -288,6 +290,25 @@ static char *logmsg_reencode(const struct commit *commit,
return out;
}

static int mailmap_name(struct strbuf *sb, const char *email)
{
static struct path_list *mail_map;
char buffer[1024];

if (!mail_map) {
mail_map = xcalloc(1, sizeof(*mail_map));
read_mailmap(mail_map, ".mailmap", NULL);
}

if (!mail_map->nr)
return -1;

if (!map_email(mail_map, email, buffer, sizeof(buffer)))
return -1;
strbuf_addstr(sb, buffer);
return 0;
}

static size_t format_person_part(struct strbuf *sb, char part,
const char *msg, int len)
{
Expand All @@ -309,10 +330,12 @@ static size_t format_person_part(struct strbuf *sb, char part,
if (end >= len - 2)
goto skip;

if (part == 'n') { /* name */
if (part == 'n' || part == 'N') { /* name */
while (end > 0 && isspace(msg[end - 1]))
end--;
strbuf_add(sb, msg, end);
if (part != 'N' || !msg[end] || !msg[end + 1] ||
mailmap_name(sb, msg + end + 2) < 0)
strbuf_add(sb, msg, end);
return placeholder_len;
}
start = ++end; /* save email start position */
Expand Down

0 comments on commit e0cbc39

Please sign in to comment.