Skip to content

Commit 3a27e99

Browse files
jacob-kellergitster
authored andcommitted
check-mailmap: accept "user@host" contacts
git check-mailmap splits each provided contact using split_ident_line. This function requires that the contact either be of the form "Name <user@host>" or of the form "<user@host>". In particular, if the mail portion of the contact is not surrounded by angle brackets, split_ident_line will reject it. This results in git check-mailmap rejecting attempts to translate simple email addresses: $ git check-mailmap user@host fatal: unable to parse contact: user@host This limits the usability of check-mailmap as it requires placing angle brackets around plain email addresses. In particular, attempting to use git check-mailmap to support mapping addresses in git send-email is not straight forward. The sanitization and validation functions in git send-email strip angle brackets from plain email addresses. It is not trivial to add brackets prior to invoking git check-mailmap. Instead, modify check_mailmap() to allow such strings as contacts. In particular, treat any line which cannot be split by split_ident_line as a simple email address. No attempt is made to actually parse the address line, or validate that it is actually an email address. Implementing such validation is not trivial. Besides, we weren't validating the address between angle brackets before anyways. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25673b1 commit 3a27e99

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

Documentation/git-check-mailmap.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ SYNOPSIS
1515
DESCRIPTION
1616
-----------
1717

18-
For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line
19-
or standard input (when using `--stdin`), look up the person's canonical name
20-
and email address (see "Mapping Authors" below). If found, print them;
21-
otherwise print the input as-is.
18+
For each ``Name $$<user@host>$$'', ``$$<user@host>$$'', or ``$$user@host$$''
19+
from the command-line or standard input (when using `--stdin`), look up the
20+
person's canonical name and email address (see "Mapping Authors" below). If
21+
found, print them; otherwise print the input as-is.
2222

2323

2424
OPTIONS

builtin/check-mailmap.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)
2525
size_t namelen, maillen;
2626
struct ident_split ident;
2727

28-
if (split_ident_line(&ident, contact, strlen(contact)))
29-
die(_("unable to parse contact: %s"), contact);
30-
31-
name = ident.name_begin;
32-
namelen = ident.name_end - ident.name_begin;
33-
mail = ident.mail_begin;
34-
maillen = ident.mail_end - ident.mail_begin;
28+
if (!split_ident_line(&ident, contact, strlen(contact))) {
29+
name = ident.name_begin;
30+
namelen = ident.name_end - ident.name_begin;
31+
mail = ident.mail_begin;
32+
maillen = ident.mail_end - ident.mail_begin;
33+
} else {
34+
name = NULL;
35+
namelen = 0;
36+
mail = contact;
37+
maillen = strlen(contact);
38+
}
3539

3640
map_user(mailmap, &mail, &maillen, &name, &namelen);
3741

t/t4203-mailmap.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,46 @@ test_expect_success 'check-mailmap --stdin arguments: mapping' '
7171
test_cmp expect actual
7272
'
7373

74-
test_expect_success 'check-mailmap bogus contact' '
75-
test_must_fail git check-mailmap bogus
74+
test_expect_success 'check-mailmap simple address: mapping' '
75+
test_when_finished "rm .mailmap" &&
76+
cat >.mailmap <<-EOF &&
77+
New Name <$GIT_AUTHOR_EMAIL>
78+
EOF
79+
cat .mailmap >expect &&
80+
git check-mailmap "$GIT_AUTHOR_EMAIL" >actual &&
81+
test_cmp expect actual
82+
'
83+
84+
test_expect_success 'check-mailmap --stdin simple address: mapping' '
85+
test_when_finished "rm .mailmap" &&
86+
cat >.mailmap <<-EOF &&
87+
New Name <$GIT_AUTHOR_EMAIL>
88+
EOF
89+
cat >stdin <<-EOF &&
90+
$GIT_AUTHOR_EMAIL
91+
EOF
92+
cat .mailmap >expect &&
93+
git check-mailmap --stdin <stdin >actual &&
94+
test_cmp expect actual
95+
'
96+
97+
test_expect_success 'check-mailmap simple address: no mapping' '
98+
cat >expect <<-EOF &&
99+
100+
EOF
101+
git check-mailmap "[email protected]" >actual &&
102+
test_cmp expect actual
76103
'
77104

78-
test_expect_success 'check-mailmap bogus contact --stdin' '
79-
test_must_fail git check-mailmap --stdin bogus </dev/null
105+
test_expect_success 'check-mailmap --stdin simple address: no mapping' '
106+
cat >expect <<-EOF &&
107+
108+
EOF
109+
cat >stdin <<-EOF &&
110+
111+
EOF
112+
git check-mailmap --stdin <stdin >actual &&
113+
test_cmp expect actual
80114
'
81115

82116
test_expect_success 'No mailmap' '

0 commit comments

Comments
 (0)