1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

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>
This commit is contained in:
Jacob Keller 2024-08-27 14:27:16 -07:00 committed by Junio C Hamano
parent 25673b1c47
commit 3a27e991f2
3 changed files with 53 additions and 15 deletions

View file

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

View file

@ -25,13 +25,17 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)
size_t namelen, maillen;
struct ident_split ident;
if (split_ident_line(&ident, contact, strlen(contact)))
die(_("unable to parse contact: %s"), contact);
name = ident.name_begin;
namelen = ident.name_end - ident.name_begin;
mail = ident.mail_begin;
maillen = ident.mail_end - ident.mail_begin;
if (!split_ident_line(&ident, contact, strlen(contact))) {
name = ident.name_begin;
namelen = ident.name_end - ident.name_begin;
mail = ident.mail_begin;
maillen = ident.mail_end - ident.mail_begin;
} else {
name = NULL;
namelen = 0;
mail = contact;
maillen = strlen(contact);
}
map_user(mailmap, &mail, &maillen, &name, &namelen);

View file

@ -71,12 +71,46 @@ test_expect_success 'check-mailmap --stdin arguments: mapping' '
test_cmp expect actual
'
test_expect_success 'check-mailmap bogus contact' '
test_must_fail git check-mailmap bogus
test_expect_success 'check-mailmap simple address: mapping' '
test_when_finished "rm .mailmap" &&
cat >.mailmap <<-EOF &&
New Name <$GIT_AUTHOR_EMAIL>
EOF
cat .mailmap >expect &&
git check-mailmap "$GIT_AUTHOR_EMAIL" >actual &&
test_cmp expect actual
'
test_expect_success 'check-mailmap bogus contact --stdin' '
test_must_fail git check-mailmap --stdin bogus </dev/null
test_expect_success 'check-mailmap --stdin simple address: mapping' '
test_when_finished "rm .mailmap" &&
cat >.mailmap <<-EOF &&
New Name <$GIT_AUTHOR_EMAIL>
EOF
cat >stdin <<-EOF &&
$GIT_AUTHOR_EMAIL
EOF
cat .mailmap >expect &&
git check-mailmap --stdin <stdin >actual &&
test_cmp expect actual
'
test_expect_success 'check-mailmap simple address: no mapping' '
cat >expect <<-EOF &&
<bugs@company.xx>
EOF
git check-mailmap "bugs@company.xx" >actual &&
test_cmp expect actual
'
test_expect_success 'check-mailmap --stdin simple address: no mapping' '
cat >expect <<-EOF &&
<bugs@company.xx>
EOF
cat >stdin <<-EOF &&
bugs@company.xx
EOF
git check-mailmap --stdin <stdin >actual &&
test_cmp expect actual
'
test_expect_success 'No mailmap' '