From patchwork Tue Aug 27 21:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 13780172 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF93D19755B for ; Tue, 27 Aug 2024 21:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724794056; cv=none; b=My9Xb+xvKtEiwnRtrtV6uURljId7DaWys+wN5XyjhqKlqAQA1ccNMFOdK0JRrtSOd36KUOHsT6Yj+8pXpWH+Xbijq4mKLrfVxSGKLIJzzYiSVpaA3Iv8Tcl2xAgYDHmU/620wXL/bNbOYT8yEYRTMIJX/xcY2Eyv7z+jBzC5Hiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724794056; c=relaxed/simple; bh=lw6NiF1fm48C5S9eXHjrHshC4CLfBRLpYzW5t+PdPFc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To; b=R52/ZlkKcHW425UFlfW0WuI9+JcEctzBdoNWdV5jidRLtyGmESyyukA0BxqtKXLGXGEPMstAbJIE3RT1Q/NozsivkeFgdOsNDFcZB5m5+M3jazetgRZ+RB5ihGqqOMpGT098YcQXUTfPtmgvZNTFoWU/TPCMG6XfnadXJIyQYdw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cEs+xcKp; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cEs+xcKp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724794055; x=1756330055; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to; bh=lw6NiF1fm48C5S9eXHjrHshC4CLfBRLpYzW5t+PdPFc=; b=cEs+xcKpifmb+mV/QtiudW/y9VLg92n9DqWV/qQX+kvrz1xK1SgbEQZb 6p+gLF6INuNdNr5HSLwUv1Slm9g5kUcrMHW9CibsxgI02QUUcrnmJYpBH G3brWmG5tFZnOu/oQbgAVYU5qYLs8syRXsJ0HkcTxeFXp2tOEyhsIl8Ev +ut4DLOhRt/pmxpjuZcyWz7TRZRSsGk9dvigxvYF3hZgZ3B4IKCB/fRoY hKdBxEKks7TiSoYxRnvuewjy1rSymIEp3eWUj02iqSZg9G5q5SJkHzeOh LerqgVfMXOI2z0gzqyYxUIJ3TNZ5p0fYN5Yr2SRRoYGcy3SLv8Lzy14Df Q==; X-CSE-ConnectionGUID: oPmXMwd7Rt2jyyJ71+vbbw== X-CSE-MsgGUID: j+G293wyStSjHHxJjPcZmA== X-IronPort-AV: E=McAfee;i="6700,10204,11177"; a="33959506" X-IronPort-AV: E=Sophos;i="6.10,181,1719903600"; d="scan'208";a="33959506" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Aug 2024 14:27:32 -0700 X-CSE-ConnectionGUID: 81uXMQYAQvO8pQTglBunGQ== X-CSE-MsgGUID: hvjoFxvSRG6q13ujiS3VQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,181,1719903600"; d="scan'208";a="63517535" Received: from jekeller-desk.jf.intel.com ([10.166.241.20]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Aug 2024 14:27:32 -0700 From: Jacob Keller Date: Tue, 27 Aug 2024 14:27:16 -0700 Subject: [PATCH v3 1/3] check-mailmap: accept "user@host" contacts Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-jk-send-email-mailmap-support-v3-1-bec5ba9be391@gmail.com> References: <20240827-jk-send-email-mailmap-support-v3-0-bec5ba9be391@gmail.com> In-Reply-To: <20240827-jk-send-email-mailmap-support-v3-0-bec5ba9be391@gmail.com> To: Eric Sunshine , Josh Steadmon , git@vger.kernel.org, Junio C Hamano , Jeff King X-Mailer: b4 0.14.0 From: Jacob Keller git check-mailmap splits each provided contact using split_ident_line. This function requires that the contact either be of the form "Name " or of the form "". 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 --- builtin/check-mailmap.c | 18 +++++++++------- Documentation/git-check-mailmap.txt | 8 +++---- t/t4203-mailmap.sh | 42 +++++++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index b8a05b8e07b5..6b7fb53494f0 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -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); diff --git a/Documentation/git-check-mailmap.txt b/Documentation/git-check-mailmap.txt index 02f441832321..7747e38e25e3 100644 --- a/Documentation/git-check-mailmap.txt +++ b/Documentation/git-check-mailmap.txt @@ -15,10 +15,10 @@ SYNOPSIS DESCRIPTION ----------- -For each ``Name $$$$'' or ``$$$$'' 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 $$$$'', ``$$$$'', 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 diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 79e5f42760d9..2265ff8872df 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -72,12 +72,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 .mailmap <<-EOF && + New Name <$GIT_AUTHOR_EMAIL> + EOF + cat >stdin <<-EOF && + $GIT_AUTHOR_EMAIL + EOF + cat .mailmap >expect && + git check-mailmap --stdin actual && + test_cmp expect actual +' + +test_expect_success 'check-mailmap simple address: no mapping' ' + cat >expect <<-EOF && + + 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 && + + EOF + cat >stdin <<-EOF && + bugs@company.xx + EOF + git check-mailmap --stdin actual && + test_cmp expect actual ' test_expect_success 'No mailmap' ' From patchwork Tue Aug 27 21:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 13780173 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AA8A1D1F7C for ; Tue, 27 Aug 2024 21:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724794057; cv=none; b=UDtN+jXeqBsHTZvEIt40rGYq6w5qayxIT2slzdw6I59a2v2Gn4VqXSk/EvcjRJKgwM8ZRrmMpmlKSWZhbDztmjPm1b5mfYkK2WMdby6g4EeUdunSPti4wqgjJr+qTYqJM2/q+pDwPAZeCbb+38frZv64uAc0EqAA0Co7P3Fuf44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724794057; c=relaxed/simple; bh=bMngD6mwgNiHh3gcgvWsjnzy6KE+sKQ6Uq1sVDBAZQ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To; b=RGpZJUmyLwz9hqCk6qKpRPa34J1Qi83ySSlbNUx/IhMLF7gTIHYEmmnifxVPojtH5wn2XQACq1mnjL/SXnbQYZYxk8w9wjGpKn5DKdm8+a5feoGZ4+s+5AJqul87QV7s2R6NqGeqa/LkxYopGcFZIVpdhrNSQGGgk01yvAjPz74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HaZfdydW; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HaZfdydW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724794055; x=1756330055; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to; bh=bMngD6mwgNiHh3gcgvWsjnzy6KE+sKQ6Uq1sVDBAZQ0=; b=HaZfdydWnZYHnnB3DSICoEyz3TY83cFxey817QM1qbj6uB6I2SFhAOzR nNieNPHZwWPrxN4rp/MHKqgPKnuJLhanQ2TB9XDbnwG/3bbthmNAJnsyF rnkch1cVNVPMLSAWbr3zwhcVlZpR+nrrwYoVaL6QSUDiYs1El0ekvOeHP Qs9hPpPiynvqFZBbM6zJ7lC8EmRdYpX5sSL6RgvLOXRYoT3/D8U8sKVIk eOOWA8g14hwWIg4U+0urb/fbv+UrX7EEAciIhvBUxHmcAHXvdxAE3daaf VHpSYTChG0Sdk/NUsBmWu/RLxeuezg9SsrR3PzNvLS+vOtoMjEQlo/OZH w==; X-CSE-ConnectionGUID: aWs8KpSTTOea+5G47H7MCQ== X-CSE-MsgGUID: maCEPjPtTMKQ26mvQsaD3A== X-IronPort-AV: E=McAfee;i="6700,10204,11177"; a="33959510" X-IronPort-AV: E=Sophos;i="6.10,181,1719903600"; d="scan'208";a="33959510" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Aug 2024 14:27:32 -0700 X-CSE-ConnectionGUID: M/a6aJvxRQKhBxgUyoPXVw== X-CSE-MsgGUID: ozTRV9P9S8CSmoJzkm6iWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,181,1719903600"; d="scan'208";a="63517536" Received: from jekeller-desk.jf.intel.com ([10.166.241.20]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Aug 2024 14:27:32 -0700 From: Jacob Keller Date: Tue, 27 Aug 2024 14:27:17 -0700 Subject: [PATCH v3 2/3] check-mailmap: add options for additional mailmap sources Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-jk-send-email-mailmap-support-v3-2-bec5ba9be391@gmail.com> References: <20240827-jk-send-email-mailmap-support-v3-0-bec5ba9be391@gmail.com> In-Reply-To: <20240827-jk-send-email-mailmap-support-v3-0-bec5ba9be391@gmail.com> To: Eric Sunshine , Josh Steadmon , git@vger.kernel.org, Junio C Hamano , Jeff King X-Mailer: b4 0.14.0 From: Jacob Keller The git check-mailmap command reads the mailmap from either the default .mailmap location and then from the mailmap.blob and mailmap.file configurations. A following change to git send-email will want to support new configuration options based on the configured identity. The identity-based configuration and options only make sense in the context of git send-email. Expose the read_mailmap_file and read_mailmap_blob functions from mailmap.c. Teach git check-mailmap the --mailmap-file and --mailmap-blob options which load the additional mailmap sources. Signed-off-by: Jacob Keller --- mailmap.h | 7 +++++++ builtin/check-mailmap.c | 7 +++++++ mailmap.c | 9 +++------ Documentation/git-check-mailmap.txt | 10 ++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/mailmap.h b/mailmap.h index cbda9bc5e0c1..908365e1bffa 100644 --- a/mailmap.h +++ b/mailmap.h @@ -6,6 +6,13 @@ struct string_list; extern char *git_mailmap_file; extern char *git_mailmap_blob; +/* Flags for read_mailmap_file() */ +#define MAILMAP_NOFOLLOW (1<<0) + +int read_mailmap_file(struct string_list *map, const char *filename, + unsigned flags); +int read_mailmap_blob(struct string_list *map, const char *name); + int read_mailmap(struct string_list *map); void clear_mailmap(struct string_list *map); diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index 6b7fb53494f0..2334b5722275 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 const char *mailmap_file, *mailmap_blob; static const char * const check_mailmap_usage[] = { N_("git check-mailmap [] ..."), NULL @@ -16,6 +17,8 @@ NULL static const struct option check_mailmap_options[] = { OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")), + OPT_FILENAME(0, "mailmap-file", &mailmap_file, N_("read additional mailmap entries from file")), + OPT_STRING(0, "mailmap-blob", &mailmap_blob, N_("blob"), N_("read additional mailmap entries from blob")), OPT_END() }; @@ -56,6 +59,10 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix) die(_("no contacts specified")); read_mailmap(&mailmap); + if (mailmap_blob) + read_mailmap_blob(&mailmap, mailmap_blob); + if (mailmap_file) + read_mailmap_file(&mailmap, mailmap_file, 0); for (i = 0; i < argc; ++i) check_mailmap(&mailmap, argv[i]); diff --git a/mailmap.c b/mailmap.c index 2acf97f30760..9f9fa3199a85 100644 --- a/mailmap.c +++ b/mailmap.c @@ -142,11 +142,8 @@ static void read_mailmap_line(struct string_list *map, char *buffer) add_mapping(map, name1, email1, name2, email2); } -/* Flags for read_mailmap_file() */ -#define MAILMAP_NOFOLLOW (1<<0) - -static int read_mailmap_file(struct string_list *map, const char *filename, - unsigned flags) +int read_mailmap_file(struct string_list *map, const char *filename, + unsigned flags) { char buffer[1024]; FILE *f; @@ -186,7 +183,7 @@ static void read_mailmap_string(struct string_list *map, char *buf) } } -static int read_mailmap_blob(struct string_list *map, const char *name) +int read_mailmap_blob(struct string_list *map, const char *name) { struct object_id oid; char *buf; diff --git a/Documentation/git-check-mailmap.txt b/Documentation/git-check-mailmap.txt index 7747e38e25e3..966c91c46af7 100644 --- a/Documentation/git-check-mailmap.txt +++ b/Documentation/git-check-mailmap.txt @@ -27,6 +27,16 @@ OPTIONS Read contacts, one per line, from the standard input after exhausting contacts provided on the command-line. +--mailmap-file=:: + In addition to any configured mailmap files, read the specified + mailmap file. Entries in this file take precedence over entries in + either the default mailmap file or any configured mailmap file. + +--mailmap-blob=:: + Like `--mailmap-file`, but consider the value as a reference to a + blob in the repository. If both `--mailmap-file` and + `--mailmap-blob` are specified, entries in `--mailmap-file` will + take precedence. OUTPUT ------ From patchwork Tue Aug 27 21:27:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 13780174 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19F4318859A for ; Tue, 27 Aug 2024 21:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724794058; cv=none; b=NChGamHj70a2Rpq5e/Xkjw10Zm2G0BhYryJH16GrLx0vs4v6ZkB+8pXy1l+aGNtvMxyOAu8RC5uYqg9re9oGTN3b6eIsAKv0GVqqSry+7y6yosfv32KvcAwOu6a6TEd83pbIPHDTvSmYmDHuPBIkBgxP8Z3AWogAEJVtiolpaco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724794058; c=relaxed/simple; bh=R9iWmJ0X1ApjTVgxpL2yib0dM5JnDS/DDko2IU6DZgM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To; b=dOkicO9NwA8jeyQIumiWFjRw+ANe3fE9J8INmPMt7VGFplQ6kZzoAXB8fjCHxDdtnPCwVttcMw41VZOF3x6+SbrR+QEdTSWv5EhDN5h+t2BS5ChC6wUTNve8Xa7emAdiKWmm3I9SF9k0BZ1lxV0dP0iwEbnD24ZORR0//NVdU1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KihM1WwK; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KihM1WwK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724794057; x=1756330057; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to; bh=R9iWmJ0X1ApjTVgxpL2yib0dM5JnDS/DDko2IU6DZgM=; b=KihM1WwKWrH/0h5V8TZegs37bYW4GlUSx6CgXXQE6Saacz+3YhGK4sSo xNzVHEnN5F+mrhQCMGUGwKg7ZOuvwlfaDjGE38huYXhZm4sfsD5houVUU eTrnC0d05EeUa6SHuB0JuzTayRrXKYvwg+eow/EqMTIjbh37j78Xi9oG9 69IcR3XLGHZR+xGnRpp01IhuRoUKL6Lt2/rFbjTkpMLJL5G6nYocryTDX 8qSYHe/5spFUJ9fXGjB8E/gUj+mqrrO/zr6uVvZv335mvUwEEbnEyoarC 9IIvX53FPE+9KqzIjweDP2FtvtBEtRm6P7D6MSlDZZ1cN5Iz2erOtpoiz w==; X-CSE-ConnectionGUID: CLA+aHn+TjC/1xlqJebQZA== X-CSE-MsgGUID: LuUcJHv7TMWTPpSsS3noqw== X-IronPort-AV: E=McAfee;i="6700,10204,11177"; a="33959516" X-IronPort-AV: E=Sophos;i="6.10,181,1719903600"; d="scan'208";a="33959516" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Aug 2024 14:27:32 -0700 X-CSE-ConnectionGUID: jji5NXQfQDyue3oICleQvg== X-CSE-MsgGUID: BWMkTVoQRnuHwu3IQ/s+cg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,181,1719903600"; d="scan'208";a="63517537" Received: from jekeller-desk.jf.intel.com ([10.166.241.20]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Aug 2024 14:27:32 -0700 From: Jacob Keller Date: Tue, 27 Aug 2024 14:27:18 -0700 Subject: [PATCH v3 3/3] send-email: add mailmap support via sendemail.mailmap and --mailmap Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-jk-send-email-mailmap-support-v3-3-bec5ba9be391@gmail.com> References: <20240827-jk-send-email-mailmap-support-v3-0-bec5ba9be391@gmail.com> In-Reply-To: <20240827-jk-send-email-mailmap-support-v3-0-bec5ba9be391@gmail.com> To: Eric Sunshine , Josh Steadmon , git@vger.kernel.org, Junio C Hamano , Jeff King X-Mailer: b4 0.14.0 From: Jacob Keller In some cases, a user may be generating a patch for an old commit which now has an out-of-date author or other identity. For example, consider a team member who contributes to an internal fork of an upstream project, but leaves before this change is submitted upstream. In this case, the team members company address may no longer be valid, and will thus bounce when sending email. This can be manually avoided by editing the generated patch files, or by carefully using --suppress- options. This requires a lot of manual intervention and is easy to forget. Git has support for mapping old email addresses and names to a canonical name and address via the .mailmap file (and its associated mailmap.file, mailmap.blob, and log.mailmap options). Teach git send-email to enable mailmap support for all addresses. This ensures that addresses point to the canonical real name and email address. Add the sendemail.mailmap configuration option and its associated --mailmap (and --use-mailmap for compatibility with git log) options. For now, the default behavior is to disable the mailmap in order to avoid any surprises or breaking any existing setups. These options support per-identity configuration via the sendemail.identity configuration blocks. This enables identity-specific configuration in cases where users may not want to enable support. In addition, support send-email specific mailmap data via sendemail.mailmap.file, sendemail.mailmap.blob and their identity-specific variants. The intention of these options is to enable mapping addresses which are no longer valid to a current project or team maintainer. Such mappings may change the actual person being referred to, and may not make sense in a traditional mailmap file which is intended for updating canonical name and address for the same individual. Signed-off-by: Jacob Keller --- git-send-email.perl | 20 +++++++++ t/t9001-send-email.sh | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) diff --git a/git-send-email.perl b/git-send-email.perl index 72044e5ef3a8..8995d5f12d9e 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -46,6 +46,8 @@ sub usage { --compose-encoding * Encoding to assume for introduction. --8bit-encoding * Encoding to assume 8bit mails if undeclared --transfer-encoding * Transfer encoding to use (quoted-printable, 8bit, base64) + --[no-]mailmap * Use mailmap file to map all email addresses to canonical + real names and email addresses. Sending: --envelope-sender * Email envelope sender. @@ -272,12 +274,14 @@ sub do_edit { my ($auto_8bit_encoding); my ($compose_encoding); my ($sendmail_cmd); +my ($mailmap_file, $mailmap_blob); # Variables with corresponding config settings & hardcoded defaults my ($debug_net_smtp) = 0; # Net::SMTP, see send_message() my $thread = 1; my $chain_reply_to = 0; my $use_xmailer = 1; my $validate = 1; +my $mailmap = 0; my $target_xfer_encoding = 'auto'; my $forbid_sendmail_variables = 1; @@ -294,6 +298,7 @@ sub do_edit { "annotate" => \$annotate, "xmailer" => \$use_xmailer, "forbidsendmailvariables" => \$forbid_sendmail_variables, + "mailmap" => \$mailmap, ); my %config_settings = ( @@ -327,6 +332,8 @@ sub do_edit { my %config_path_settings = ( "aliasesfile" => \@alias_files, "smtpsslcertpath" => \$smtp_ssl_cert_path, + "mailmap.file" => \$mailmap_file, + "mailmap.blob" => \$mailmap_blob, ); # Handle Uncouth Termination @@ -524,6 +531,8 @@ sub config_regexp { "thread!" => \$thread, "validate!" => \$validate, "transfer-encoding=s" => \$target_xfer_encoding, + "mailmap!" => \$mailmap, + "use-mailmap!" => \$mailmap, "format-patch!" => \$format_patch, "8bit-encoding=s" => \$auto_8bit_encoding, "compose-encoding=s" => \$compose_encoding, @@ -1085,6 +1094,16 @@ sub expand_one_alias { our ($message_id, %mail, $subject, $in_reply_to, $references, $message, $needs_confirm, $message_num, $ask_default); +sub mailmap_address_list { + return @_ unless @_ and $mailmap; + my @options = (); + push(@options, "--mailmap-file=$mailmap_file") if $mailmap_file; + push(@options, "--mailmap-blob=$mailmap_blob") if $mailmap_blob; + my @addr_list = Git::command('check-mailmap', @options, @_); + s/^<(.*)>$/$1/ for @addr_list; + return @addr_list; +} + sub extract_valid_address { my $address = shift; my $local_part_regexp = qr/[^<>"\s@]+/; @@ -1294,6 +1313,7 @@ sub process_address_list { @addr_list = expand_aliases(@addr_list); @addr_list = sanitize_address_list(@addr_list); @addr_list = validate_address_list(@addr_list); + @addr_list = mailmap_address_list(@addr_list); return @addr_list; } diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 64a4ab3736ef..4bdc793a53a2 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -2379,6 +2379,128 @@ test_expect_success $PREREQ 'leading and trailing whitespaces are removed' ' test_cmp expected-list actual-list ' +test_expect_success $PREREQ 'mailmap support with --to' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + cat >mailmap.test <<-EOF && + Some Body + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example " \ + --smtp-server="$(pwd)/fake.sendmail" \ + --to=someone@example.org \ + --mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'sendemail.mailmap configuration' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + test_config sendemail.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example " \ + --smtp-server="$(pwd)/fake.sendmail" \ + --to=someone@example.org \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'sendemail.mailmap.file configuration' ' + clean_fake_sendmail && + test_config sendemail.mailmap.file "mailmap.test" && + test_config sendemail.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example " \ + --smtp-server="$(pwd)/fake.sendmail" \ + --to=someone@example.org \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'sendemail.mailmap identity overrides configuration' ' + clean_fake_sendmail && + test_config sendemail.cloud.mailmap.file "mailmap.test" && + test_config sendemail.mailmap "false" && + test_config sendemail.cloud.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example " \ + --smtp-server="$(pwd)/fake.sendmail" \ + --identity=cloud \ + --to=someone@example.org \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ '--no-mailmap overrides configuration' ' + clean_fake_sendmail && + test_config sendemail.cloud.mailmap.file "mailmap.test" && + test_config sendemail.mailmap "false" && + test_config sendemail.cloud.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example " \ + --smtp-server="$(pwd)/fake.sendmail" \ + --identity=cloud \ + --to=someone@example.org \ + --no-mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.org!$" commandline1 +' + +test_expect_success $PREREQ 'mailmap support in To header' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + cat >mailmap.test <<-EOF && + + EOF + git format-patch --stdout -1 --to=someone@example.org >a.patch && + git send-email \ + --from="Example " \ + --smtp-server="$(pwd)/fake.sendmail" \ + --mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'mailmap support in Cc header' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + cat >mailmap.test <<-EOF && + + EOF + git format-patch --stdout -1 --cc=someone@example.org >a.patch && + git send-email \ + --from="Example " \ + --smtp-server="$(pwd)/fake.sendmail" \ + --mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + test_expect_success $PREREQ 'test using command name with --sendmail-cmd' ' clean_fake_sendmail && PATH="$PWD:$PATH" \