From patchwork Fri May 28 09:23:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0AC1C4708C for ; Fri, 28 May 2021 09:24:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B52CF6127A for ; Fri, 28 May 2021 09:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236181AbhE1JZg (ORCPT ); Fri, 28 May 2021 05:25:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235672AbhE1JZd (ORCPT ); Fri, 28 May 2021 05:25:33 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC2EC06174A for ; Fri, 28 May 2021 02:23:57 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id l18-20020a1c79120000b0290181c444b2d0so1977502wme.5 for ; Fri, 28 May 2021 02:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jYXqFWJmbITdUifHX7psazBPf1OOFD6Z85t7c+XZhlo=; b=hYqdAPGByfRKmxhRUJPWIDl7T5J38M4HtpgnoI6etflPT3ZYvK/mybQb78VR5BYc9D C9lMRWM36PToawEVXraERyTnf9DUyNyVmoMHKHp6svb8gpPY12mGl+AX8HMnethJOIGn nHOexafMWsrpGm2wbN+L1h2h3oppCLQK7fO/VGpfHpRqkLfwhIPUn3EtwaJyLc8zJSiS eOpl98kprqycvFu0BiB4ltYgwzE6izirUSotZgpVoqcOqjtiKeZ0XseHdqyWxzWdeWUZ 7ZlbNxkpxPjm+25fxNoLvQ9MEElcs7ohflO4CZX7ZCPu+90iJs/Y9Xnl9989+GSMHXdK qEJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jYXqFWJmbITdUifHX7psazBPf1OOFD6Z85t7c+XZhlo=; b=KO7KqOou8qbOvz0ukwyA9kPli/sJDZzzgxnx5NetJF3VaMACoPdcsU3NQXi8x+5fCT dM+m35JhUcJ2ADZa6qOAHToSa0JoGwWUBuCbI5+YXCCdg7oGgRu7fWMWQLTCFRI+hMQ7 yieSK2rsizE/PsTdxvsHdUT/LYtmtpFYyrxfktWuNM5YFWC8qYbQ+YuXYqdZ3QLn91Qx p4V2o3ew4RUVvkaR5w8uKol0Sq/zxW+tTh0EW5dFH3JaaeL83np6osM7yG6cHUofVrIJ lP5EYyZN0iXZm+cIPns6JaWA5sIMy1XD0x96gdlqk9vAdZAWKqmwIMzsC7j1aELuoyo2 bkzQ== X-Gm-Message-State: AOAM530MF7i77c3UAqNlTf5DUWkfrt3huWrWkwNPHu0bldFaIeaHSV6V 2JB157cbq9fi1/FX1/2D7fL1mqDAfX1zoA== X-Google-Smtp-Source: ABdhPJxbG8AlZbBNo8cIOYu4x+60SPFq3k2zxiglSV7+rLV2jHus+TQVJBv8uEj4iLZo3tlL4D9dYQ== X-Received: by 2002:a1c:61c3:: with SMTP id v186mr839091wmb.101.1622193835572; Fri, 28 May 2021 02:23:55 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:23:54 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 01/13] send-email tests: support GIT_TEST_PERL_FATAL_WARNINGS=true Date: Fri, 28 May 2021 11:23:40 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add support for the "GIT_TEST_PERL_FATAL_WARNINGS=true" test mode to "send-email". This was added to e.g. git-svn in 5338ed2b26 (perl: check for perl warnings while running tests, 2020-10-21), but not "send-email". Let's rectify that. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 25be2ebd2af..1630e87cd4d 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -18,7 +18,7 @@ use 5.008; use strict; -use warnings; +use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : (); use POSIX qw/strftime/; use Term::ReadLine; use Getopt::Long; From patchwork Fri May 28 09:23:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29500C4708C for ; Fri, 28 May 2021 09:24:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A0F3613B6 for ; Fri, 28 May 2021 09:24:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236200AbhE1JZj (ORCPT ); Fri, 28 May 2021 05:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236122AbhE1JZd (ORCPT ); Fri, 28 May 2021 05:25:33 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 079F7C061760 for ; Fri, 28 May 2021 02:23:58 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v23so249650wrd.10 for ; Fri, 28 May 2021 02:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sv7iNawyF3qxEolByD3bBsf8/A55eF52TTUmYN40oLo=; b=JuU3HncdvSTaMDPJns7Rwm9Rbavz2ATDYIHDwN8EpQR7Z5tTAlq2EnFPq8B/9i8S7g a+2aJTioj0hUdkrZB5Azeg0XIRwwgRxjVdnjRqVSRefHvhGR49nwlsEkanjxg3Aj5YAA i1kTwGw53HAM4D5UMtGhjlBLXE5jbc0jhn+nROgLGeFFjg/i/z6j/RIcXatfKuBNzdCt aU3leNvUcYtkwDSqM/aH0qXq/ZuZ14VySlWIXLFI0CGicIbA2I+R7tdE3WHMOH6ewJYs bAk2BDY2gRkGOzvDZ4+ZA2rRkOXbIgrMHSX7hvIRELaoCT9vtyvW4yj8fwZAXfxITa+g vAxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sv7iNawyF3qxEolByD3bBsf8/A55eF52TTUmYN40oLo=; b=qqDXslrE54aC58+LeOY2c8+/rc2aU+gDc+WaGN5IFMylTFLF0mp29q5+BwcmwfBjks sPqL519N7NhXFj0lr+suGvBNKX4p84f29Cb5iw9IC7WlXJDomrZxIhFhe70QP4EdMmIE iPsNcBVZAbFQwELS5Dw+FyePQ8CyJxUFsNObXnjOorceRfpn7+Lk2uZu7TPD28nRqqnC n9uuH+xDZhWpixsILdUJtVgx5ULaMdgTKqNey6+0+taCqkpYF1znjB19y7eBBz8I+bGA 47EciQ//AuWXGeTCcsXzOg0kh74Kg+ulDJKoW/ad/qoP5xFTBNUONvR3HnnaeZdMwSvE Kvwg== X-Gm-Message-State: AOAM531vj76YeC4gwgGHES1vl9hAN9t6AR+iKYNldB0t7XcB9wHmQnjE aKXbbgm/wlpx/HhV5rHPtFI8wKYkouKW9A== X-Google-Smtp-Source: ABdhPJz2hFPQtVsVRQg2ZaiNVlsI25w5FuqiwcSX4MoCVxI+X0l2SpM9w0i2DHVWDiFEXyMj4PsVmw== X-Received: by 2002:adf:f7c4:: with SMTP id a4mr7612639wrq.20.1622193836350; Fri, 28 May 2021 02:23:56 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:23:55 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 02/13] send-email tests: test for boolean variables without a value Date: Fri, 28 May 2021 11:23:41 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The Git.pm code does its own Perl-ifying of boolean variables, let's ensure that empty values = true for boolean variables, as in the C code. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t9001-send-email.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 3b7540050ca..612de095fd7 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1368,6 +1368,16 @@ test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' ' ! grep "X-Mailer" stdout ' +test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' ' + git -c sendemail.xmailer \ + send-email \ + --dry-run \ + --from="nobody@example.com" \ + $patches >stdout && + grep "To: default@example.com" stdout && + grep "X-Mailer" stdout +' + test_expect_success $PREREQ '--no-to overrides sendemail.to' ' git send-email \ --dry-run \ @@ -2092,6 +2102,18 @@ test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' ' do_xmailer_test 1 "--xmailer" ' +test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' ' + test_when_finished "test_unconfig sendemail.xmailer" && + cat >>.git/config <<-\EOF && + [sendemail] + xmailer + EOF + test_config sendemail.xmailer true && + do_xmailer_test 1 "" && + do_xmailer_test 0 "--no-xmailer" && + do_xmailer_test 1 "--xmailer" +' + test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' ' test_config sendemail.xmailer false && do_xmailer_test 0 "" && @@ -2099,6 +2121,13 @@ test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' ' do_xmailer_test 1 "--xmailer" ' +test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' ' + test_config sendemail.xmailer "" && + do_xmailer_test 0 "" && + do_xmailer_test 0 "--no-xmailer" && + do_xmailer_test 1 "--xmailer" +' + test_expect_success $PREREQ 'setup expected-list' ' git send-email \ --dry-run \ From patchwork Fri May 28 09:23:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3853AC4708D for ; Fri, 28 May 2021 09:24:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CFD36127A for ; Fri, 28 May 2021 09:24:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236166AbhE1JZh (ORCPT ); Fri, 28 May 2021 05:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236104AbhE1JZe (ORCPT ); Fri, 28 May 2021 05:25:34 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE892C061574 for ; Fri, 28 May 2021 02:23:58 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id f75-20020a1c1f4e0000b0290171001e7329so2003639wmf.1 for ; Fri, 28 May 2021 02:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=buaQsRPXqAyBpxHx0C/x1vNTJBc8mxwyFQSYVkK46SI=; b=m289FLxElmcF/9wlCekL/oX151id1lYrUfEmIs8eGqQfDwmjC+NHtDSR3Fej9NmD9a ZCM5JgO8zHsFQz0iVKhBl2kfRxc7dIxtznyiJrBXA+fXyA62zmUm/bRmCTzc9Kj8fuAV xGIdSV1ZJiRXg2lN/cQcyvVdVok9eZpbok4UZi7/0tnovnpxX/XtWd01UUReCQc4gMpd EuXAdQM8zpw1sQ6gEtpNU1IBNMSz32CyhnJaG4BEwd0Q2On00VziD6Aw/PZGm8tLSuBh ecJm6ANS4XWvzEtipwz44/sJCUZyuN5nuDxcNB9Frt9UidScU+CFm+Qvt2jHClKK0hiD n+tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=buaQsRPXqAyBpxHx0C/x1vNTJBc8mxwyFQSYVkK46SI=; b=rbFnD52wgfEYCyBdNjkz+IGfujHyCKEGu+4Z1Eba3aQGzMhgfM5+qPVcIyQluxfZHs HW1aGGqnrTdXDJnHlXV2SxKaan8or2O2bj1mnSCyoY9ndhxWLtBcwrW8/jVRzVIjUKrq AcwyBo1oFgRmHHBIaGuHYCNKUUQkeSfadutDLayt8v3OfPiUSfBlQmqiI0MVCYYs43eI x9+P6yqDympOIoUBEsla2IPbMtCoiT5H6Pp3DM9OXyePHELea850Cz5tI/XjFoGbvlIh 9iH3nh3rxUIgUyZJF10FDdotly7qq1X/3GgU08Ytr0PsEO7fL+2YAx48qV7+8hnh1SWl 7w2w== X-Gm-Message-State: AOAM531DQP+c4/jkklu/i9iZx68J1VZtJzlzVuyka3pDLe+k6JACJUFd lZc3zplbWep33Mo42rylLlu/0LarG8OnZg== X-Google-Smtp-Source: ABdhPJyUvI0U7RSS9WDAY02goa1fwS67uXNXDNfjoPDl5E2tPmLeXMtrS+2WA5YTX9/q7nl7vld5Tw== X-Received: by 2002:a7b:cc88:: with SMTP id p8mr12682923wma.171.1622193837234; Fri, 28 May 2021 02:23:57 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:23:56 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 03/13] send-email: remove non-working support for "sendemail.smtpssl" Date: Fri, 28 May 2021 11:23:42 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the already dead code to support "sendemail.smtpssl" by finally removing the dead code supporting the configuration option. In f6bebd121ac (git-send-email: add support for TLS via Net::SMTP::SSL, 2008-06-25) the --smtp-ssl command-line option was documented as deprecated, later in 65180c66186 (List send-email config options in config.txt., 2009-07-22) the "sendemail.smtpssl" configuration option was also documented as such. Then in in 3ff15040e22 (send-email: fix regression in sendemail.identity parsing, 2019-05-17) I unintentionally removed support for it by introducing a bug in read_config(). As can be seen from the diff context we've already returned unless $enc i defined, so it's not possible for us to reach the "elsif" branch here. This code was therefore already dead since Git v2.23.0. So let's just remove it. We were already 11 years into a stated deprecation period of this variable when 3ff15040e22 landed, now it's around 13. Since it hasn't worked anyway for around 2 years it looks like we can safely remove it. The --smtp-ssl option is still deprecated, if someone cares they can follow-up and remove that too, but unlike the config option that one could still be in use in the wild. I'm just removing this code that's provably unused already. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/config/sendemail.txt | 3 --- git-send-email.perl | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Documentation/config/sendemail.txt b/Documentation/config/sendemail.txt index cbc5af42fdf..50baa5d6bfb 100644 --- a/Documentation/config/sendemail.txt +++ b/Documentation/config/sendemail.txt @@ -8,9 +8,6 @@ sendemail.smtpEncryption:: See linkgit:git-send-email[1] for description. Note that this setting is not subject to the 'identity' mechanism. -sendemail.smtpssl (deprecated):: - Deprecated alias for 'sendemail.smtpEncryption = ssl'. - sendemail.smtpsslcertpath:: Path to ca-certificates (either a directory or a single file). Set it to an empty string to disable certificate verification. diff --git a/git-send-email.perl b/git-send-email.perl index 1630e87cd4d..9a1a4898e36 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -393,11 +393,7 @@ sub read_config { my $enc = Git::config(@repo, $setting); return unless defined $enc; return if $configured->{$setting}++; - if (defined $enc) { - $smtp_encryption = $enc; - } elsif (Git::config_bool(@repo, "$prefix.smtpssl")) { - $smtp_encryption = 'ssl'; - } + $smtp_encryption = $enc; } } From patchwork Fri May 28 09:23:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286467 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 306CDC4708C for ; Fri, 28 May 2021 09:24:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0980C613B6 for ; Fri, 28 May 2021 09:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236037AbhE1JZm (ORCPT ); Fri, 28 May 2021 05:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236093AbhE1JZf (ORCPT ); Fri, 28 May 2021 05:25:35 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D02C061761 for ; Fri, 28 May 2021 02:23:59 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id z19-20020a7bc7d30000b029017521c1fb75so4187379wmk.0 for ; Fri, 28 May 2021 02:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IOniThVSCYtkiM3dR38e2nO2uTv+Yd9uJOvEFMzsuKs=; b=PF2UIMve8wFL3JhVYybUVhA+5NvwIfg0MAi43NLEUNftaWTRpQfdFg9UwEN9Epabw/ 4E36dSmiEv691rkrLcJWm/50jeHTe44+Q5hDOxmNrkX4kTnjbW2TR/nTzDUG0b9lCBBI fEECKkK5LVrIKAxDflbUIfJ3yrEPelkmimrd+/yWe1wsrNnn6WKwe22TJrVu8z5fcpSz w8EcEvCpOexUvFEji4ShqeYAoN8Jxmmzv/Y5EFLQji5Z93fsuMeln0Y1YIof+8K7+YbG qe2G0CQCD2u+7Cuzdxd+gT5p2zLq+Xyly/HtXnjw/J9aiYRgM3dlMkKMGThuVmB0MHUX /GEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IOniThVSCYtkiM3dR38e2nO2uTv+Yd9uJOvEFMzsuKs=; b=Vo/9cdfX8nw720uqYwea0tStmqx/ZpUURC4ZZGTZmgrZphgBbNFZFT+uZHZNiU4Xpb EptB3XqptUI7KBrd1oN6bKYLNs9yCcdxm2T+um9yu28i9ZQVsqIx6ylJaOkj7yt8vOCU Ye4VU+LEu+94NW7WX/wRu+voDk0eaHSYVyeDRWRm08JhzsASlKsXAOhU6pkEOorF8HGu o8YbWDYqOFbqpvVrvYVsPyXxszHzzzRV2nXrilY84ngF1K11S914RF/hArPHgV60+KUK 3EzEWRp26X1jfdoYzT3kE8usQg6a5uKlk0mc6zHCLSy2tePI1xBvm2h5BDvqX4XOKIpK qWgQ== X-Gm-Message-State: AOAM533E6Yabaq8TcWMvvamWurAqf1LeXlsl/3iJf10vrvdUQ1d/RuJf yzYovjHvWdJRMykLV0Pg7Iw+GlQR/y7wLQ== X-Google-Smtp-Source: ABdhPJxjoIE6NayX5rxcWo86OQAXfjyIjDA9lXLvicKODmPlm7eX+DHrdRLaXhlihNrzN1PItzUd5A== X-Received: by 2002:a1c:2985:: with SMTP id p127mr7619242wmp.165.1622193838018; Fri, 28 May 2021 02:23:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:23:57 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 04/13] send-email: refactor sendemail.smtpencryption config parsing Date: Fri, 28 May 2021 11:23:43 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org With the removal of the support for sendemail.smtpssl in the preceding commit the parsing of sendemail.smtpencryption is no longer special, and can by moved to %config_settings. This gets us rid of an unconditional call to Git::config(), which as we'll see in subsequent commits matters for startup performance. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 9a1a4898e36..e2fe112aa50 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -287,6 +287,7 @@ sub do_edit { ); my %config_settings = ( + "smtpencryption" => \$smtp_encryption, "smtpserver" => \$smtp_server, "smtpserverport" => \$smtp_server_port, "smtpserveroption" => \@smtp_server_options, @@ -387,14 +388,6 @@ sub read_config { $$target = $v; } } - - if (!defined $smtp_encryption) { - my $setting = "$prefix.smtpencryption"; - my $enc = Git::config(@repo, $setting); - return unless defined $enc; - return if $configured->{$setting}++; - $smtp_encryption = $enc; - } } # sendemail.identity yields to --identity. We must parse this From patchwork Fri May 28 09:23:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 906D4C4708C for ; Fri, 28 May 2021 09:24:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 39EBB613AB for ; Fri, 28 May 2021 09:24:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236104AbhE1JZw (ORCPT ); Fri, 28 May 2021 05:25:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234673AbhE1JZg (ORCPT ); Fri, 28 May 2021 05:25:36 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79017C061763 for ; Fri, 28 May 2021 02:24:00 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id r10so2544233wrj.11 for ; Fri, 28 May 2021 02:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jYTaphZCrPGt4gPKzb7ds5CzSlafOXTD8Kr5Bf8VWf4=; b=iHKXyQBE6SghZwwj8UDYIBoZw3+6lrM3xyuZ9//A06mG8YRDTfUcOFQ4OPW5A9a1xS 6D0JDa/QVJ3PAxksx5qV4QDn4DLvF6TJRTt+ISyi0ju+YUrLYlbGLF9XM8ciunOay2ig iFNdfHfO89+IDqTQuBw+3Mt5UsyhJZs70rqa2Dcym7VvfKvM1sL5zOwdqGsquUVOigid xsfX+6kvZB5d45sb9kFI88MDef7nEvcwWvDb61YrPJs6qA3DaYa1V6Qzs+gJxXWp60yw nKmxsNNHRFZxWWDe2CG0jfq9UD/jbRPbVtT/W4JEWHUmgoDlv7hPS5CXAoofxMAMTrIY 5fUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jYTaphZCrPGt4gPKzb7ds5CzSlafOXTD8Kr5Bf8VWf4=; b=Hz7C5vFU+eD2K8O/n0kJzMBacU9HbljnaYUu6NH1FXw515J5VVGVrXVkDHDf4pzHQK xG2Q2kJ+anXSIm1fYXwus3ZB2PFLKfQdpSjAY1AR1ahmPy4IYp9YQN/aTrC+l8Erw58Q ExgYuM5YEvNQ/e1QYbDFBRjI5h+8CjsrR1srQ+8uBQDeBiclqH8fbYJXMPyIOZcUIX4F +Tewas3Er/a+FZDDtXGBrDajunytHD9Y78RWR2TO29b6gWsBJBnDrGAt/tepWCI3JqMy +2AQnMyiSuxmA4usIMwrJ3/hnQrKHf+SZmkoJ8bQLKgsAu+MmQyiNN3/uxxYo/N8aEIW 4e6w== X-Gm-Message-State: AOAM531gJFXYhBzhU2Bv/9Sgi6wTTgg15wrzX8ePV35DA3dZXDEiJrma itRY3oW+nwVwNsiLmzjrEqKXpiiid2OXBQ== X-Google-Smtp-Source: ABdhPJyamyaKLdcdwq/8Owxnv+jZmMoZmfdMKZ8ux3wjMB6tCNpQh515MlxpdSjpLMQWDzTMuMlIzw== X-Received: by 2002:adf:ed47:: with SMTP id u7mr7716967wro.254.1622193838794; Fri, 28 May 2021 02:23:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:23:58 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 05/13] send-email: copy "config_regxp" into git-send-email.perl Date: Fri, 28 May 2021 11:23:44 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The config_regexp() function was added in dd84e528a3 (git-send-email: die if sendmail.* config is set, 2020-07-23) for use in git-send-email, and it's the only in-tree user of it. However, the consensus is that Git.pm is a public interface, so even though it's a recently added function we can't change it. So let's copy over a minimal version of it to git-send-email.perl itself. In a subsequent commit it'll be changed further for our own use. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index e2fe112aa50..73e3d3fd26e 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -390,6 +390,24 @@ sub read_config { } } +sub config_regexp { + my ($regex) = @_; + my @ret; + eval { + @ret = Git::command( + 'config', + '--name-only', + '--get-regexp', + $regex, + ); + 1; + } or do { + # If we have no keys we're OK, otherwise re-throw + die $@ if $@->value != 1; + }; + return @ret; +} + # sendemail.identity yields to --identity. We must parse this # special-case first before the rest of the config is read. $identity = Git::config(@repo, "sendemail.identity"); @@ -488,7 +506,7 @@ sub read_config { usage(); } -if ($forbid_sendmail_variables && (scalar Git::config_regexp("^sendmail[.]")) != 0) { +if ($forbid_sendmail_variables && (scalar config_regexp("^sendmail[.]")) != 0) { die __("fatal: found configuration options for 'sendmail'\n" . "git-send-email is configured with the sendemail.* options - note the 'e'.\n" . "Set sendemail.forbidSendmailVariables to false to disable this check.\n"); From patchwork Fri May 28 09:23:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77E49C4708D for ; Fri, 28 May 2021 09:24:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57643613DA for ; Fri, 28 May 2021 09:24:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233765AbhE1JZo (ORCPT ); Fri, 28 May 2021 05:25:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235486AbhE1JZf (ORCPT ); Fri, 28 May 2021 05:25:35 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77C9CC061574 for ; Fri, 28 May 2021 02:24:01 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id z17so2578152wrq.7 for ; Fri, 28 May 2021 02:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4Lgez7bXRJfnEo5NZCxZLVUuigKOPiYSLOjMB29Vs5E=; b=Wo2vMuo2HxwIvr6KbyIewRtI5161vZXqvVVYGvgzmYiUY1XVqz6/NmNRRjK4dDqPJk UoAmkrR7crg3Vv1HxxdQisNvKSF6KQvDzINAX7eLUxxfG7ARUj/oIPPkEo7beM8kKq7H 05RjqnfxVnS+hSV2muT9c/U3Q+PH4dslICxMTRcrKYqyHv8MAFPM2JscAHxvFGIHXXZA q8wRGDEOZRnfGtDOdfFmfX0tU8ICjYwVs/ztjii8tXNPpr0YgzhchZIfjHf+od0sFQ04 BLEPRobD1/TytI1H3TvzpkSO5E4wDhsbcg8uIs7Z0WTPLOLoDFQpUXkuyUSsLihN1bQR 2I+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Lgez7bXRJfnEo5NZCxZLVUuigKOPiYSLOjMB29Vs5E=; b=lgR8T9ge9knAEZrgrj4MRWJ0LV0/j53lpVvopum5DDAmnJ/RqeAOGm/rnZc7k6lG6c PHP4h0XnEB4zlqDAFlVtHfcNGyrnvonkmb3y9LtLJUu/c5vupGRFS9QWr1LeETN4vLt+ Uph4qNMe7F8KNDrLMkPRbgmkp3ClDkUNPzD6kFsmoodkmhVQPg+VSVUBujDUcrb5wJCy cSlDLWL1zNNgSwNDsn3+C3qg2C7K2/6EQWy80R/FBMLuPsI4JTNtCugDQDeyYwt74jKe PbeFrEQ6AwY3dFfr30/tPExWzQxTfsA+If/nnlVDcpgl4FgcFAYRcZjKjw0D7sD0lkpI 2zTg== X-Gm-Message-State: AOAM530lPEM4R8JR9ENjVJw/NWqG9lz52mpviR6nuuv50cqp+i3T/eF4 v7RIt7R6BqSj5HerwFTnUNIBwXimzv8hwQ== X-Google-Smtp-Source: ABdhPJxRJzKmBkEjCmqSkYR7nHyvkzULdfA6rCHuZO1Xov8geBalrhPvuKTWELPuQEOvEPaW9U780A== X-Received: by 2002:a5d:678d:: with SMTP id v13mr7715137wru.83.1622193839657; Fri, 28 May 2021 02:23:59 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:23:59 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 06/13] send-email: lazily load config for a big speedup Date: Fri, 28 May 2021 11:23:45 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Reduce the time it takes git-send-email to get to even the most trivial of tasks (such as serving up its "-h" output) by first listing config keys that exist, and only then only call e.g. "git config --bool" on them if they do. Over a lot of runs this speeds the time to "-h" up for me from ~250ms to ~150ms, and the runtime of t9001-send-email.sh goes from ~25s to ~20s. This introduces a race condition where we'll do the "wrong" thing if a config key were to be inserted between us discovering the list and calling read_config(), i.e. we won't know about the racily added key. In theory this is a change in behavior, in practice it doesn't matter. The config_regexp() function being changed here was added in dd84e528a34 (git-send-email: die if sendmail.* config is set, 2020-07-23) for use by git-send-email. So we can change its odd return value in the case where no values are found by "git config". The difference in the *.pm code would matter if it was invoked in scalar context, but now it no longer is. Arguably this caching belongs in Git.pm itself, but in lieu of modifying it for all its callers let's only do this for "git send-email". The other big potential win would be "git svn", but unlike "git send-email" it doesn't check tens of config variables one at a time at startup (in my brief testing it doesn't check any). Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 73e3d3fd26e..de62cbf2506 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -347,11 +347,13 @@ sub signal_handler { # Read our sendemail.* config sub read_config { - my ($configured, $prefix) = @_; + my ($known_keys, $configured, $prefix) = @_; foreach my $setting (keys %config_bool_settings) { my $target = $config_bool_settings{$setting}; - my $v = Git::config_bool(@repo, "$prefix.$setting"); + my $key = "$prefix.$setting"; + next unless exists $known_keys->{$key}; + my $v = Git::config_bool(@repo, $key); next unless defined $v; next if $configured->{$setting}++; $$target = $v; @@ -359,8 +361,10 @@ sub read_config { foreach my $setting (keys %config_path_settings) { my $target = $config_path_settings{$setting}; + my $key = "$prefix.$setting"; + next unless exists $known_keys->{$key}; if (ref($target) eq "ARRAY") { - my @values = Git::config_path(@repo, "$prefix.$setting"); + my @values = Git::config_path(@repo, $key); next unless @values; next if $configured->{$setting}++; @$target = @values; @@ -375,14 +379,16 @@ sub read_config { foreach my $setting (keys %config_settings) { my $target = $config_settings{$setting}; + my $key = "$prefix.$setting"; + next unless exists $known_keys->{$key}; if (ref($target) eq "ARRAY") { - my @values = Git::config(@repo, "$prefix.$setting"); + my @values = Git::config(@repo, $key); next unless @values; next if $configured->{$setting}++; @$target = @values; } else { - my $v = Git::config(@repo, "$prefix.$setting"); + my $v = Git::config(@repo, $key); next unless defined $v; next if $configured->{$setting}++; $$target = $v; @@ -408,9 +414,20 @@ sub config_regexp { return @ret; } +# Save ourselves a lot of work of shelling out to 'git config' (it +# parses 'bool' etc.) by only doing so for config keys that exist. +my %known_config_keys; +{ + my @known_config_keys = config_regexp("^sende?mail[.]"); + @known_config_keys{@known_config_keys} = (); +} + # sendemail.identity yields to --identity. We must parse this # special-case first before the rest of the config is read. -$identity = Git::config(@repo, "sendemail.identity"); +{ + my $key = "sendemail.identity"; + $identity = Git::config(@repo, $key) if exists $known_config_keys{$key}; +} my $rc = GetOptions( "identity=s" => \$identity, "no-identity" => \$no_identity, @@ -421,8 +438,8 @@ sub config_regexp { # Now we know enough to read the config { my %configured; - read_config(\%configured, "sendemail.$identity") if defined $identity; - read_config(\%configured, "sendemail"); + read_config(\%known_config_keys, \%configured, "sendemail.$identity") if defined $identity; + read_config(\%known_config_keys, \%configured, "sendemail"); } # Begin by accumulating all the variables (defined above), that we will end up @@ -506,7 +523,7 @@ sub config_regexp { usage(); } -if ($forbid_sendmail_variables && (scalar config_regexp("^sendmail[.]")) != 0) { +if ($forbid_sendmail_variables && grep { /^sendmail/s } keys %known_config_keys) { die __("fatal: found configuration options for 'sendmail'\n" . "git-send-email is configured with the sendemail.* options - note the 'e'.\n" . "Set sendemail.forbidSendmailVariables to false to disable this check.\n"); From patchwork Fri May 28 09:23:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66B3CC47087 for ; Fri, 28 May 2021 09:24:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C5B66127A for ; Fri, 28 May 2021 09:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbhE1JZx (ORCPT ); Fri, 28 May 2021 05:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236082AbhE1JZi (ORCPT ); Fri, 28 May 2021 05:25:38 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D39BC06174A for ; Fri, 28 May 2021 02:24:02 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id m18so2605544wrv.2 for ; Fri, 28 May 2021 02:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bED2B3CFeTVCuzkzOamjxxfVgf4HZaMtTMYsXygiv6E=; b=MWmCmkcocxdY+LoDOP4yjZCl12rtmNpY/kmULIANuGf72/TY3KQaL2hIH6cTTviovw Vxck8l8/dZf3e9xjqw6EbESPrjNybUFUg4AmVU9pOH15U1xmTl3N4akIzyeQ3pa2KUQL HuBKc2qVf63bv7nfSQ4pNUVgZwRN0ZChNB2Y0FjE8s8WZF7FX2rDE0qWkh/69zHCQfkC T2JikJSCfrZOYiKjB3KCvMs9VcR246noCPdeuk9nnv62N+Q8MbpJfm4Wd0ktc1BFeDMl 5bD1Td3yQO5g8wy2QoPwMt3vnZGGhOp5sBsuTJd8zqiAwyJCRSy0pv5ADvNa4UM9RBZf tHpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bED2B3CFeTVCuzkzOamjxxfVgf4HZaMtTMYsXygiv6E=; b=GlY90JXsQUjY3CleKYCDrTbNHcMq/eyUPCvtmZIVR7klq5ocQDl/vbeApuMCIGO3Qi 7yN+xD+gUVX6VJgRkaRCbRgh6hlbkCamRTtuMW+BbE64WW3eD1Yh1hZAYVc/5JNshxLK IqUnJ5i1DDBL7T5+dK+8BFiLD1jSV8c7zWNVgQY8wLCxfToZPl4ZeZQtt9KzBIf5TCrx O+vPUZFxV0v+Aoh+iw7uZVREtpw0vuQQb6xTtJNzO6zEx6mS93b3bSPkW+XgvBDNjV5T +XOgWb8faQErD2En4iQgHTPoT+krLioPiJh7hkaS32/U/yNkuUm+P7GaXJsivTErlR9K tcZg== X-Gm-Message-State: AOAM530fLDRBdy6/nyC5xqFJMNNjorlCCUHZyzjv1To0Y2QMDKyJOrva +2BRWXyODN0+CCYjIe0FM8d4NPzBouiSIw== X-Google-Smtp-Source: ABdhPJy+2alPk8zWGf6X5cJ8wK8q/ywUwF/yZP5j3LIqfWiN31OjZI32PD5MBO+hLWeE3xLa6who2A== X-Received: by 2002:a5d:54c5:: with SMTP id x5mr7541871wrv.151.1622193840731; Fri, 28 May 2021 02:24:00 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:24:00 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 07/13] send-email: lazily shell out to "git var" Date: Fri, 28 May 2021 11:23:46 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Optimize git-send-email by only shelling out to "git var" if we need to. This is easily done by re-inventing our own small version of perl's Memoize module. I suppose I could just use Memoize itself, but in a subsequent patch I'll be micro-optimizing send-email's use of dependencies. Using Memoize is a measly extra 5-10 milliseconds, but as we'll see that'll end up mattering for us in the end. This brings the runtime of a plain "send-email" from around ~160-170ms to ~140m-150ms. The runtime of the tests is around the same, or around ~20s. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index de62cbf2506..38408ec75a8 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -588,8 +588,18 @@ sub config_regexp { } my ($repoauthor, $repocommitter); -($repoauthor) = Git::ident_person(@repo, 'author'); -($repocommitter) = Git::ident_person(@repo, 'committer'); +{ + my %cache; + my ($author, $committer); + my $common = sub { + my ($what) = @_; + return $cache{$what} if exists $cache{$what}; + ($cache{$what}) = Git::ident_person(@repo, $what); + return $cache{$what}; + }; + $repoauthor = sub { $common->('author') }; + $repocommitter = sub { $common->('committer') }; +} sub parse_address_line { return map { $_->format } Mail::Address->parse($_[0]); @@ -777,7 +787,7 @@ sub get_patch_subject { or die sprintf(__("Failed to open for writing %s: %s"), $compose_filename, $!); - my $tpl_sender = $sender || $repoauthor || $repocommitter || ''; + my $tpl_sender = $sender || $repoauthor->() || $repocommitter->() || ''; my $tpl_subject = $initial_subject || ''; my $tpl_in_reply_to = $initial_in_reply_to || ''; my $tpl_reply_to = $reply_to || ''; @@ -983,7 +993,7 @@ sub file_declares_8bit_cte { $sender =~ s/^\s+|\s+$//g; ($sender) = expand_aliases($sender); } else { - $sender = $repoauthor || $repocommitter || ''; + $sender = $repoauthor->() || $repocommitter->() || ''; } # $sender could be an already sanitized address @@ -1132,7 +1142,7 @@ sub make_message_id { $uniq = "$message_id_stamp-$message_id_serial"; my $du_part; - for ($sender, $repocommitter, $repoauthor) { + for ($sender, $repocommitter->(), $repoauthor->()) { $du_part = extract_valid_address(sanitize_address($_)); last if (defined $du_part and $du_part ne ''); } From patchwork Fri May 28 09:23:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3020C4708C for ; Fri, 28 May 2021 09:24:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 837E5613DD for ; Fri, 28 May 2021 09:24:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236314AbhE1JZz (ORCPT ); Fri, 28 May 2021 05:25:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236202AbhE1JZk (ORCPT ); Fri, 28 May 2021 05:25:40 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47685C061761 for ; Fri, 28 May 2021 02:24:03 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id f17so300516wmf.2 for ; Fri, 28 May 2021 02:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XbRLQzfS7HgmYluama4jW9zElxYkZKF9hzNcmBGBaa8=; b=AEVWXrrlDKZo+8E/JR210BararzMO6tN/EAKfywUC21Wm3UVJtWAHpIDhGmvK5Pde1 OSedh76VOtuXtmBvQWotJPsSle3JCwbp7BLRgqcXHWA6sMeZFTSzYMgnKb0ZJdX+brGR MwJh99ATFUJSTgptLmL+NmyZrUodpzvU5yJOL+liEMfJd4CeeOP21e9QljQJu4w87aRD pQ4ISfLS1AEcWURZYF3kOCCftVsOxvW7rfpEZ1w7RprZWJgOPFvPRsrnEYXoOx+f+Fy2 Wuy0QszCQfZ1Oym1YoQaivHrA/Aqz4OmB7HdZ7Nmz332PuNyP3elyHWd/6OHlsc+9Tz5 /Jaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XbRLQzfS7HgmYluama4jW9zElxYkZKF9hzNcmBGBaa8=; b=nKoa/k7mmDe30dzIvIEnKrImWM4YA4FCVUUa3Z7JtNhQcoubMunbB9O9UhssOWLkYa a90p54mMjBJayFg0JFEo9wAyb2mMaLn+/y2//aiQzMx3GbAlr2tKWvVSByWVtKId5Mq6 CBYK7djiav2bOAL0BgSWuwrW78TEA6+OPYBrHraeiKGApJOJAeEmj4p20l+JkXsj72gg 9fDxZog1jlcu4uoftbxCAneq8f/OLA1gMV+xqQD4BdOehwgRMDWdw/wK5YAhwa6P/1RC 4PQKLUePpNGVBbuS36BMRdOqzZCpJQZ0otLSEXnaMsBCrvYROE1KYoUalWieYMX9wpbM ToCQ== X-Gm-Message-State: AOAM530Xd+4FsTr6LCoxdFkb1zEp+U4G6hpIz6dPo9micdccIpJ+VoaB VCcBEekWYWAo3ZeC+zRUIzmYMI9QASdwVQ== X-Google-Smtp-Source: ABdhPJzXM2oVEHrc/pnYmLz4LzJPaTRfzKMX+hsJb7Gmkp80tw0d5qL9Tmy4Lz7Q6fJJVWfg1b6KbQ== X-Received: by 2002:a1c:44f:: with SMTP id 76mr7546475wme.166.1622193841630; Fri, 28 May 2021 02:24:01 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:24:01 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 08/13] send-email: use function syntax instead of barewords Date: Fri, 28 May 2021 11:23:47 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change calls like "__ 'foo'" to "__('foo')" so the Perl compiler doesn't have to guess that "__" is a function. This makes the code more readable. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 38408ec75a8..44dc3f6eb10 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -706,7 +706,7 @@ sub is_format_patch_arg { if (defined($format_patch)) { return $format_patch; } - die sprintf(__ < X-Patchwork-Id: 12286475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19CD8C4708E for ; Fri, 28 May 2021 09:24:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F40A9613B6 for ; Fri, 28 May 2021 09:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236209AbhE1JZy (ORCPT ); Fri, 28 May 2021 05:25:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234740AbhE1JZk (ORCPT ); Fri, 28 May 2021 05:25:40 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2865AC0613ED for ; Fri, 28 May 2021 02:24:04 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id u5-20020a7bc0450000b02901480e40338bso6409448wmc.1 for ; Fri, 28 May 2021 02:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5Ccp4jAR8aBm0TTvorAB3HUQqDUytbWlk6QrCX2oTao=; b=O4eozcz/JVmzOjrLGWhQapFcOnZuQa2/4078M8YFIRCmA7+JyTb31f3yz+A19BH4ar Ad80g/QHln3zK28vleb6kfHBMEbN2DJd4Q3AS8vauJlRch6Snw1Q1jSt5u55K8v5c9IA krsuG3SWBSLsh6Q74kjBlLK6+cTcUkjJ2fwqOjduBxJwsKEtCTBPtSfOytYMvUHgq+W9 gmxufUrZUMSd6Vj9g4tIfyIuK+66UNssVlY7Bukwg2CtRGLXlYeAq+doDsmoVtWJHmSn r4BhMjCPke77JcZ0ngGLlrDLciEzkDvP4SUuHe5ZIGr4fmIMQCYHL7FfrZNbn3ebHmuK slfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5Ccp4jAR8aBm0TTvorAB3HUQqDUytbWlk6QrCX2oTao=; b=D9yh0TyNqdOLJpVJ5AkmBTnwt9B3Kr39GEiQqFl1vy7cGD79AytvXqz8M4sJoyHac9 pgtOdHka6/tYOgCfnbSlb/ydsin8MtlP3SDDiDy6EpyGEEuOrOSQp9OwzyCJyxGuEzuL +ozZV8EM8xaiBrXp0gIpK1Iyy89vBESzfx4PbsfEJ+CBER1EMlHiPk7UbQsjmAlsAsnD Cxq5pQPvcnxXdF4KaGbdoRVqBINaSSl4QCahagWknrEYigdrEoO2Fic1OrZjnqwdzaOU vRhyFfkcNc1EY+8G8p/BP57R1bHBJe8aVUhwgGff9N8Io0Xk0hjaK4fZQGG67wpbi3tl 6/LA== X-Gm-Message-State: AOAM533vzHWzFfGTAlnRJvHtkvARomqZFfQmvF9cBHyJBEDp5PkYctZT 3xLEsRNFfGR2XgK+AiPO2VNdQ5N9F3cRDw== X-Google-Smtp-Source: ABdhPJxLdvl8Bv6BWw1YYlpWciCKT4zUED/Mb/FwRdyIeD+xOcOz2iLg4RGehIE0jtCgmwlzuBsh9Q== X-Received: by 2002:a05:600c:2cd2:: with SMTP id l18mr7498976wmc.142.1622193842423; Fri, 28 May 2021 02:24:02 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:24:01 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 09/13] send-email: get rid of indirect object syntax Date: Fri, 28 May 2021 11:23:48 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change indirect object syntax such as "new X ARGS" to "X->new(ARGS)". This allows perl to see what "new" is at compile-time without having loaded Term::ReadLine. This doesn't matter now, but will in a subsequent commit when we start lazily loading it. Let's do the same for the adjacent "FakeTerm" package for consistency, even though we're not going to conditionally load it. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 44dc3f6eb10..cc1027d8774 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -194,11 +194,11 @@ sub format_2822_time { my @repo = $repo ? ($repo) : (); my $term = eval { $ENV{"GIT_SEND_EMAIL_NOTTY"} - ? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT - : new Term::ReadLine 'git-send-email'; + ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT) + : Term::ReadLine->new('git-send-email'); }; if ($@) { - $term = new FakeTerm "$@: going non-interactive"; + $term = FakeTerm->new("$@: going non-interactive"); } # Behavior modification variables From patchwork Fri May 28 09:23:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7A68C4708D for ; Fri, 28 May 2021 09:24:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6339613DD for ; Fri, 28 May 2021 09:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236334AbhE1JZ5 (ORCPT ); Fri, 28 May 2021 05:25:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234497AbhE1JZl (ORCPT ); Fri, 28 May 2021 05:25:41 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58D66C06138C for ; Fri, 28 May 2021 02:24:05 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id m18so1759642wmq.0 for ; Fri, 28 May 2021 02:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=br7SwP5fnqqAfXSBPF5xLRPT9/56hBZmmDmZOLqcfOI=; b=tekOrJtoWSoaT5IwuyFH/SjspK482x9QFSWl9rEuq9mrC2QWfQovWs54Ca6mVq4YfC aPHlS2aTBQPxp5Vu2df1Qh+vXc49KVrbCmMtD+/qeHLxX8yuD4RYRR2dbCcfHorfOYKS imEVAabXhQC9WtkBPTx3eG12rEBsEF+wZ6AYMgA3tXB/YvytOyo7PVeZT0PxEXPyOSZu v9Fq5JTgZqvl+sdkQw3LeAEoNI0anPoOxhi8q4uNdm0pC7v7miIS4+ykgkqy3c9FRnfU GUlCkKSD9g8aDdfan33MJvCI2wgVV3jVE3BjSVDKwn/+Ecfm0PRpWPInMobR8KcLQYHK bt9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=br7SwP5fnqqAfXSBPF5xLRPT9/56hBZmmDmZOLqcfOI=; b=K18b8IAbLdI9P+iVRQtY0V4nzaRIp70DZKUq876npe3cPdF40e61nXwXCwHbQQTyum 5O05Mfn+MfjkTWi66vibSy18sWqqjz50HuBxmN+s2gcriWlbz45ex8IMgL9q8p+dV7+b e4FPEEbySf495l+6Y6jUDFRaUjl+7rKSZz1liwwQVuOsrJLIzXKZV6P/uCKF6cDUR7A6 3AR53hAXnsrNUox3Eo9/F8AmrFmqXs2YBSKhaVF0ntCXQr1rGjESzbH2uIuXqKnQx214 LDWDqKnjISYieNrP/EO8VP7XSNVOvmM17a0b/jsHxIOR98jtWokSscye1gfgC8+VuU6D U1yA== X-Gm-Message-State: AOAM533A4BaSXjs9ZM1WCtVtOsaMTSHhjMU2Ys5k+0ZvS1Qu+pGx8qIs P/cftdCbA/0Bm7Mql7tAFf3ixIQZCwB6Lg== X-Google-Smtp-Source: ABdhPJyuNXPAdF6YCgXhDSAJlNoyiH8rHQA/R4DeIFXFsAMqzFMrJvhIu2G99CmG4nJOf33XCN+JJA== X-Received: by 2002:a05:600c:4f15:: with SMTP id l21mr7490814wmq.37.1622193843304; Fri, 28 May 2021 02:24:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:24:02 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 10/13] send-email: lazily load modules for a big speedup Date: Fri, 28 May 2021 11:23:49 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Optimize the time git-send-email takes to do even the simplest of things (such as serving up "-h") from around ~150ms to ~80ms-~90ms by lazily loading the modules it requires. Before this change Devel::TraceUse would report 99/97 used modules under NO_GETTEXT=[|Y], respectively. Now it's 52/37. It now takes ~15s to run t9001-send-email.sh, down from ~20s. Changing File::Spec::Functions::{catdir,catfile} to invoking class methods on File::Spec itself is idiomatic. See [1] for a more elaborate explanation, the resulting code behaves the same way, just without the now-pointless function wrapper. 1. http://lore.kernel.org/git/8735u8mmj9.fsf@evledraar.gmail.com Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 71 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index cc1027d8774..a8949c9d313 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -19,20 +19,10 @@ use 5.008; use strict; use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : (); -use POSIX qw/strftime/; -use Term::ReadLine; use Getopt::Long; -use Text::ParseWords; -use Term::ANSIColor; -use File::Temp qw/ tempdir tempfile /; -use File::Spec::Functions qw(catdir catfile); use Git::LoadCPAN::Error qw(:try); -use Cwd qw(abs_path cwd); use Git; use Git::I18N; -use Net::Domain (); -use Net::SMTP (); -use Git::LoadCPAN::Mail::Address; Getopt::Long::Configure qw/ pass_through /; @@ -166,7 +156,6 @@ sub format_2822_time { ); } -my $have_email_valid = eval { require Email::Valid; 1 }; my $smtp; my $auth; my $num_sent = 0; @@ -192,14 +181,6 @@ sub format_2822_time { my $repo = eval { Git->repository() }; my @repo = $repo ? ($repo) : (); -my $term = eval { - $ENV{"GIT_SEND_EMAIL_NOTTY"} - ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT) - : Term::ReadLine->new('git-send-email'); -}; -if ($@) { - $term = FakeTerm->new("$@: going non-interactive"); -} # Behavior modification variables my ($quiet, $dry_run) = (0, 0); @@ -319,9 +300,9 @@ sub do_edit { # Handle Uncouth Termination sub signal_handler { - # Make text normal - print color("reset"), "\n"; + require Term::ANSIColor; + print Term::ANSIColor::color("reset"), "\n"; # SMTP password masked system "stty echo"; @@ -602,11 +583,13 @@ sub config_regexp { } sub parse_address_line { + require Git::LoadCPAN::Mail::Address; return map { $_->format } Mail::Address->parse($_[0]); } sub split_addrs { - return quotewords('\s*,\s*', 1, @_); + require Text::ParseWords; + return Text::ParseWords::quotewords('\s*,\s*', 1, @_); } my %aliases; @@ -655,10 +638,11 @@ sub parse_sendmail_aliases { s/\\"/"/g foreach @addr; $aliases{$alias} = \@addr }}}, - mailrc => sub { my $fh = shift; while (<$fh>) { + mailrc => sub { my $fh = shift; while (<$fh>) { if (/^alias\s+(\S+)\s+(.*?)\s*$/) { + require Text::ParseWords; # spaces delimit multiple addresses - $aliases{$1} = [ quotewords('\s+', 0, $2) ]; + $aliases{$1} = [ Text::ParseWords::quotewords('\s+', 0, $2) ]; }}}, pine => sub { my $fh = shift; my $f='\t[^\t]*'; for (my $x = ''; defined($x); $x = $_) { @@ -730,7 +714,8 @@ sub is_format_patch_arg { opendir my $dh, $f or die sprintf(__("Failed to opendir %s: %s"), $f, $!); - push @files, grep { -f $_ } map { catfile($f, $_) } + require File::Spec; + push @files, grep { -f $_ } map { File::Spec->catfile($f, $_) } sort readdir $dh; closedir $dh; } elsif ((-f $f or -p $f) and !is_format_patch_arg($f)) { @@ -743,7 +728,8 @@ sub is_format_patch_arg { if (@rev_list_opts) { die __("Cannot run git format-patch from outside a repository\n") unless $repo; - push @files, $repo->command('format-patch', '-o', tempdir(CLEANUP => 1), @rev_list_opts); + require File::Temp; + push @files, $repo->command('format-patch', '-o', File::Temp::tempdir(CLEANUP => 1), @rev_list_opts); } @files = handle_backup_files(@files); @@ -780,9 +766,10 @@ sub get_patch_subject { if ($compose) { # Note that this does not need to be secure, but we will make a small # effort to have it be unique + require File::Temp; $compose_filename = ($repo ? - tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) : - tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1]; + File::Temp::tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) : + File::Temp::tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1]; open my $c, ">", $compose_filename or die sprintf(__("Failed to open for writing %s: %s"), $compose_filename, $!); @@ -889,6 +876,19 @@ sub get_patch_subject { do_edit(@files); } +sub term { + my $term = eval { + require Term::ReadLine; + $ENV{"GIT_SEND_EMAIL_NOTTY"} + ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT) + : Term::ReadLine->new('git-send-email'); + }; + if ($@) { + $term = FakeTerm->new("$@: going non-interactive"); + } + return $term; +} + sub ask { my ($prompt, %arg) = @_; my $valid_re = $arg{valid_re}; @@ -896,6 +896,7 @@ sub ask { my $confirm_only = $arg{confirm_only}; my $resp; my $i = 0; + my $term = term(); return defined $default ? $default : undef unless defined $term->IN and defined fileno($term->IN) and defined $term->OUT and defined fileno($term->OUT); @@ -1076,6 +1077,7 @@ sub extract_valid_address { return $address if ($address =~ /^($local_part_regexp)$/); $address =~ s/^\s*<(.*)>\s*$/$1/; + my $have_email_valid = eval { require Email::Valid; 1 }; if ($have_email_valid) { return scalar Email::Valid->address($address); } @@ -1135,7 +1137,8 @@ sub validate_address_list { sub make_message_id { my $uniq; if (!defined $message_id_stamp) { - $message_id_stamp = strftime("%Y%m%d%H%M%S.$$", gmtime(time)); + require POSIX; + $message_id_stamp = POSIX::strftime("%Y%m%d%H%M%S.$$", gmtime(time)); $message_id_serial = 0; } $message_id_serial++; @@ -1305,6 +1308,7 @@ sub valid_fqdn { sub maildomain_net { my $maildomain; + require Net::Domain; my $domain = Net::Domain::domainname(); $maildomain = $domain if valid_fqdn($domain); @@ -1315,6 +1319,7 @@ sub maildomain_mta { my $maildomain; for my $host (qw(mailhost localhost)) { + require Net::SMTP; my $smtp = Net::SMTP->new($host); if (defined $smtp) { my $domain = $smtp->domain; @@ -1994,13 +1999,15 @@ sub validate_patch { if ($repo) { my $hooks_path = $repo->command_oneline('rev-parse', '--git-path', 'hooks'); - my $validate_hook = catfile($hooks_path, + require File::Spec; + my $validate_hook = File::Spec->catfile($hooks_path, 'sendemail-validate'); my $hook_error; if (-x $validate_hook) { - my $target = abs_path($fn); + require Cwd; + my $target = Cwd::abs_path($fn); # The hook needs a correct cwd and GIT_DIR. - my $cwd_save = cwd(); + my $cwd_save = Cwd::cwd(); chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); From patchwork Fri May 28 09:23:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51638C4708C for ; Fri, 28 May 2021 09:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28978613B6 for ; Fri, 28 May 2021 09:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236381AbhE1J0H (ORCPT ); Fri, 28 May 2021 05:26:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235299AbhE1JZt (ORCPT ); Fri, 28 May 2021 05:25:49 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4E88C06138D for ; Fri, 28 May 2021 02:24:05 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id j14so2584761wrq.5 for ; Fri, 28 May 2021 02:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5I+xcKLkUGBqWiPXXs25+b2vmihNkiQ1B8sYGc+SI7I=; b=IeDo2WjBYgUDy19cciLhpsmpuK0HjsDy/lDvROWFvM+y9s1lLAaoClEfWzji0VlPBH E/HA8Ps1OIa+oe1JHAHr+AmLugLf2LkizZLbATNxCH/WSoW0TncFdcyx8QUlv73w8bK/ 0eu6ZBXnvD2pD7NIfGOfXET+JB939CYp43Kuuhzg3PK2bZ8zHNPiXxbuSg7ybGv3VkWk c88435+7mQXUTprChJlScU2cNRmOlqRE2BTnzDe/rW9EWDwDyOvz6mN9rx+WFe8yI7rZ vu0K91Lojk9zE5t64U46ZT3LNrUZRRY5ukkOaAUY4MKiwmCknLSAnlXBVJfpChKko4OF I5Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5I+xcKLkUGBqWiPXXs25+b2vmihNkiQ1B8sYGc+SI7I=; b=N9SYKvOVGuaweCY5PRFnExcadnB1cNOKV3q1Lo8oLOsnRyjemjfAUKp4LOxR4ajY2B m7K6X7KV1cj2A5BG9yyXn7Z/gyVs0mRriv9cBj8X5gD/O/NzoQPCkxNUWX/lKZGT9obL Z1FBdZLxd8vpprr7+vtwpjlu0itlxeEWNAauQ5R5uKG5TiCjoSeL2PAvHMuRwHujZkfL PAupoZAP5WZVkyuz606FuRDU+LphKbuzUoE9XmvOa+ClNqRMapTQ1t6LM3RfIGg8X+98 v0VKMG82J0zG/knHm3PNe/M9CGbDbmWP5ffwF1ZyFak8n9JSClYq1PapESnUwjfOKB7T yn+w== X-Gm-Message-State: AOAM532YDW6SJXC3N95QO77rgmq034f/k5jOBKndVnwmJ2N7hFNlXu0d IOKDT+IgRcGGgYmaVrg56yKZa46mARk2DQ== X-Google-Smtp-Source: ABdhPJwXkZp93tOGBnmJpVCw06yQ5oELDfryURPpnNSxmJWzpHzEOekbpvhHmOu/NgHPjvxqEYETxQ== X-Received: by 2002:adf:f54a:: with SMTP id j10mr1642422wrp.383.1622193843947; Fri, 28 May 2021 02:24:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:24:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 11/13] perl: lazily load some common Git.pm setup code Date: Fri, 28 May 2021 11:23:50 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of unconditionally requiring modules such as File::Spec, let's only load them when needed. This speeds up code that only needs a subset of the features Git.pm provides. This brings a plain invocation of "git send-email" down from 52/37 loaded modules under NO_GETTEXT=[|Y] to 39/18, and it now takes ~60-~70ms instead of ~80-~90ms. The runtime of t9001-send-email.sh test is down to ~13s from ~15s. Signed-off-by: Ævar Arnfjörð Bjarmason --- perl/Git.pm | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/perl/Git.pm b/perl/Git.pm index 02eacef0c2a..5562c0cede2 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -11,9 +11,6 @@ package Git; use strict; use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : (); -use File::Temp (); -use File::Spec (); - BEGIN { our ($VERSION, @ISA, @EXPORT, @EXPORT_OK); @@ -103,12 +100,9 @@ =head1 DESCRIPTION =cut -use Carp qw(carp croak); # but croak is bad - throw instead +sub carp { require Carp; goto &Carp::carp } +sub croak { require Carp; goto &Carp::croak } use Git::LoadCPAN::Error qw(:try); -use Cwd qw(abs_path cwd); -use IPC::Open2 qw(open2); -use Fcntl qw(SEEK_SET SEEK_CUR); -use Time::Local qw(timegm); } @@ -191,13 +185,15 @@ sub repository { $dir = undef; }; + require Cwd; if ($dir) { + require File::Spec; File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir; - $opts{Repository} = abs_path($dir); + $opts{Repository} = Cwd::abs_path($dir); # If --git-dir went ok, this shouldn't die either. my $prefix = $search->command_oneline('rev-parse', '--show-prefix'); - $dir = abs_path($opts{Directory}) . '/'; + $dir = Cwd::abs_path($opts{Directory}) . '/'; if ($prefix) { if (substr($dir, -length($prefix)) ne $prefix) { throw Error::Simple("rev-parse confused me - $dir does not have trailing $prefix"); @@ -223,7 +219,7 @@ sub repository { throw Error::Simple("fatal: Not a git repository: $dir"); } - $opts{Repository} = abs_path($dir); + $opts{Repository} = Cwd::abs_path($dir); } delete $opts{Directory}; @@ -408,10 +404,12 @@ sub command_bidi_pipe { my $cwd_save = undef; if ($self) { shift; - $cwd_save = cwd(); + require Cwd; + $cwd_save = Cwd::cwd(); _setup_git_cmd_env($self); } - $pid = open2($in, $out, 'git', @_); + require IPC::Open2; + $pid = IPC::Open2::open2($in, $out, 'git', @_); chdir($cwd_save) if $cwd_save; return ($pid, $in, $out, join(' ', @_)); } @@ -538,7 +536,8 @@ sub get_tz_offset { my $t = shift || time; my @t = localtime($t); $t[5] += 1900; - my $gm = timegm(@t); + require Time::Local; + my $gm = Time::Local::timegm(@t); my $sign = qw( + + - )[ $gm <=> $t ]; return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]); } @@ -1340,6 +1339,7 @@ sub _temp_cache { my $n = $name; $n =~ s/\W/_/g; # no strange chars + require File::Temp; ($$temp_fd, $fname) = File::Temp::tempfile( "Git_${n}_XXXXXX", UNLINK => 1, DIR => $tmpdir, ) or throw Error::Simple("couldn't open new temp file"); @@ -1362,9 +1362,9 @@ sub temp_reset { truncate $temp_fd, 0 or throw Error::Simple("couldn't truncate file"); - sysseek($temp_fd, 0, SEEK_SET) and seek($temp_fd, 0, SEEK_SET) + sysseek($temp_fd, 0, Fcntl::SEEK_SET()) and seek($temp_fd, 0, Fcntl::SEEK_SET()) or throw Error::Simple("couldn't seek to beginning of file"); - sysseek($temp_fd, 0, SEEK_CUR) == 0 and tell($temp_fd) == 0 + sysseek($temp_fd, 0, Fcntl::SEEK_CUR()) == 0 and tell($temp_fd) == 0 or throw Error::Simple("expected file position to be reset"); } From patchwork Fri May 28 09:23:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13F74C4708C for ; Fri, 28 May 2021 09:24:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E77A9613D1 for ; Fri, 28 May 2021 09:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236063AbhE1JZ7 (ORCPT ); Fri, 28 May 2021 05:25:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234061AbhE1JZt (ORCPT ); Fri, 28 May 2021 05:25:49 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9BEBC06138E for ; Fri, 28 May 2021 02:24:06 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n2so2661315wrm.0 for ; Fri, 28 May 2021 02:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gq6zEoXKs292L8hv6k3D9V64J/nM+XhRPtXaYczoB4k=; b=pqGQyKOzq2MZMvgEbAgDadJ+Z+JS/jj85Xegr8GguoZU7SjKxLo7mWzo7caP+sjeTJ A6LgAAdxah1uo/cmQN49xtUJa7WHVEvwW03oPCB+yvnLi8JYDYB4zMAMvTzrvxwd9AXW urgxrnEKdYZ3zan+2KG3l3Eabc0t/QjIOF/YVs3nP2kl9HaWxSVXWYaSqmhdBF8XIMDU eRNxSedDFV5gp435rlCMj5upGHafTIefwReC8VC5tnuLPAPtkyVu16Vwxw41/BAe9QIz AujkvpBgYINbgdqu3g1OINS0t672A80+5QXvUIADuYEVTlYMouAwiS87HQ6J6FbTumYi +yVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gq6zEoXKs292L8hv6k3D9V64J/nM+XhRPtXaYczoB4k=; b=OldxibOZ5Oz5CW39KilW/jhBnzFvVBM4AbHCuz92wQuUOmzUBKoo2Os14jwead1mc2 Mvqn8Li8arAWMYVikKH1ulVWwe4kmkKt+k1FH5YooERhOVlfzW4nyZ0QS7fuSGSrlk8j B6/C3MYj16wBzj9mEWmUopjaUgSFjLkV6fDNhVUIemRBsGDk1oBlsAeIYRzmH3pS9cYH sB05erj+EiFG/HCLL09+mEeSBAB7vTbUdJQjFD3GSvJd3ezsoiKgBy9OGx+y91cbLbXt LHVOFP7bIItBlErVc4jsp1ZBVf2qKiVVizckyjrm6d89mVxYFSSrCu9DQtKQ30u3PGSK mxeQ== X-Gm-Message-State: AOAM532ASYITBxL1KN/h+DKrxwBzq2o0rKt7ryNZdIyvRt2R3RRVNl2U W+Q9iECX6uQCtlePPSNMJWuIXOoL4CyUow== X-Google-Smtp-Source: ABdhPJxiNUgd1j/IaPYkPBIUtAL3zq/lNtoHSK+7mr9tGe/obaMub4ULCny6UB0Ymp17iFkUPy1CFA== X-Received: by 2002:adf:f341:: with SMTP id e1mr7844394wrp.352.1622193844907; Fri, 28 May 2021 02:24:04 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:24:04 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 12/13] send-email: move trivial config handling to Perl Date: Fri, 28 May 2021 11:23:51 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Optimize the startup time of git-send-email by using an amended config_regexp() function to retrieve the list of config keys and values we're interested in. For boolean keys we can handle the [true|false] case ourselves, and the "--get" case didn't need any parsing. Let's leave "--path" and other "--bool" cases to "git config". I'm not bothering with the "undef" or "" case (true and false, respectively), let's just punt on those and others and have "git config --type=bool" handle it. The "grep { defined } @values" here covers a rather subtle case. For list values such as sendemail.to it is possible as with any other config key to provide a plain "-c sendemail.to", i.e. to set the key as a boolean true. In that case the Git::config() API will return an empty string, but this new parser will correctly return "undef". However, that means we can end up with "undef" in the middle of a list. E.g. for sendemail.smtpserveroption in conjuction with sendemail.smtpserver as a path this would have produce a warning. For most of the other keys we'd behave the same despite the subtle change in the value, e.g. sendemail.to would behave the same because Mail::Address->parse() happens to return an empty list if fed "undef". For the boolean values we were already prepared to handle these variables being initialized as undef anyway. This brings the runtime of "git send-email" from ~60-~70ms to a very steady ~40ms on my test box. We now run just one "git config" invocation on startup instead of 8, the exact number will differ based on the local sendemail.* config. I happen to have 8 of those set. This brings the runtime of t9001-send-email.sh from ~13s down to ~12s for me. The change there is less impressive as many of those tests set various config values, and we're also getting to the point of diminishing returns for optimizing "git send-email" itself. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index a8949c9d313..57911386835 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -334,7 +334,11 @@ sub read_config { my $target = $config_bool_settings{$setting}; my $key = "$prefix.$setting"; next unless exists $known_keys->{$key}; - my $v = Git::config_bool(@repo, $key); + my $v = (@{$known_keys->{$key}} == 1 && + (defined $known_keys->{$key}->[0] && + $known_keys->{$key}->[0] =~ /^(?:true|false)$/s)) + ? $known_keys->{$key}->[0] eq 'true' + : Git::config_bool(@repo, $key); next unless defined $v; next if $configured->{$setting}++; $$target = $v; @@ -363,13 +367,13 @@ sub read_config { my $key = "$prefix.$setting"; next unless exists $known_keys->{$key}; if (ref($target) eq "ARRAY") { - my @values = Git::config(@repo, $key); - next unless @values; + my @values = @{$known_keys->{$key}}; + @values = grep { defined } @values; next if $configured->{$setting}++; @$target = @values; } else { - my $v = Git::config(@repo, $key); + my $v = $known_keys->{$key}->[0]; next unless defined $v; next if $configured->{$setting}++; $$target = $v; @@ -381,12 +385,19 @@ sub config_regexp { my ($regex) = @_; my @ret; eval { - @ret = Git::command( + my $ret = Git::command( 'config', - '--name-only', + '--null', '--get-regexp', $regex, ); + @ret = map { + # We must always return ($k, $v) here, since + # empty config values will be just "key\0", + # not "key\nvalue\0". + my ($k, $v) = split /\n/, $_, 2; + ($k, $v); + } split /\0/, $ret; 1; } or do { # If we have no keys we're OK, otherwise re-throw @@ -399,8 +410,10 @@ sub config_regexp { # parses 'bool' etc.) by only doing so for config keys that exist. my %known_config_keys; { - my @known_config_keys = config_regexp("^sende?mail[.]"); - @known_config_keys{@known_config_keys} = (); + my @kv = config_regexp("^sende?mail[.]"); + while (my ($k, $v) = splice @kv, 0, 2) { + push @{$known_config_keys{$k}} => $v; + } } # sendemail.identity yields to --identity. We must parse this From patchwork Fri May 28 09:23:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12286485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81AEFC47087 for ; Fri, 28 May 2021 09:24:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55C6D613AB for ; Fri, 28 May 2021 09:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236279AbhE1J0M (ORCPT ); Fri, 28 May 2021 05:26:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236294AbhE1JZv (ORCPT ); Fri, 28 May 2021 05:25:51 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2A1C06138F for ; Fri, 28 May 2021 02:24:07 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id q5so2592245wrs.4 for ; Fri, 28 May 2021 02:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fkdJxmF6FhRLfxsGl5M79qLuD3sqvanHP5RvQKO2lYU=; b=eZBkgJMaFUDDCP0lRWKFkNp5P8LsrRZAub/Y/h1QjVxOX/Y0LKkRm7vClr97C73Yd6 ZK7+Bzf/8EAcI+9cRVd3BegFh3mfcilTmziev1JoSGiu9+kxETNeeRFuFNh9LoCf2wGp ecRyaJ19N/FtSoWzA5cpB+ITPK9Ruco+BQxvvgebUJYKRvDBbPbcS+ke1HJAwKR6IWKk /h5p8FDEGSwTAiV9BXyCAdBBGVENhK4xIQk6mvalIeKdKMdVew0zhu0xwB1qmMnUcaV3 cmcy28sxv7H6XjECoqhSyM/UbY2NUahyrt4yhCHrnjjta6INCEpvu+SO40BdSK2eA1Rq qoAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fkdJxmF6FhRLfxsGl5M79qLuD3sqvanHP5RvQKO2lYU=; b=C8mUxh9v0b1d/COcKDQ+Cyxw39hCkaobwU45bgyrSFT3TfWQVJEJuoRt3nQSa7i+s/ bBWwmVCIE3S2BjGt+J9rl7Lgt9fpwXK3cd5vJMMOePRjtm3kW8PpeY/GKkrwPtzOfKXn IaGtjtFJ1iUpViKfVsrUxZ1z0/TlBTi4PeXkHjpZjlqc0DXE8fwWOgkBWDjNzA3ThJWY 6kMNclUG5xo/NLafKKwzC2ZHlooOXZOH4coeDAg8oOZ2pO9jl1ah/TxbfWNnuwcACTWt VvhgIQm08DCT75/nQPuMVrIT8feOF2R/zJjKxwFu9Qkyqb7qZpSEmXUT1IncqZT29+6Y c/lA== X-Gm-Message-State: AOAM530NKCgdj7Oc3LxXXwu4oFAWvSr1i6UPIQI62iXFt6IFtq+Fvbxx l25qbV9Q0WPR/bhZIhHYRGlNI+XmaE7cOA== X-Google-Smtp-Source: ABdhPJwUpbz2ibhkOEaDtUo7wrlU54t/wmMdWe0UsIMfkhx2d12GESyJAsEroyUAYKvsqGczZKXHwg== X-Received: by 2002:a5d:4ccb:: with SMTP id c11mr1476136wrt.169.1622193846067; Fri, 28 May 2021 02:24:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18sm5842009wmj.15.2021.05.28.02.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:24:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Gregory Anders , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Jeff King , Eric Sunshine , Eric Wong , Felipe Contreras , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 13/13] perl: nano-optimize by replacing Cwd::cwd() with Cwd::getcwd() Date: Fri, 28 May 2021 11:23:52 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc1.458.gd885d4f985c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It has been pointed out[1] that cwd() invokes "pwd(1)" while getcwd() is a Perl-native XS function. For what we're using these for we can use getcwd(). The performance difference is miniscule, we're saving on the order of a millisecond or so, see [2] below for the benchmark. I don't think this matters in practice for optimizing git-send-email or perl execution (unlike the patches leading up to this one). But let's do it regardless of that, if only so we don't have to think about this as a low-hanging fruit anymore. 1. https://lore.kernel.org/git/20210512180517.GA11354@dcvr/ 2. $ perl -MBenchmark=:all -MCwd -wE 'cmpthese(10000, { getcwd => sub { getcwd }, cwd => sub { cwd }, pwd => sub { system "pwd >/dev/null" }})' (warning: too few iterations for a reliable count) Rate pwd cwd getcwd pwd 982/s -- -48% -100% cwd 1890/s 92% -- -100% getcwd 10000000000000000000/s 1018000000000000000% 529000000000000064% - Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 2 +- perl/Git.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 57911386835..0efe85c0b02 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -2020,7 +2020,7 @@ sub validate_patch { require Cwd; my $target = Cwd::abs_path($fn); # The hook needs a correct cwd and GIT_DIR. - my $cwd_save = Cwd::cwd(); + my $cwd_save = Cwd::getcwd(); chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); diff --git a/perl/Git.pm b/perl/Git.pm index 5562c0cede2..090a7df63fc 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -405,7 +405,7 @@ sub command_bidi_pipe { if ($self) { shift; require Cwd; - $cwd_save = Cwd::cwd(); + $cwd_save = Cwd::getcwd(); _setup_git_cmd_env($self); } require IPC::Open2;