From patchwork Tue Jan 17 01:37:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13104019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49E6DC54EBE for ; Tue, 17 Jan 2023 01:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235136AbjAQBiS (ORCPT ); Mon, 16 Jan 2023 20:38:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233226AbjAQBiC (ORCPT ); Mon, 16 Jan 2023 20:38:02 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2052.outbound.protection.outlook.com [40.107.100.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAA662B29A for ; Mon, 16 Jan 2023 17:37:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=obM29LIjKxyHOs2FnZ0AYYkV93IAWkkfr/XLmOhD1kFdyZnYa6Aez7+i1+wsFZ+GjBugAfaYr6Vrw6eXI28S7RSI0maOLdgDCm3sTwYGXSNuBFJrLmnOCXMVQlrfmTlIvMdkCSn186UtP9yC+A3uCp7656hjLeqV4Wl8qQ5zdveGV7E4Upwl0v8i/ZCzrF9NnABkzPzLSTdEnH7uvHd8yGSVd7Lkk9gl/nUXnoO330rh/5Lj7eDUNaWbUSB/4tLAMPqsYPn33bJepGyIJVT09Mc1LrlThavLmLMM3fPeKJJ/ENtSIyHmPrYWeztBtle4ya9XWT/jZ60rNf0yYjPUsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=unJ/BcNM1w47KD5X/qrbM56l0bB74cFhM+aATeoFI4I=; b=NEtpd535drRWaXJhBsP+Vc4uLszrer1EctR+4+k9zsi5Pyoypv1hHVG6yoygG2/LzDEAJtmM0atP2G1Z+Pos0Geo7DwZl73gXfeo0DSL0VzRS+/5AyP8j8CVjYZbUhO7fYtrdySzIgyJj5l1z8hq/CqzsMzch/Hh53QjDLHBgKgPHo0FPAmSERbEVH0a2LDWO5G7T9iv7oc6oICRtDoZ0+WdjYbaW3vWFZTCdtY/TSQ1Z+EJdZuJsXyIKiMvdT3Ani4Fm0jj89VIB6JgzWXMTzsB6DTnjp24oPrcLp1CtvtyqKr59kXbf5Qimz3V999O2w7cfv9lhrOqYvB7f+aWQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=unJ/BcNM1w47KD5X/qrbM56l0bB74cFhM+aATeoFI4I=; b=DxTpBy4yiQM4hf5QVpgqrr6eJt8LHpuW1Q8Veau3+UrAOStQu+bXOMD85tJc4eNVqD+odNZ89ufTiv5AG9Rs+kD5PsPzWWpL5wOqOoa2LrBwbt9ZZZFR7IPyodDyKHn+dV0e1FB7IN/xRuLkpXBg04Kdg610rGO2dO1Z8h0mkmQ= Received: from DM6PR12MB4356.namprd12.prod.outlook.com (2603:10b6:5:2aa::8) by MN0PR12MB5764.namprd12.prod.outlook.com (2603:10b6:208:377::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.23; Tue, 17 Jan 2023 01:37:38 +0000 Received: from DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::5484:99ef:2b52:eb77]) by DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::5484:99ef:2b52:eb77%3]) with mapi id 15.20.5986.019; Tue, 17 Jan 2023 01:37:38 +0000 From: "Strawbridge, Michael" To: "git@vger.kernel.org" CC: "Strawbridge, Michael" , "Tuikov, Luben" , Junio C Hamano Subject: [PATCH v5 2/2] send-email: expose header information to git-send-email's sendemail-validate hook Thread-Topic: [PATCH v5 2/2] send-email: expose header information to git-send-email's sendemail-validate hook Thread-Index: AQHZKhRI3pD5ftuX0kGmxDnSI6POhg== Date: Tue, 17 Jan 2023 01:37:38 +0000 Message-ID: <20230117013709.47054-3-michael.strawbridge@amd.com> References: <20230117013709.47054-1-michael.strawbridge@amd.com> In-Reply-To: <20230117013709.47054-1-michael.strawbridge@amd.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.34.1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR12MB4356:EE_|MN0PR12MB5764:EE_ x-ms-office365-filtering-correlation-id: a9a1d9f0-33a0-4c92-f040-08daf82b6afc x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: IpEGrz5ARhIdjqSV2fkaXhzAu3Tyj2ZTHNVr4rYuGq4fjacJ5EfberBGMClU5TCIujIfRY/P4BniXvztQft2vE8ZD6+ietWIs8+m+R1vkbL/ClCACZ42fWjHHeON2ZzU3i2BSTPnoBY/H2VajJFfDdZbNtbaodhGJu8CjjyfkDuMhxOcE0567nueQesovLOBDUpvNWNHuTjANwrFSIqwS2nG9c8LXCNCwwJqlw5AssOXqVTIvPNWH37D9GVB5XcZbL6A50+U51r2JMDm4JWmUojqwAjlsO4LE4jPaamAw5sLDz6PzCRSG6RqaUNrcfL7QBe39D2fq0e+G9Ei0FyfCcqNgAn5InQmA6/AO0H/qnTvZRJK2MWvsEJzwpiXqo0Sb6CTKgcYBvAQsJlcOyhYqezQqHivz9bmSBcxC1CbDBzxMQ0w0YVvm2gqcarQuDku4VibNb/HELZiuoj3caiSP5LLghDoLmrvE0nmyGJo2bv4GuwWEYnjqL7IZBOlfQAk8Cpv2A/zwDVpoZg5DA+Dbr+y6Ka6b4Vc+o2KuBbadGfzziLbLQUrH37UOhyoz7qXJj30qp4yA5Su6VGkUNSVDjRxxfW2V2wSES0FkyDCanoJ8bGQ9PmXRgJJoqSibCqBufnMs7YDl4W10F3pnSk5Vh3xTvkuy/pd/GlWjaNcY377+xx9AcgykZaCUrU9cZBDZcs8u8faN9i3gkwY69h/gQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4356.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(346002)(39860400002)(136003)(366004)(451199015)(71200400001)(316002)(478600001)(122000001)(6486002)(5660300002)(1076003)(36756003)(54906003)(6916009)(38100700002)(4326008)(15650500001)(8676002)(6512007)(38070700005)(2906002)(8936002)(83380400001)(2616005)(41300700001)(186003)(26005)(64756008)(86362001)(66556008)(76116006)(66446008)(66476007)(66946007)(91956017)(6506007);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?M24NNbAl6fOEaHCXWcqBVH3?= =?iso-8859-1?q?FGwNzmHLSdfNso9guEROxtCz56wOP0LEXwl+su6FGJMnvxSsS2v3IVjcQlDo?= =?iso-8859-1?q?/k9hYUPJc9sRTuaOy4ApV2dn8h/5FCij4+63NAQjQS5jr/0Gss9QDyY0wF0g?= =?iso-8859-1?q?jg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X/rHybrcOnI5p+lM0BHmJZYdcevIICPqwb58z8/?= =?iso-8859-1?q?e4p1SeBtDYyJgEfjS0dG0RtrC6V2CruS7Da39UyOWVXul/KRacQhYFbk+4ei?= =?iso-8859-1?q?FkZTgvQPnIdwDa/LvyaTJCEKvMu/6VsK5vYSigmlNT+59TN7tPaYsfTOSFWd?= =?iso-8859-1?q?ySOGzLx6izqMtePNw8n7YcqipJg0UsIJpoFbG+99C8rtu/4OqaxkdJTJtIwb?= =?iso-8859-1?q?SOKOzBYpkuabhyN2oSmMuKEEEZXThtxnTBbf1l9cgDPQPQUCWYcicZyUlX8P?= =?iso-8859-1?q?h4N9lMksA9UDi6hyVTPC/mh7hrEHfE+OlPEV0jop0P1yGAA7pJ6kujlKqh4/?= =?iso-8859-1?q?Cpj2Viq4RuyarDQFDLBdvjS20HEnc3yiu4YpKv0HwfChO58jfP1+MyIMLFFH?= =?iso-8859-1?q?dLlkt+h+wD2T+D7+a9FtTrt2hObMLbqWo2kOOX2yA3lJO5axw4mMgIDQ2sH+?= =?iso-8859-1?q?K0kxsYHDWiygvFoFgQIGyWrbAJe4oR8IQ8tqRIjgYAQNdafVvucUA8bPWppy?= =?iso-8859-1?q?J947xo/KbUC52AfXcDOY+vmUW/PUM5ZewRGXIqsjw37zgxDTnH6UBoz1bAWt?= =?iso-8859-1?q?jfn7PsczyGAz1qqDC?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4356.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a9a1d9f0-33a0-4c92-f040-08daf82b6afc X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2023 01:37:38.7966 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5PS1GKWu8p3XIzlM7fmX8U1WJrxJBY263pWc3N2tvLDAgg8FikmT81i6xo+/hC5stxsTomK8QvoZqZhKVrSDUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5764 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To allow further flexibility in the git hook, the SMTP header information of the email that git-send-email intends to send, is now passed as a 2nd argument to the sendemail-validate hook. As an example, this can be useful for acting upon keywords in the subject or specific email addresses. Cc: Luben Tuikov Cc: Junio C Hamano Signed-off-by: Michael Strawbridge --- Documentation/githooks.txt | 17 +++++++++++++---- git-send-email.perl | 31 +++++++++++++++++++++---------- t/t9001-send-email.sh | 29 +++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index a16e62bc8c..2b5c6640cc 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -583,10 +583,19 @@ processed by rebase. sendemail-validate ~~~~~~~~~~~~~~~~~~ -This hook is invoked by linkgit:git-send-email[1]. It takes a single parameter, -the name of the file that holds the e-mail to be sent. Exiting with a -non-zero status causes `git send-email` to abort before sending any -e-mails. +This hook is invoked by linkgit:git-send-email[1]. + +It takes these command line arguments: +1. the name of the file that holds the e-mail to be sent. +2. the name of the file that holds the SMTP headers to be used. + +The hook doesn't need to support multiple header names (for example only Cc +is passed). However, it does need to understand that lines beginning with +whitespace belong to the previous header. The header information follows +the same format as the confirmation given at the end of send-email. + +Exiting with a non-zero status causes `git send-email` to abort +before sending any e-mails. fsmonitor-watchman ~~~~~~~~~~~~~~~~~~ diff --git a/git-send-email.perl b/git-send-email.perl index 810dd1f1ce..b2adca515e 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -787,14 +787,6 @@ sub is_format_patch_arg { @files = handle_backup_files(@files); -if ($validate) { - foreach my $f (@files) { - unless (-p $f) { - validate_patch($f, $target_xfer_encoding); - } - } -} - if (@files) { unless ($quiet) { print $_,"\n" for (@files); @@ -1738,6 +1730,16 @@ sub send_message { return 1; } +if ($validate) { + foreach my $f (@files) { + unless (-p $f) { + pre_process_file($f, 1); + + validate_patch($f, $target_xfer_encoding); + } + } +} + $in_reply_to = $initial_in_reply_to; $references = $initial_in_reply_to || ''; $message_num = 0; @@ -2101,11 +2103,20 @@ sub validate_patch { chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); + + my ($recipients_ref, $to, $date, $gitversion, $cc, $ccline, $header) = gen_header(); + + require File::Temp; + my ($header_filehandle, $header_filename) = File::Temp::tempfile( + ".gitsendemail.header.XXXXXX", DIR => $repo->repo_path()); + print $header_filehandle $header; + my @cmd = ("git", "hook", "run", "--ignore-missing", $hook_name, "--"); - my @cmd_msg = (@cmd, ""); - my @cmd_run = (@cmd, $target); + my @cmd_msg = (@cmd, "", "
"); + my @cmd_run = (@cmd, $target, $header_filename); $hook_error = system_or_msg(\@cmd_run, undef, "@cmd_msg"); + unlink($header_filehandle); chdir($cwd_save) or die("chdir: $!"); } if ($hook_error) { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 1130ef21b3..f02b1eba16 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -540,7 +540,7 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual @@ -559,7 +559,32 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 + warning: no patches were sent + EOF + test_cmp expect actual +' + +test_expect_success $PREREQ "--validate hook supports header argument" ' + test_when_finished "rm my-hooks.ran" && + write_script my-hooks/sendemail-validate <<-\EOF && + filesize=$(stat -c%s "$2") + if [ "$filesize" != "0" ]; then + >my-hooks.ran + fi + exit 1 + EOF + test_config core.hooksPath "my-hooks" && + test_must_fail git send-email \ + --from="Example " \ + --to=nobody@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + --validate \ + longline.patch 2>actual && + test_path_is_file my-hooks.ran && + cat >expect <<-EOF && + fatal: longline.patch: rejected by sendemail-validate hook + fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual