Change current mailmap usage to do matching on both name and email of author/committer.
Signed-off-by: Marius Storm-Olsen <marius@trolltech.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
0925ce4d49
commit
d20d654fe8
@ -103,6 +103,7 @@ The placeholders are:
|
|||||||
- '%an': author name
|
- '%an': author name
|
||||||
- '%aN': author name (respecting .mailmap)
|
- '%aN': author name (respecting .mailmap)
|
||||||
- '%ae': author email
|
- '%ae': author email
|
||||||
|
- '%aE': author email (respecting .mailmap)
|
||||||
- '%ad': author date (format respects --date= option)
|
- '%ad': author date (format respects --date= option)
|
||||||
- '%aD': author date, RFC2822 style
|
- '%aD': author date, RFC2822 style
|
||||||
- '%ar': author date, relative
|
- '%ar': author date, relative
|
||||||
@ -111,6 +112,7 @@ The placeholders are:
|
|||||||
- '%cn': committer name
|
- '%cn': committer name
|
||||||
- '%cN': committer name (respecting .mailmap)
|
- '%cN': committer name (respecting .mailmap)
|
||||||
- '%ce': committer email
|
- '%ce': committer email
|
||||||
|
- '%cE': committer email (respecting .mailmap)
|
||||||
- '%cd': committer date
|
- '%cd': committer date
|
||||||
- '%cD': committer date, RFC2822 style
|
- '%cD': committer date, RFC2822 style
|
||||||
- '%cr': committer date, relative
|
- '%cr': committer date, relative
|
||||||
|
@ -1263,11 +1263,12 @@ struct commit_info
|
|||||||
* Parse author/committer line in the commit object buffer
|
* Parse author/committer line in the commit object buffer
|
||||||
*/
|
*/
|
||||||
static void get_ac_line(const char *inbuf, const char *what,
|
static void get_ac_line(const char *inbuf, const char *what,
|
||||||
int bufsz, char *person, const char **mail,
|
int person_len, char *person,
|
||||||
|
int mail_len, char *mail,
|
||||||
unsigned long *time, const char **tz)
|
unsigned long *time, const char **tz)
|
||||||
{
|
{
|
||||||
int len, tzlen, maillen;
|
int len, tzlen, maillen;
|
||||||
char *tmp, *endp, *timepos;
|
char *tmp, *endp, *timepos, *mailpos;
|
||||||
|
|
||||||
tmp = strstr(inbuf, what);
|
tmp = strstr(inbuf, what);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
@ -1278,10 +1279,11 @@ static void get_ac_line(const char *inbuf, const char *what,
|
|||||||
len = strlen(tmp);
|
len = strlen(tmp);
|
||||||
else
|
else
|
||||||
len = endp - tmp;
|
len = endp - tmp;
|
||||||
if (bufsz <= len) {
|
if (person_len <= len) {
|
||||||
error_out:
|
error_out:
|
||||||
/* Ugh */
|
/* Ugh */
|
||||||
*mail = *tz = "(unknown)";
|
*tz = "(unknown)";
|
||||||
|
strcpy(mail, *tz);
|
||||||
*time = 0;
|
*time = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1304,9 +1306,10 @@ static void get_ac_line(const char *inbuf, const char *what,
|
|||||||
*tmp = 0;
|
*tmp = 0;
|
||||||
while (*tmp != ' ')
|
while (*tmp != ' ')
|
||||||
tmp--;
|
tmp--;
|
||||||
*mail = tmp + 1;
|
mailpos = tmp + 1;
|
||||||
*tmp = 0;
|
*tmp = 0;
|
||||||
maillen = timepos - tmp;
|
maillen = timepos - tmp;
|
||||||
|
memcpy(mail, mailpos, maillen);
|
||||||
|
|
||||||
if (!mailmap.nr)
|
if (!mailmap.nr)
|
||||||
return;
|
return;
|
||||||
@ -1315,20 +1318,23 @@ static void get_ac_line(const char *inbuf, const char *what,
|
|||||||
* mailmap expansion may make the name longer.
|
* mailmap expansion may make the name longer.
|
||||||
* make room by pushing stuff down.
|
* make room by pushing stuff down.
|
||||||
*/
|
*/
|
||||||
tmp = person + bufsz - (tzlen + 1);
|
tmp = person + person_len - (tzlen + 1);
|
||||||
memmove(tmp, *tz, tzlen);
|
memmove(tmp, *tz, tzlen);
|
||||||
tmp[tzlen] = 0;
|
tmp[tzlen] = 0;
|
||||||
*tz = tmp;
|
*tz = tmp;
|
||||||
|
|
||||||
tmp = tmp - (maillen + 1);
|
|
||||||
memmove(tmp, *mail, maillen);
|
|
||||||
tmp[maillen] = 0;
|
|
||||||
*mail = tmp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now, convert e-mail using mailmap
|
* Now, convert both name and e-mail using mailmap
|
||||||
*/
|
*/
|
||||||
map_email(&mailmap, tmp + 1, person, tmp-person-1);
|
if(map_user(&mailmap, mail+1, mail_len-1, person, tmp-person-1)) {
|
||||||
|
/* Add a trailing '>' to email, since map_user returns plain emails
|
||||||
|
Note: It already has '<', since we replace from mail+1 */
|
||||||
|
mailpos = memchr(mail, '\0', mail_len);
|
||||||
|
if (mailpos && mailpos-mail < mail_len - 1) {
|
||||||
|
*mailpos = '>';
|
||||||
|
*(mailpos+1) = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_commit_info(struct commit *commit,
|
static void get_commit_info(struct commit *commit,
|
||||||
@ -1337,8 +1343,10 @@ static void get_commit_info(struct commit *commit,
|
|||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *tmp, *endp, *reencoded, *message;
|
char *tmp, *endp, *reencoded, *message;
|
||||||
static char author_buf[1024];
|
static char author_name[1024];
|
||||||
static char committer_buf[1024];
|
static char author_mail[1024];
|
||||||
|
static char committer_name[1024];
|
||||||
|
static char committer_mail[1024];
|
||||||
static char summary_buf[1024];
|
static char summary_buf[1024];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1356,9 +1364,11 @@ static void get_commit_info(struct commit *commit,
|
|||||||
}
|
}
|
||||||
reencoded = reencode_commit_message(commit, NULL);
|
reencoded = reencode_commit_message(commit, NULL);
|
||||||
message = reencoded ? reencoded : commit->buffer;
|
message = reencoded ? reencoded : commit->buffer;
|
||||||
ret->author = author_buf;
|
ret->author = author_name;
|
||||||
|
ret->author_mail = author_mail;
|
||||||
get_ac_line(message, "\nauthor ",
|
get_ac_line(message, "\nauthor ",
|
||||||
sizeof(author_buf), author_buf, &ret->author_mail,
|
sizeof(author_name), author_name,
|
||||||
|
sizeof(author_mail), author_mail,
|
||||||
&ret->author_time, &ret->author_tz);
|
&ret->author_time, &ret->author_tz);
|
||||||
|
|
||||||
if (!detailed) {
|
if (!detailed) {
|
||||||
@ -1366,9 +1376,11 @@ static void get_commit_info(struct commit *commit,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->committer = committer_buf;
|
ret->committer = committer_name;
|
||||||
|
ret->committer_mail = committer_mail;
|
||||||
get_ac_line(message, "\ncommitter ",
|
get_ac_line(message, "\ncommitter ",
|
||||||
sizeof(committer_buf), committer_buf, &ret->committer_mail,
|
sizeof(committer_name), committer_name,
|
||||||
|
sizeof(committer_mail), committer_mail,
|
||||||
&ret->committer_time, &ret->committer_tz);
|
&ret->committer_time, &ret->committer_tz);
|
||||||
|
|
||||||
ret->summary = summary_buf;
|
ret->summary = summary_buf;
|
||||||
|
@ -40,6 +40,7 @@ static void insert_one_record(struct shortlog *log,
|
|||||||
char *buffer, *p;
|
char *buffer, *p;
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
char namebuf[1024];
|
char namebuf[1024];
|
||||||
|
char emailbuf[1024];
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *eol;
|
const char *eol;
|
||||||
const char *boemail, *eoemail;
|
const char *boemail, *eoemail;
|
||||||
@ -51,7 +52,19 @@ static void insert_one_record(struct shortlog *log,
|
|||||||
eoemail = strchr(boemail, '>');
|
eoemail = strchr(boemail, '>');
|
||||||
if (!eoemail)
|
if (!eoemail)
|
||||||
return;
|
return;
|
||||||
if (!map_email(&log->mailmap, boemail+1, namebuf, sizeof(namebuf))) {
|
|
||||||
|
/* copy author name to namebuf, to support matching on both name and email */
|
||||||
|
memcpy(namebuf, author, boemail - author);
|
||||||
|
len = boemail - author;
|
||||||
|
while(len > 0 && isspace(namebuf[len-1]))
|
||||||
|
len--;
|
||||||
|
namebuf[len] = 0;
|
||||||
|
|
||||||
|
/* copy email name to emailbuf, to allow email replacement as well */
|
||||||
|
memcpy(emailbuf, boemail+1, eoemail - boemail);
|
||||||
|
emailbuf[eoemail - boemail - 1] = 0;
|
||||||
|
|
||||||
|
if (!map_user(&log->mailmap, emailbuf, sizeof(emailbuf), namebuf, sizeof(namebuf))) {
|
||||||
while (author < boemail && isspace(*author))
|
while (author < boemail && isspace(*author))
|
||||||
author++;
|
author++;
|
||||||
for (len = 0;
|
for (len = 0;
|
||||||
@ -67,8 +80,8 @@ static void insert_one_record(struct shortlog *log,
|
|||||||
|
|
||||||
if (log->email) {
|
if (log->email) {
|
||||||
size_t room = sizeof(namebuf) - len - 1;
|
size_t room = sizeof(namebuf) - len - 1;
|
||||||
int maillen = eoemail - boemail + 1;
|
int maillen = strlen(emailbuf);
|
||||||
snprintf(namebuf + len, room, " %.*s", maillen, boemail);
|
snprintf(namebuf + len, room, " <%.*s>", maillen, emailbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
item = string_list_insert(namebuf, &log->list);
|
item = string_list_insert(namebuf, &log->list);
|
||||||
@ -321,6 +334,5 @@ void shortlog_output(struct shortlog *log)
|
|||||||
|
|
||||||
log->list.strdup_strings = 1;
|
log->list.strdup_strings = 1;
|
||||||
string_list_clear(&log->list, 1);
|
string_list_clear(&log->list, 1);
|
||||||
log->mailmap.strdup_strings = 1;
|
clear_mailmap(&log->mailmap);
|
||||||
string_list_clear(&log->mailmap, 1);
|
|
||||||
}
|
}
|
||||||
|
57
pretty.c
57
pretty.c
@ -305,23 +305,14 @@ static char *logmsg_reencode(const struct commit *commit,
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mailmap_name(struct strbuf *sb, const char *email)
|
static int mailmap_name(char *email, int email_len, char *name, int name_len)
|
||||||
{
|
{
|
||||||
static struct string_list *mail_map;
|
static struct string_list *mail_map;
|
||||||
char buffer[1024];
|
|
||||||
|
|
||||||
if (!mail_map) {
|
if (!mail_map) {
|
||||||
mail_map = xcalloc(1, sizeof(*mail_map));
|
mail_map = xcalloc(1, sizeof(*mail_map));
|
||||||
read_mailmap(mail_map, NULL);
|
read_mailmap(mail_map, NULL);
|
||||||
}
|
}
|
||||||
|
return mail_map->nr && map_user(mail_map, email, email_len, name, name_len);
|
||||||
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,
|
static size_t format_person_part(struct strbuf *sb, char part,
|
||||||
@ -332,6 +323,9 @@ static size_t format_person_part(struct strbuf *sb, char part,
|
|||||||
int start, end, tz = 0;
|
int start, end, tz = 0;
|
||||||
unsigned long date = 0;
|
unsigned long date = 0;
|
||||||
char *ep;
|
char *ep;
|
||||||
|
const char *name_start, *name_end, *mail_start, *mail_end, *msg_end = msg+len;
|
||||||
|
char person_name[1024];
|
||||||
|
char person_mail[1024];
|
||||||
|
|
||||||
/* advance 'end' to point to email start delimiter */
|
/* advance 'end' to point to email start delimiter */
|
||||||
for (end = 0; end < len && msg[end] != '<'; end++)
|
for (end = 0; end < len && msg[end] != '<'; end++)
|
||||||
@ -345,25 +339,34 @@ static size_t format_person_part(struct strbuf *sb, char part,
|
|||||||
if (end >= len - 2)
|
if (end >= len - 2)
|
||||||
goto skip;
|
goto skip;
|
||||||
|
|
||||||
|
/* Seek for both name and email part */
|
||||||
|
name_start = msg;
|
||||||
|
name_end = msg+end;
|
||||||
|
while (name_end > name_start && isspace(*(name_end-1)))
|
||||||
|
name_end--;
|
||||||
|
mail_start = msg+end+1;
|
||||||
|
mail_end = mail_start;
|
||||||
|
while (mail_end < msg_end && *mail_end != '>')
|
||||||
|
mail_end++;
|
||||||
|
if (mail_end == msg_end)
|
||||||
|
goto skip;
|
||||||
|
end = mail_end-msg;
|
||||||
|
|
||||||
|
if (part == 'N' || part == 'E') { /* mailmap lookup */
|
||||||
|
strlcpy(person_name, name_start, name_end-name_start+1);
|
||||||
|
strlcpy(person_mail, mail_start, mail_end-mail_start+1);
|
||||||
|
mailmap_name(person_mail, sizeof(person_mail), person_name, sizeof(person_name));
|
||||||
|
name_start = person_name;
|
||||||
|
name_end = name_start + strlen(person_name);
|
||||||
|
mail_start = person_mail;
|
||||||
|
mail_end = mail_start + strlen(person_mail);
|
||||||
|
}
|
||||||
if (part == 'n' || part == 'N') { /* name */
|
if (part == 'n' || part == 'N') { /* name */
|
||||||
while (end > 0 && isspace(msg[end - 1]))
|
strbuf_add(sb, name_start, name_end-name_start);
|
||||||
end--;
|
|
||||||
if (part != 'N' || !msg[end] || !msg[end + 1] ||
|
|
||||||
mailmap_name(sb, msg + end + 2) < 0)
|
|
||||||
strbuf_add(sb, msg, end);
|
|
||||||
return placeholder_len;
|
return placeholder_len;
|
||||||
}
|
}
|
||||||
start = ++end; /* save email start position */
|
if (part == 'e' || part == 'E') { /* email */
|
||||||
|
strbuf_add(sb, mail_start, mail_end-mail_start);
|
||||||
/* advance 'end' to point to email end delimiter */
|
|
||||||
for ( ; end < len && msg[end] != '>'; end++)
|
|
||||||
; /* do nothing */
|
|
||||||
|
|
||||||
if (end >= len)
|
|
||||||
goto skip;
|
|
||||||
|
|
||||||
if (part == 'e') { /* email */
|
|
||||||
strbuf_add(sb, msg + start, end - start);
|
|
||||||
return placeholder_len;
|
return placeholder_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,4 +106,110 @@ test_expect_success 'No mailmap files, but configured' '
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# Extended mailmap configurations should give us the following output for shortlog
|
||||||
|
cat >expect <<\EOF
|
||||||
|
A U Thor <author@example.com> (1):
|
||||||
|
initial
|
||||||
|
|
||||||
|
CTO <cto@company.xx> (1):
|
||||||
|
seventh
|
||||||
|
|
||||||
|
Other Author <other@author.xx> (2):
|
||||||
|
third
|
||||||
|
fourth
|
||||||
|
|
||||||
|
Santa Claus <santa.claus@northpole.xx> (2):
|
||||||
|
fifth
|
||||||
|
sixth
|
||||||
|
|
||||||
|
Some Dude <some@dude.xx> (1):
|
||||||
|
second
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'Shortlog output (complex mapping)' '
|
||||||
|
echo three >>one &&
|
||||||
|
git add one &&
|
||||||
|
test_tick &&
|
||||||
|
git commit --author "nick2 <bugs@company.xx>" -m third &&
|
||||||
|
|
||||||
|
echo four >>one &&
|
||||||
|
git add one &&
|
||||||
|
test_tick &&
|
||||||
|
git commit --author "nick2 <nick2@company.xx>" -m fourth &&
|
||||||
|
|
||||||
|
echo five >>one &&
|
||||||
|
git add one &&
|
||||||
|
test_tick &&
|
||||||
|
git commit --author "santa <me@company.xx>" -m fifth &&
|
||||||
|
|
||||||
|
echo six >>one &&
|
||||||
|
git add one &&
|
||||||
|
test_tick &&
|
||||||
|
git commit --author "claus <me@company.xx>" -m sixth &&
|
||||||
|
|
||||||
|
echo seven >>one &&
|
||||||
|
git add one &&
|
||||||
|
test_tick &&
|
||||||
|
git commit --author "CTO <cto@coompany.xx>" -m seventh &&
|
||||||
|
|
||||||
|
mkdir internal_mailmap &&
|
||||||
|
echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
|
||||||
|
echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
|
||||||
|
echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
|
||||||
|
echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
|
||||||
|
echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
|
||||||
|
echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
|
||||||
|
echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
|
||||||
|
|
||||||
|
git shortlog -e HEAD >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
|
# git log with --pretty format which uses the name and email mailmap placemarkers
|
||||||
|
cat >expect <<\EOF
|
||||||
|
Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
|
||||||
|
Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
|
||||||
|
|
||||||
|
Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
|
||||||
|
Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
|
||||||
|
|
||||||
|
Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
|
||||||
|
Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
|
||||||
|
|
||||||
|
Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
|
||||||
|
Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
|
||||||
|
|
||||||
|
Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
|
||||||
|
Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
|
||||||
|
|
||||||
|
Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
|
||||||
|
Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
|
||||||
|
|
||||||
|
Author A U Thor <author@example.com> maps to A U Thor <author@example.com>
|
||||||
|
Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'Log output (complex mapping)' '
|
||||||
|
git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
# git blame
|
||||||
|
cat >expect <<\EOF
|
||||||
|
^3a2fdcb (A U Thor 2005-04-07 15:13:13 -0700 1) one
|
||||||
|
7de6f99b (Some Dude 2005-04-07 15:13:13 -0700 2) two
|
||||||
|
5815879d (Other Author 2005-04-07 15:14:13 -0700 3) three
|
||||||
|
ff859d96 (Other Author 2005-04-07 15:15:13 -0700 4) four
|
||||||
|
5ab6d4fa (Santa Claus 2005-04-07 15:16:13 -0700 5) five
|
||||||
|
38a42d8b (Santa Claus 2005-04-07 15:17:13 -0700 6) six
|
||||||
|
8ddc0386 (CTO 2005-04-07 15:18:13 -0700 7) seven
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'Blame output (complex mapping)' '
|
||||||
|
git blame one >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user