From: Jacob Keller <jacob.e.keller@intel.com>
To: Josh Steadmon <steadmon@google.com>,
git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Jeff King <peff@peff.net>
Subject: [PATCH 1/2] check-mailmap: add --no-brackets mode
Date: Fri, 16 Aug 2024 16:06:23 -0700 [thread overview]
Message-ID: <20240816-jk-send-email-mailmap-support-v1-1-68ca5b4a6078@gmail.com> (raw)
In-Reply-To: <20240816-jk-send-email-mailmap-support-v1-0-68ca5b4a6078@gmail.com>
From: Jacob Keller <jacob.keller@gmail.com>
The git check-mailmap command can be used to convert identities to their
canonical real name and email address. Currently, if a simple email
address is provided without surrounding angle brackets, git
check-mailmap will fail:
$ git check-mailmap test@example.com
fatal: unable to parse contact: test@example.com
This is generally fine since identifies are expected to be of the form
"name <email@domain>". However, requiring brackets around simple email
addresses can make it difficult to support mailmap operation in other
environments where angle brackets may be missing.
Specifically, attempting to support the mailmap within git send-email is
tricky, since angle brackets are not always provided for addresses.
Teach check-mailmap a new '--no-brackets' mode. In this mode, any
contact line which cannot be interpreted by split_ident_line is treated
as a simple address without a name. In addition, when any contact does
not have a name, output the mail address without the angle brackets.
Note that angle brackets are accepted if they are present, however the
output will strip them.
This mode will be useful for git send-email in a following feature
implementation to enable mapping any email addresses to their canonical
value.
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
builtin/check-mailmap.c | 27 ++++++++++++-----
Documentation/git-check-mailmap.txt | 8 ++++-
t/t4203-mailmap.sh | 60 +++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+), 9 deletions(-)
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index b8a05b8e07b5..7c8cde370b97 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -9,6 +9,7 @@
#include "write-or-die.h"
static int use_stdin;
+static int no_brackets;
static const char * const check_mailmap_usage[] = {
N_("git check-mailmap [<options>] <contact>..."),
NULL
@@ -16,6 +17,7 @@ NULL
static const struct option check_mailmap_options[] = {
OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")),
+ OPT_BOOL(0, "no-brackets", &no_brackets, N_("do not require or output brackets for nameless email addresses")),
OPT_END()
};
@@ -25,19 +27,28 @@ 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)))
+ 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 if (no_brackets) {
+ name = contact;
+ namelen = 0;
+ mail = contact;
+ maillen = strlen(contact);
+ } else {
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;
+ }
map_user(mailmap, &mail, &maillen, &name, &namelen);
if (namelen)
- printf("%.*s ", (int)namelen, name);
- printf("<%.*s>\n", (int)maillen, mail);
+ printf("%.*s <%.*s>\n", (int)namelen, name, (int)maillen, mail);
+ else if (no_brackets)
+ printf("%.*s\n", (int)maillen, mail);
+ else
+ printf("<%.*s>\n", (int)maillen, mail);
}
int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
diff --git a/Documentation/git-check-mailmap.txt b/Documentation/git-check-mailmap.txt
index 02f441832321..30f44391a9dd 100644
--- a/Documentation/git-check-mailmap.txt
+++ b/Documentation/git-check-mailmap.txt
@@ -27,13 +27,19 @@ OPTIONS
Read contacts, one per line, from the standard input after exhausting
contacts provided on the command-line.
+--no-brackets::
+ Do not require ``<`` and ``>`` angle brackets when interpreting
+ contacts without a name. Additionally, do not output brackets when
+ outputting an email without a name.
+
OUTPUT
------
For each contact, a single line is output, terminated by a newline. If the
name is provided or known to the 'mailmap', ``Name $$<user@host>$$'' is
-printed; otherwise only ``$$<user@host>$$'' is printed.
+printed; otherwise only ``$$<user@host>$$'' is printed. If ``--no-brackets``
+is specified, output only ``<user@host>`` for contacts without a name.
CONFIGURATION
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index 79e5f42760d9..83f012b34ab1 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -80,6 +80,66 @@ test_expect_success 'check-mailmap bogus contact --stdin' '
test_must_fail git check-mailmap --stdin bogus </dev/null
'
+test_expect_success 'check-mailmap --no-brackets simple address: no mapping' '
+ cat >expect <<-EOF &&
+ bugs@company.xy
+ EOF
+ git check-mailmap --no-brackets bugs@company.xy >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap --no-brackets address with brackets: no mapping' '
+ cat >expect <<-EOF &&
+ bugs@company.xy
+ EOF
+ git check-mailmap --no-brackets "<bugs@company.xy>" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap --no-brackets simple address: mapping' '
+ cat >.mailmap <<-EOF &&
+ New Name <bugs@company.xy>
+ EOF
+ cat >expect <<-EOF &&
+ New Name <bugs@company.xy>
+ EOF
+ git check-mailmap --no-brackets bugs@company.xy >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap --stdin --no-brackets simple address: mapping' '
+ cat >.mailmap <<-EOF &&
+ New Name <bugs@company.xy>
+ EOF
+ cat >stdin <<-EOF &&
+ bugs@company.xy
+ EOF
+ cat >expect <<-EOF &&
+ New Name <bugs@company.xy>
+ EOF
+ git check-mailmap --stdin --no-brackets <stdin >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap --no-brackets simple address: mapping, no name' '
+ cat >.mailmap <<-EOF &&
+ <bugs@company.xz> <bugs@company.xy>
+ EOF
+ cat >expect <<-EOF &&
+ bugs@company.xz
+ EOF
+ git check-mailmap --no-brackets bugs@company.xy >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap --no-brackets bogus address' '
+ cat >expect <<-EOF &&
+ bogus
+ EOF
+ git check-mailmap --no-brackets bogus >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'No mailmap' '
cat >expect <<-EOF &&
$GIT_AUTHOR_NAME (1):
--
2.46.0.124.g2dc1a81c8933
next prev parent reply other threads:[~2024-08-16 23:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-16 23:06 [PATCH 0/2] send-email: add --mailmap support Jacob Keller
2024-08-16 23:06 ` Jacob Keller [this message]
2024-08-16 23:22 ` [PATCH 1/2] check-mailmap: add --no-brackets mode Eric Sunshine
2024-08-16 23:42 ` Jacob Keller
2024-08-16 23:51 ` Eric Sunshine
2024-08-16 23:06 ` [PATCH 2/2] send-email: add support for --mailmap Jacob Keller
2024-08-16 23:41 ` Eric Sunshine
2024-08-16 23:49 ` Jacob Keller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240816-jk-send-email-mailmap-support-v1-1-68ca5b4a6078@gmail.com \
--to=jacob.e.keller@intel.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=steadmon@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).