Git fork

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 <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jacob Keller and committed by
Junio C Hamano
3a27e991 25673b1c

+53 -15
+4 -4
Documentation/git-check-mailmap.txt
··· 15 15 DESCRIPTION 16 16 ----------- 17 17 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. 22 22 23 23 24 24 OPTIONS
+11 -7
builtin/check-mailmap.c
··· 25 25 size_t namelen, maillen; 26 26 struct ident_split ident; 27 27 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 + } 35 39 36 40 map_user(mailmap, &mail, &maillen, &name, &namelen); 37 41
+38 -4
t/t4203-mailmap.sh
··· 71 71 test_cmp expect actual 72 72 ' 73 73 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 76 82 ' 77 83 78 - test_expect_success 'check-mailmap bogus contact --stdin' ' 79 - test_must_fail git check-mailmap --stdin bogus </dev/null 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 + <bugs@company.xx> 100 + EOF 101 + git check-mailmap "bugs@company.xx" >actual && 102 + test_cmp expect actual 103 + ' 104 + 105 + test_expect_success 'check-mailmap --stdin simple address: no mapping' ' 106 + cat >expect <<-EOF && 107 + <bugs@company.xx> 108 + EOF 109 + cat >stdin <<-EOF && 110 + bugs@company.xx 111 + EOF 112 + git check-mailmap --stdin <stdin >actual && 113 + test_cmp expect actual 80 114 ' 81 115 82 116 test_expect_success 'No mailmap' '