From patchwork Thu Sep 2 13:11:01 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: 12471589 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 BF4FFC4320E for ; Thu, 2 Sep 2021 13:11:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8312E610D0 for ; Thu, 2 Sep 2021 13:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345026AbhIBNMr (ORCPT ); Thu, 2 Sep 2021 09:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344960AbhIBNMl (ORCPT ); Thu, 2 Sep 2021 09:12:41 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 822BFC061757 for ; Thu, 2 Sep 2021 06:11:43 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 79-20020a1c0452000000b002e6cf79e572so1414411wme.1 for ; Thu, 02 Sep 2021 06:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bvVBOJdBBtfeZCN94yNP2MKEWRBK9krfZjxpV8DXyQg=; b=BKAm3Q/Qpx/EmA2R2eVDgza+KQV2OaGUDyB6a2w9myx7n5FZtr1Q+APzqoPsvr/y8t 0TLk9TAH8Y5U/7WPvmQ6ZhMZfVvZa6DNmOG+WddQPHHld7UnLmJJbSM7Bu52HtO10Gap YaIa91Mf17nwrQhakgq1cYvDzfoYOc9QgrZae+UKmWxHQJoVMMAsfqDli8JiiGNwi+07 9P5oCImCGsWgWpkX6XuIT2GQaPET4d/voz0LsWhwBBsHMK+knXnUDNutBU1dFregC9F8 X6D+tM7Up2RO88fC5sKGH0yGktFWe49BXU896OFr02snOuO+5XNbqCPGXK53zjkpcu65 Dkjw== 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=bvVBOJdBBtfeZCN94yNP2MKEWRBK9krfZjxpV8DXyQg=; b=PFZbKgvsYPOTYM65vEH/bpp5HQHqLheqIdt1Re7bo+WniHeeJri659+cBxQtPE5vmF Id7Lr5MUonVTPcPthk0cOap0hYXinzGO7ijq6g0GlZG4dbGpuroY0DgD4lR4d/VxJEGY N0OtnhJG9K5aiZdZxqngPhoH5fs9+l3/sE6R8bZ8HsBGjJD+mFuFP8/rh/juYLN+64hn 43p/I+dkKDcrvE7PUa9IDtaklJ85YuP5OAHpHBImFcw9FnSTCI5v5spa9a+G6Zab3F6u jZbwck4dlbNn5NeGBZbcDl3l2rgfMUosI4RoJgDGRXD7IsgxoiQ3buu4lobIKT57X5dL aafw== X-Gm-Message-State: AOAM5313rTW2QAXB5FE+cmhSJLGSKzPsf2nEc7sSKwDD8rEvzCnGnzyc TCLYClgbCuF7sLVRDf1mTkQKcddxLT1wLg== X-Google-Smtp-Source: ABdhPJwFm7qM1EuyL6q5c/vkT0DtcDC799aGGPMHmTQfU9FuTzvicgR33U8bmQ0b1Uzkq1mjpXcvuw== X-Received: by 2002:a7b:c4cb:: with SMTP id g11mr3141901wmk.80.1630588301773; Thu, 02 Sep 2021 06:11:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 01/36] Makefile: mark "check" target as .PHONY Date: Thu, 2 Sep 2021 15:11:01 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a bug in 44c9e8594e (Fix up header file dependencies and add sparse checking rules, 2005-07-03), we never marked the phony "check" target as such. Perhaps we should just remove it, since as of a combination of 912f9980d2 (Makefile: help people who run 'make check' by mistake, 2008-11-11) 0bcd9ae85d (sparse: Fix errors due to missing target-specific variables, 2011-04-21) we've been suggesting the user run "make sparse" directly. But under that mode it still does something, as well as directing the user to run "make test" under non-sparse. So let's punt that and narrowly fix the PHONY bug. Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index d1feab008fc..5ec23e6b59a 100644 --- a/Makefile +++ b/Makefile @@ -2941,6 +2941,7 @@ hdr-check: $(HCO) style: git clang-format --style file --diff --extensions c,h +.PHONY: check check: config-list.h command-list.h @if sparse; \ then \ From patchwork Thu Sep 2 13:11:02 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: 12471593 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 027CFC432BE for ; Thu, 2 Sep 2021 13:11:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE4DF610D0 for ; Thu, 2 Sep 2021 13:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345036AbhIBNMt (ORCPT ); Thu, 2 Sep 2021 09:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344993AbhIBNMn (ORCPT ); Thu, 2 Sep 2021 09:12:43 -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 C13D8C061575 for ; Thu, 2 Sep 2021 06:11:44 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 192-20020a1c04c9000000b002f7a4ab0a49so1123678wme.0 for ; Thu, 02 Sep 2021 06:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G4yujwZRHvfKWDpk0vPk5I355epwFHoUGNFWbZCu5oE=; b=lMY6MN6l3sKc3ohzFtFkDlWD/d82IYmrq1HJse+a5UgA6uddsfc9JgSWtGRwStykY4 Rr3J5Eaw27kkkErGouSbjVywQxv8WO//098997KoRoK1MUlDlt3K4qfnw3pdv72JzLvJ t/NgkW5y4asq4RAxfrDL0BzTfBbdLCkgtiKMbKr19bDbN42nzY2BGwh0hd5aV3hhnrYk 5GnFuQlR+v5ZNjLbhBQfRMfIQtL1Ge5+5zK+j0toRILE4HJYmzJKZytiuGc0Kk6q9P0G h5ElKkz+zVXhDh1k5vdPAXE8xlPYmMZJVjSk4l30ISM1i8x33sjBaLQNTG9VVawrUKQz RkZg== 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=G4yujwZRHvfKWDpk0vPk5I355epwFHoUGNFWbZCu5oE=; b=CfyHjk5ud5mMgV3aIyNZDUHLYxoe679D441phtATBbVVk/LfS15ndqVq/arZwwQ6kQ 9Jf29ojmCk6F4oOo7WIYmuBcyLwWRcnUg14ruPGqSNnmSssqAZj5u5hy4wAbqJVqUfMu WVgtB7X/BA8U0A/JhY2h6gp9xjeUiV5QB80M/PrakHygp08NU1FJPsgdmIZrHCB0lLxD lekz5g1eqZZrMhewhOLOR/flsTWQZ1dNq+B8P4lnqQog6L/W6DVt2e7QfsWoslKptEag l0eNKipvZVmEKvhGeDtvAhfB5Y4+RbbEszSS4H7aTy6IdCeBciA5H/bTa0uQ6MovKUyn U/JQ== X-Gm-Message-State: AOAM531KgcfB5FNjpnC0yFtqACEr+/BR1Is5obloYDrFGfAm2stFkY/2 /MeXClrXwrYiE4vOwZJDCoYZWeY4188QZg== X-Google-Smtp-Source: ABdhPJzUSjHIrJg/JQVG+Pto3AOrSdzQ89inkwux24kfQvC9X4q6rIx97dFwgZEINWeaiWyg0PVOuA== X-Received: by 2002:a1c:7417:: with SMTP id p23mr3131724wmc.144.1630588303077; Thu, 02 Sep 2021 06:11:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 02/36] Makefile: stop hardcoding {command,config}-list.h Date: Thu, 2 Sep 2021 15:11:02 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change various places that hardcode the names of these two files to refer to either $(GENERATED_H), or to a new generated-hdrs target. That target is consistent with the *-objs targets I recently added in 029bac01a8 (Makefile: add {program,xdiff,test,git,fuzz}-objs & objects targets, 2021-02-23). A subsequent commit will add a new generated hook-list.h. By doing this refactoring we'll only need to add the new file to the GENERATED_H variable, not EXCEPT_HDRS, the vcbuild/README etc. Hardcoding command-list.h there seems to have been a case of copy/paste programming in 976aaedca0 (msvc: add a Makefile target to pre-generate the Visual Studio solution, 2019-07-29). The config-list.h was added later in 709df95b78 (help: move list_config_help to builtin/help, 2020-04-16). Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 6 ++++-- compat/vcbuild/README | 2 +- config.mak.uname | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5ec23e6b59a..4f1f13b5f0a 100644 --- a/Makefile +++ b/Makefile @@ -824,6 +824,8 @@ XDIFF_LIB = xdiff/lib.a GENERATED_H += command-list.h GENERATED_H += config-list.h +.PHONY: generated-hdrs +generated-hdrs: $(GENERATED_H) LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ $(FIND) . \ @@ -2919,7 +2921,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE .PHONY: sparse $(SP_OBJ) sparse: $(SP_OBJ) -EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/% +EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/% ifndef GCRYPT_SHA256 EXCEPT_HDRS += sha256/gcrypt.h endif @@ -2942,7 +2944,7 @@ style: git clang-format --style file --diff --extensions c,h .PHONY: check -check: config-list.h command-list.h +check: $(GENERATED_H) @if sparse; \ then \ echo >&2 "Use 'make sparse' instead"; \ diff --git a/compat/vcbuild/README b/compat/vcbuild/README index 51fb083dbbe..29ec1d0f104 100644 --- a/compat/vcbuild/README +++ b/compat/vcbuild/README @@ -92,7 +92,7 @@ The Steps of Build Git with VS2008 the git operations. 3. Inside Git's directory run the command: - make command-list.h config-list.h + make generated-hdrs to generate the header file needed to compile git. 4. Then either build Git with the GNU Make Makefile in the Git projects diff --git a/config.mak.uname b/config.mak.uname index 76516aaa9a5..8aac06eb094 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -735,9 +735,9 @@ vcxproj: echo '') >git-remote-http/LinkOrCopyRemoteHttp.targets git add -f git/LinkOrCopyBuiltins.targets git-remote-http/LinkOrCopyRemoteHttp.targets - # Add command-list.h and config-list.h - $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 config-list.h command-list.h - git add -f config-list.h command-list.h + # Add generated headers + $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 $(GENERATED_H) + git add -f $(GENERATED_H) # Add scripts rm -f perl/perl.mak From patchwork Thu Sep 2 13:11:03 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: 12471595 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 644A7C43214 for ; Thu, 2 Sep 2021 13:11:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4865F610D2 for ; Thu, 2 Sep 2021 13:11:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345069AbhIBNMx (ORCPT ); Thu, 2 Sep 2021 09:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345004AbhIBNMo (ORCPT ); Thu, 2 Sep 2021 09:12:44 -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 BCBF7C061757 for ; Thu, 2 Sep 2021 06:11:45 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id k20-20020a05600c0b5400b002e87ad6956eso1340970wmr.1 for ; Thu, 02 Sep 2021 06:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wDACj8AlTebPdYzdVkvvWEYbk7RRMjgrwuCw+v/OEzs=; b=SlvMgun6lH1fH3nU6PvduWVEPHEY4ZPqtOk5Gl+YZ805fczhGyM/uNaSwqa81CNSQB mqgbMhOkdeH1jdw4ESR7JeT791gpD6DzqqJlorRtj1N3koyfokH142rft0YKElmUFw7K EZHQbH/SGrvIotDzs8JceqJ0/aa8hBm9vozqQkxf0j/g08DooBTp0zNjVOvPbql1B1AJ EeX/JleKeHehJVOgk70TaQxu6IZOXZ0rAuD02jr5yvFjT4Lq5ENhtiGzoijTEPVDR3hY ebjwBMPWsPQFMm6cYMM3eSfhiNMF4a+f968A/2BXIAJb3+K0g41q96bQ+TGUAjiiaQYy hbJg== 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=wDACj8AlTebPdYzdVkvvWEYbk7RRMjgrwuCw+v/OEzs=; b=dRj/y6Ii8gvgydgS/B+aD1XF5eAomtmyxW48F3KhsrzsJsLeDxcBGkFxrs2hkmpj1i ujwohdp9nh/HMEwLpKqeFDazkez8bnhDwavQ0Wq1dTns8WjQYUfdMI/LPgUeKO1pLnbC R69sj2kqBlI9H3ZSbcfXtJUUdGE1oM7XWq1xZ8pOAfrAw87/vZnWFjQURJKpRLHFGRFy 7ZDnpYTidmLj/Z5AzNhqWlLVDw10ewGzFTBlYyIrSSIRntlC1FjqRT6tgjBOOuCFsUl7 qTvdtQagMF8F3Qa135bBkt6qERoBHbCMdWf6ogjiV6N5QJG7XBMz1OBOBTLrREjx4pbF U2yw== X-Gm-Message-State: AOAM532Ob4jsboonpIIeG+ZSADXCYMhHnZLFvOnW+0S/GAbPC8P8BHRf SofLKBiGaqwbbza98tw7JcxL8AbfprWa2A== X-Google-Smtp-Source: ABdhPJy6PW3iU8VQj/+VKQjJb03jJOLQfk6y7hS1PoPeKx9L9sRBmeDQ5zuaIuXamaBUnL9nBdxmRQ== X-Received: by 2002:a05:600c:230a:: with SMTP id 10mr3061283wmo.79.1630588304081; Thu, 02 Sep 2021 06:11:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:43 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 03/36] Makefile: remove an out-of-date comment Date: Thu, 2 Sep 2021 15:11:03 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This comment added in dfea575017 (Makefile: lazily compute header dependencies, 2010-01-26) has been out of date since 92b88eba9f (Makefile: use `git ls-files` to list header files, if possible, 2019-03-04), when we did exactly what it tells us not to do and added $(GENERATED_H) to $(OBJECTS) dependencies. The rest of it was also somewhere between inaccurate and outdated, since as of b8ba629264 (Makefile: fold MISC_H into LIB_H, 2012-06-20) it's not followed by a list of header files, that got moved earlier in the file into LIB_H in 60d24dd255 (Makefile: fold XDIFF_H and VCSSVN_H into LIB_H, 2012-07-06). Let's just remove it entirely, to the extent that we have anything useful to say here the comment on the "USE_COMPUTED_HEADER_DEPENDENCIES" variable a few lines above this change does the job for us. Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Makefile b/Makefile index 4f1f13b5f0a..53c67f4a726 100644 --- a/Makefile +++ b/Makefile @@ -2524,13 +2524,6 @@ ifneq ($(dep_files_present),) include $(dep_files_present) endif else -# Dependencies on header files, for platforms that do not support -# the gcc -MMD option. -# -# Dependencies on automatically generated headers such as command-list.h -# should _not_ be included here, since they are necessary even when -# building an object for the first time. - $(OBJECTS): $(LIB_H) $(GENERATED_H) endif From patchwork Thu Sep 2 13:11:04 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: 12471597 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 1CE6AC43216 for ; Thu, 2 Sep 2021 13:11:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05687610D0 for ; Thu, 2 Sep 2021 13:11:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345076AbhIBNMy (ORCPT ); Thu, 2 Sep 2021 09:12:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345013AbhIBNMq (ORCPT ); Thu, 2 Sep 2021 09:12:46 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 255D4C061575 for ; Thu, 2 Sep 2021 06:11:47 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id b6so2851723wrh.10 for ; Thu, 02 Sep 2021 06:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fSSia/gmx3cZomWwRZNJjezRyCHF5eUQp7+TVGkFYsU=; b=g2nyxnNVMnVeywWGoq80LjnbV3QiQwJunOx4iVtvTxYWF2jSR3gSeKSKxyR8wVL1F6 YLDRxkCZNPkHdIZwwhqXHQ8PQ76OO+7i/IzXHIJN6gTlighp5XtuZGOn9OSCH/l9IIok kuYLLfd3A8thb6rP7reT//5QbYe3TBAv6wUaIgwHuiFRzlOijfSzaxgW9o7H1bObz5yF aoBu5650LbMmS74rxKv0XXca4ORnhOtBT1JMzC/Xw9MYqEpMPm2l+fX0/ViA2Phav+y/ Caa6U0DPMG5kUkX5WPNEmvfMRwNOQnqjpCQHtf7gZM2X0cWjNKFgeo58Db4ldUkM/g8p oc+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=fSSia/gmx3cZomWwRZNJjezRyCHF5eUQp7+TVGkFYsU=; b=IEbuLboWwvFpUUHe13d6Xguh5Y4znTDk7ciJsqEzoIoAPRc0qHkG+0NvsDG0sTz3yU CFrivvhcWIbEzlrML1rKLbK7l8s0QDVASIROwGx+XPaIWUcw4xNXCQ6azbjSKsG7z8yJ Lv0RjZTBxtlAxWsDHItncHRh4pBHIGf867MEDlpIDHk3cb/XHoIPIGrnc89auyhdaIky wEy92O42tcewYHZtD+Xycy5RUaM+u8VlzQ6xsZ4GZsQje5+XbgyiP8bxBZD+rIwKdCEH ame7M3bIA+AGbqLxJNi5mXVtF9RkzUDF9TA1PuoS8m2W0ZkEC0Q+E/dLgiDO9DQNdRWv WXxw== X-Gm-Message-State: AOAM532wUXztZeuwaSK3lqE1T8y6SPH/NjCECrjyrcpPTP2SRJdCgJ8J ooV/iagr9G04s0EKTBqufNFkSzOLdJS9lw== X-Google-Smtp-Source: ABdhPJwg9S24Ba+O2GlW7SQct2uKIVHjKFeo6oW8cv+O0FzRsEDZys+ah/8HkV/bzkUSAijFt7tPMg== X-Received: by 2002:a5d:424c:: with SMTP id s12mr3753141wrr.268.1630588305425; Thu, 02 Sep 2021 06:11:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 04/36] hook.[ch]: move find_hook() from run-command.c to hook.c Date: Thu, 2 Sep 2021 15:11:04 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the find_hook() function from run-command.c to a new hook.c library. This change establishes a stub library that's pretty pointless right now, but will see much wider use with Emily Shaffer's upcoming "configuration-based hooks" series. Eventually all the hook related code will live in hook.[ch]. Let's start that process by moving the simple find_hook() function over as-is. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 1 + builtin/am.c | 1 + builtin/bugreport.c | 2 +- builtin/commit.c | 1 + builtin/merge.c | 1 + builtin/receive-pack.c | 1 + builtin/worktree.c | 1 + hook.c | 37 +++++++++++++++++++++++++++++++++++++ hook.h | 11 +++++++++++ refs.c | 1 + run-command.c | 35 +---------------------------------- run-command.h | 7 ------- sequencer.c | 1 + transport.c | 1 + 14 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 hook.c create mode 100644 hook.h diff --git a/Makefile b/Makefile index 53c67f4a726..ae256672780 100644 --- a/Makefile +++ b/Makefile @@ -911,6 +911,7 @@ LIB_OBJS += hash-lookup.o LIB_OBJS += hashmap.o LIB_OBJS += help.o LIB_OBJS += hex.o +LIB_OBJS += hook.o LIB_OBJS += ident.o LIB_OBJS += json-writer.o LIB_OBJS += kwset.o diff --git a/builtin/am.c b/builtin/am.c index 0c2ad96b70e..c603f3cebdf 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -11,6 +11,7 @@ #include "parse-options.h" #include "dir.h" #include "run-command.h" +#include "hook.h" #include "quote.h" #include "tempfile.h" #include "lockfile.h" diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 9915a5841de..596f079a7f9 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -3,7 +3,7 @@ #include "strbuf.h" #include "help.h" #include "compat/compiler.h" -#include "run-command.h" +#include "hook.h" static void get_system_info(struct strbuf *sys_info) diff --git a/builtin/commit.c b/builtin/commit.c index 243c626307c..26c8fad6366 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -19,6 +19,7 @@ #include "revision.h" #include "wt-status.h" #include "run-command.h" +#include "hook.h" #include "refs.h" #include "log-tree.h" #include "strbuf.h" diff --git a/builtin/merge.c b/builtin/merge.c index febb0c99c93..2fc78f54e43 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -13,6 +13,7 @@ #include "builtin.h" #include "lockfile.h" #include "run-command.h" +#include "hook.h" #include "diff.h" #include "diff-merges.h" #include "refs.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 2d1f97e1ca7..97aebdc15bd 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -7,6 +7,7 @@ #include "pkt-line.h" #include "sideband.h" #include "run-command.h" +#include "hook.h" #include "exec-cmd.h" #include "commit.h" #include "object.h" diff --git a/builtin/worktree.c b/builtin/worktree.c index 0d0a80da61f..d22ece93e1a 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -8,6 +8,7 @@ #include "branch.h" #include "refs.h" #include "run-command.h" +#include "hook.h" #include "sigchain.h" #include "submodule.h" #include "utf8.h" diff --git a/hook.c b/hook.c new file mode 100644 index 00000000000..c4dbef1d0ef --- /dev/null +++ b/hook.c @@ -0,0 +1,37 @@ +#include "cache.h" +#include "hook.h" +#include "run-command.h" + +const char *find_hook(const char *name) +{ + static struct strbuf path = STRBUF_INIT; + + strbuf_reset(&path); + strbuf_git_path(&path, "hooks/%s", name); + if (access(path.buf, X_OK) < 0) { + int err = errno; + +#ifdef STRIP_EXTENSION + strbuf_addstr(&path, STRIP_EXTENSION); + if (access(path.buf, X_OK) >= 0) + return path.buf; + if (errno == EACCES) + err = errno; +#endif + + if (err == EACCES && advice_ignored_hook) { + static struct string_list advise_given = STRING_LIST_INIT_DUP; + + if (!string_list_lookup(&advise_given, name)) { + string_list_insert(&advise_given, name); + advise(_("The '%s' hook was ignored because " + "it's not set as executable.\n" + "You can disable this warning with " + "`git config advice.ignoredHook false`."), + path.buf); + } + } + return NULL; + } + return path.buf; +} diff --git a/hook.h b/hook.h new file mode 100644 index 00000000000..56a7b3c9164 --- /dev/null +++ b/hook.h @@ -0,0 +1,11 @@ +#ifndef HOOK_H +#define HOOK_H + +/** + * Returns the path to the hook file, or NULL if the hook is missing + * or disabled. Note that this points to static storage that will be + * overwritten by further calls to find_hook(). + */ +const char *find_hook(const char *name); + +#endif diff --git a/refs.c b/refs.c index 8b9f7c3a80a..6211692eaae 100644 --- a/refs.c +++ b/refs.c @@ -10,6 +10,7 @@ #include "refs.h" #include "refs/refs-internal.h" #include "run-command.h" +#include "hook.h" #include "object-store.h" #include "object.h" #include "tag.h" diff --git a/run-command.c b/run-command.c index f72e72cce73..352f5be1646 100644 --- a/run-command.c +++ b/run-command.c @@ -8,6 +8,7 @@ #include "string-list.h" #include "quote.h" #include "config.h" +#include "hook.h" void child_process_init(struct child_process *child) { @@ -1319,40 +1320,6 @@ int async_with_fork(void) #endif } -const char *find_hook(const char *name) -{ - static struct strbuf path = STRBUF_INIT; - - strbuf_reset(&path); - strbuf_git_path(&path, "hooks/%s", name); - if (access(path.buf, X_OK) < 0) { - int err = errno; - -#ifdef STRIP_EXTENSION - strbuf_addstr(&path, STRIP_EXTENSION); - if (access(path.buf, X_OK) >= 0) - return path.buf; - if (errno == EACCES) - err = errno; -#endif - - if (err == EACCES && advice_ignored_hook) { - static struct string_list advise_given = STRING_LIST_INIT_DUP; - - if (!string_list_lookup(&advise_given, name)) { - string_list_insert(&advise_given, name); - advise(_("The '%s' hook was ignored because " - "it's not set as executable.\n" - "You can disable this warning with " - "`git config advice.ignoredHook false`."), - path.buf); - } - } - return NULL; - } - return path.buf; -} - int run_hook_ve(const char *const *env, const char *name, va_list args) { struct child_process hook = CHILD_PROCESS_INIT; diff --git a/run-command.h b/run-command.h index af1296769f9..f76b740f927 100644 --- a/run-command.h +++ b/run-command.h @@ -204,13 +204,6 @@ int finish_command_in_signal(struct child_process *); */ int run_command(struct child_process *); -/* - * Returns the path to the hook file, or NULL if the hook is missing - * or disabled. Note that this points to static storage that will be - * overwritten by further calls to find_hook and run_hook_*. - */ -const char *find_hook(const char *name); - /** * Run a hook. * The first argument is a pathname to an index file, or NULL diff --git a/sequencer.c b/sequencer.c index 1ceb4c0d7fd..3214f02f393 100644 --- a/sequencer.c +++ b/sequencer.c @@ -8,6 +8,7 @@ #include "sequencer.h" #include "tag.h" #include "run-command.h" +#include "hook.h" #include "exec-cmd.h" #include "utf8.h" #include "cache-tree.h" diff --git a/transport.c b/transport.c index 17e9629710a..77e196f75f5 100644 --- a/transport.c +++ b/transport.c @@ -2,6 +2,7 @@ #include "config.h" #include "transport.h" #include "run-command.h" +#include "hook.h" #include "pkt-line.h" #include "fetch-pack.h" #include "remote.h" From patchwork Thu Sep 2 13:11:05 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: 12471599 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 18D92C432BE for ; Thu, 2 Sep 2021 13:12:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00B75610D0 for ; Thu, 2 Sep 2021 13:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345092AbhIBNM6 (ORCPT ); Thu, 2 Sep 2021 09:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345015AbhIBNMq (ORCPT ); Thu, 2 Sep 2021 09:12:46 -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 3358CC061757 for ; Thu, 2 Sep 2021 06:11:48 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id v10so2853958wrd.4 for ; Thu, 02 Sep 2021 06:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RaVYmn7tkPYTewAfFPVulJvTmrL+DdB+FOfQqAqpQmw=; b=Sv56NSBP+rKe0s9lNcmOGrpyjlluU1RKbypDNRJo3dj+NtIZi54iWGjCrDqojD8dyq bLma1fWDfM1I/7vmbAlcVP0Y3Mit7n1yfb2ZcBUZDh03TgzNxbalzPKig8CfR6gIw9VQ lpByIdwcS80HLs02ebnFKlKCWLRM8JLHCtZ1tnlNzV1sKs8g28BXIlXK65uxSU1idMdr rTvwL/2LE1injjXoJmwHCSgCeU4OWdMz4xyNLosT00EEADfURasNrUSmGWe/moVOO3Fy XNY4f/tclq0Zg20IqTOIU5/WYRR625+71cv027MDhH5+QyvIoJzErReVd0pyh/deZrHv xddw== 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=RaVYmn7tkPYTewAfFPVulJvTmrL+DdB+FOfQqAqpQmw=; b=VznnYJbZzD8PdM+vSRYcCVMPUzbblTRXR/cQfRlUzIDyzbM8mamp62K0SaLLPV7WbV PR9k4DygidQ9h4Rb5NNHK/7fTq+0NjZCoiF1GkIOP7ltmcRnd3/IQbt97AatoKkWzy0W DB16WId8/BI/dXIHCcE9kDVtgz6B/BPqmEW1Mr4LeVqcfCn3aLHwARNLLNQ6Zim1saGh dLmVV2dEutmwQ25kT3jkZNIfOvXGZuVlE2+hNXR+kYiKKbTdIOWJbwwQH8mWhZXxob25 OnIdBJ5SVkj8YXtJh8KHuradNOMn43yWZOxfAly6xKNJBCsn8SozSgCO58WYEpfwZXQd gbmA== X-Gm-Message-State: AOAM533xyUzvFB30DqnKjioN7X6Vyr3WX8Gv30AMs1TbUJr0vi9La19y zOidNTe2rb3KumJMDVCDPhLC/0+Mj5vBpw== X-Google-Smtp-Source: ABdhPJy+93Ud2EDTq+Xzc9jvo/UulV+YLEjOwN9d9ICR3IsbIpkhOzZEFzjls0N2opz/qZ5cO8z95g== X-Received: by 2002:a5d:6286:: with SMTP id k6mr3584017wru.103.1630588306519; Thu, 02 Sep 2021 06:11:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 05/36] hook.c: add a hook_exists() wrapper and use it in bugreport.c Date: Thu, 2 Sep 2021 15:11:05 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Add a boolean version of the find_hook() function for those callers who are only interested in checking whether the hook exists, not what the path to it is. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/bugreport.c | 2 +- hook.c | 5 +++++ hook.h | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 596f079a7f9..941c8d5e270 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -82,7 +82,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) } for (i = 0; i < ARRAY_SIZE(hook); i++) - if (find_hook(hook[i])) + if (hook_exists(hook[i])) strbuf_addf(hook_info, "%s\n", hook[i]); } diff --git a/hook.c b/hook.c index c4dbef1d0ef..97cd799a320 100644 --- a/hook.c +++ b/hook.c @@ -35,3 +35,8 @@ const char *find_hook(const char *name) } return path.buf; } + +int hook_exists(const char *name) +{ + return !!find_hook(name); +} diff --git a/hook.h b/hook.h index 56a7b3c9164..368754b1201 100644 --- a/hook.h +++ b/hook.h @@ -8,4 +8,9 @@ */ const char *find_hook(const char *name); +/** + * A boolean version of find_hook() + */ +int hook_exists(const char *hookname); + #endif From patchwork Thu Sep 2 13:11:06 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: 12471601 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 C6970C4320E for ; Thu, 2 Sep 2021 13:12:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B44E5610D0 for ; Thu, 2 Sep 2021 13:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344960AbhIBNM7 (ORCPT ); Thu, 2 Sep 2021 09:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345018AbhIBNMr (ORCPT ); Thu, 2 Sep 2021 09:12:47 -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 42C9CC061575 for ; Thu, 2 Sep 2021 06:11:49 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id z9-20020a7bc149000000b002e8861aff59so1431727wmi.0 for ; Thu, 02 Sep 2021 06:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A+MfU27IONT+Wl4J/FjuVyKZH2u4lvpxIGcH8Z4NxD8=; b=R6e+76F1LCBLwNgS4yeR2vKGMcP5NAt1f0Heit2yfSJLvjf0V1fTctOYeFgLzwFCte ISRjURdhy8pGoxsF8veKgoqKPJ/1c+DLJH1A+0DBvHPF4RJGye6/3D9msmAslYjb7lVd XSaVZ8rnCHLk6gFJa7KmVJ16aqmeR12eGlIVmu9YSXmN617/Nt5+UKMgnhX26DIGtrmM eQ9/Pj8IBIl+oOOBX7GgmDoBtLZprWJLvxXXwYmDZF+0ZD+btsqOBytd4jdgHbM9n/cy WFNpjkTKS5ejltCCrxiT01fOCSXFFaSS6L/9DWgeGPhuPmGujXxoytoNRKTlplbAO8L3 WfjA== 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=A+MfU27IONT+Wl4J/FjuVyKZH2u4lvpxIGcH8Z4NxD8=; b=AMQ65vZ+ELxYIBnfStvJasGS+v5AR6q7tuAW9UsHck/i7uReBpuXt3TWsMbRu8jqoA sFGZpSJK1vSnumnf6vCbJydgZSQjEeurTLtY05RDvNWyQHCpMjPJBhC4bcNsy5YF3oWi zJZhQ00ad8C6IZz+sEeJVZhD3N0fkD1HzKKpVBOwcoGsBVGV2Ot/xnklGnahrnuGXEPR LSmy1WVbqMYNz6/bs0SsLH5ejtT5Yshg3ReqvkkgoJpDOOCz1vDRgQsNkRB4bcEaRTZw jIhzQaQj7FgtDaT2nf128xutodBlMn27Axd/qNex5wfLDFBz5Lz+I2VqU92NoviYTWig y4AA== X-Gm-Message-State: AOAM533LJlH7mbhUhyxETfQ1nkB7LKT8b5KvqAviYHJRfsbituRRVYMb bgt6A7D/K8gEGfItF/Wysyx38yvRNaItwA== X-Google-Smtp-Source: ABdhPJwHVBhCnAm+N2PIKlkm8Dqer8slNbrpa3LgGUY+dPnGAMtfjYMh8vUJOSkhq9fkCNUQXa6ATw== X-Received: by 2002:a05:600c:4f46:: with SMTP id m6mr3149096wmq.133.1630588307479; Thu, 02 Sep 2021 06:11:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 06/36] hook.c users: use "hook_exists()" instead of "find_hook()" Date: Thu, 2 Sep 2021 15:11:06 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use the new hook_exists() function instead of find_hook() where the latter was called in boolean contexts. This make subsequent changes in a series where we further refactor the hook API clearer, as we won't conflate wanting to get the path of the hook with checking for its existence. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit.c | 2 +- builtin/merge.c | 2 +- builtin/receive-pack.c | 2 +- sequencer.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 26c8fad6366..f6ca9d04c78 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1052,7 +1052,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 0; } - if (!no_verify && find_hook("pre-commit")) { + if (!no_verify && hook_exists("pre-commit")) { /* * Re-read the index as pre-commit hook could have updated it, * and write it out as a tree. We must do this before we invoke diff --git a/builtin/merge.c b/builtin/merge.c index 2fc78f54e43..d75a438298b 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -850,7 +850,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) * and write it out as a tree. We must do this before we invoke * the editor and after we invoke run_status above. */ - if (find_hook("pre-merge-commit")) + if (hook_exists("pre-merge-commit")) discard_cache(); read_cache_from(index_file); strbuf_addbuf(&msg, &merge_msg); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 97aebdc15bd..91fa799b66e 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1464,7 +1464,7 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); - if (!find_hook(push_to_checkout_hook)) + if (!hook_exists(push_to_checkout_hook)) retval = push_to_deploy(sha1, &env, work_tree); else retval = push_to_checkout(sha1, &env, work_tree); diff --git a/sequencer.c b/sequencer.c index 3214f02f393..8999edf8d7b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1446,7 +1446,7 @@ static int try_to_commit(struct repository *r, } } - if (find_hook("prepare-commit-msg")) { + if (hook_exists("prepare-commit-msg")) { res = run_prepare_commit_msg_hook(r, msg, hook_commit); if (res) goto out; From patchwork Thu Sep 2 13:11:07 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: 12471603 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 DFC56C432BE for ; Thu, 2 Sep 2021 13:12:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C95FC610D0 for ; Thu, 2 Sep 2021 13:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345063AbhIBNM7 (ORCPT ); Thu, 2 Sep 2021 09:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345033AbhIBNMs (ORCPT ); Thu, 2 Sep 2021 09:12:48 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A101C061757 for ; Thu, 2 Sep 2021 06:11:50 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id q11so2846527wrr.9 for ; Thu, 02 Sep 2021 06:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SYZ3WkdKa+t9xy9n8qV878DFpCIi9LCPutLNe46eSHM=; b=COJrDOGVy17IDAhVwSPpnkvZvIr1PUKY7MgTYjRzK5Ci6DWDl7L5CodB7b88AEyhIu mQCG/Wxwm+NeLCn9uflmIoCER3FjEMOJaZTkHICszRLxITWofrNHlRAlTu3c3hIv7FG4 M2t66YkOlIf3yJt86ipsQxcqn4/vdIP+cvtR043G17SBE3zW5C4VtUq6RTWspn84YcNG J7P65zCGDuEEP/BLEu9ZsoXaqkMS7uE35jG7g1NjJc9RFE8lGPYJrQS0pYZP3NkkeGJK UK9CJEbGHjfoY7oh4QrFjEnWRdEk4EvMzueC4KKUCeeDV2LqdZugxGhEcstPV89A2aIL Ujpw== 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=SYZ3WkdKa+t9xy9n8qV878DFpCIi9LCPutLNe46eSHM=; b=B6lVHnf70E83Y00ecMFglHwuAWhj6hKCvdWkadWnsILy+l9kpnghPIV9F0kmhwLv2R DitwwGfsMbIvmuqpRhdoZ4ua+5PTi9MysIYWU1ET43EZYVbIobUZEyqXQMx5ROChRWo9 T9xOkbS6cWCovX+G4+j4elof1vhTEI8PR8lqtKl5NlF32Vc1/Ro0mm28a5lR6m2CvVfJ VZD/E5vehTvnfJCW1Nf9eR/eA7i/gRr7TvTWo3UB5sYC4Vt05QERznLtBA4TTdlBhoqg YZufC6agjFrnZZNHq1W5Qvrulcek1/tGYP4Yh7cGVkL2VgSe4p8vTXRuim2C4YZEDUQc m1Pw== X-Gm-Message-State: AOAM530tK3yhwv5FkJrV0AAzZHc8ITa96Gk26ulykDp+FwYppTx9iUvv Ti+z1meSmIL6nzWmHHaAa70u8XTLDpvpWQ== X-Google-Smtp-Source: ABdhPJxexDgI9OfxBESlNxlZk+9uLmUzNF4hzPrmrQzRh3XwZrhN7pWu8Z/Px8ULKK/OTxN+pf8lVQ== X-Received: by 2002:a5d:456b:: with SMTP id a11mr3673391wrc.291.1630588308733; Thu, 02 Sep 2021 06:11:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= , =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH v5 07/36] hook-list.h: add a generated list of hooks, like config-list.h Date: Thu, 2 Sep 2021 15:11:07 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make githooks(5) the source of truth for what hooks git supports, and punt out early on hooks we don't know about in find_hook(). This ensures that the documentation and the C code's idea about existing hooks doesn't diverge. We still have Perl and Python code running its own hooks, but that'll be addressed by Emily Shaffer's upcoming "git hook run" command. This resolves a long-standing TODO item in bugreport.c of there being no centralized listing of hooks, and fixes a bug with the bugreport listing only knowing about 1/4 of the p4 hooks. It didn't know about the recent "reference-transaction" hook either. We could make the find_hook() function die() or BUG() out if the new known_hook() returned 0, but let's make it return NULL just as it does when it can't find a hook of a known type. Making it die() is overly anal, and unlikely to be what we need in catching stupid typos in the name of some new hook hardcoded in git.git's sources. By making this be tolerant of unknown hook names, changes in a later series to make "git hook run" run arbitrary user-configured hook names will be easier to implement. I have not been able to directly test the CMake change being made here. Since 4c2c38e800 (ci: modification of main.yml to use cmake for vs-build job, 2020-06-26) some of the Windows CI has a hard dependency on CMake, this change works there, and is to my eyes an obviously correct use of a pattern established in previous CMake changes, namely: - 061c2240b1 (Introduce CMake support for configuring Git, 2020-06-12) - 709df95b78 (help: move list_config_help to builtin/help, 2020-04-16) - 976aaedca0 (msvc: add a Makefile target to pre-generate the Visual Studio solution, 2019-07-29) The LC_ALL=C is needed because at least in my locale the dash ("-") is ignored for the purposes of sorting, which results in a different order. I'm not aware of anything in git that has a hard dependency on the order, but e.g. the bugreport output would end up using whatever locale was in effect when git was compiled. Signed-off-by: Ævar Arnfjörð Bjarmason Helped-by: René Scharfe --- .gitignore | 1 + Makefile | 10 ++++++- builtin/bugreport.c | 44 ++++++----------------------- contrib/buildsystems/CMakeLists.txt | 7 +++++ generate-hooklist.sh | 18 ++++++++++++ 5 files changed, 43 insertions(+), 37 deletions(-) create mode 100755 generate-hooklist.sh diff --git a/.gitignore b/.gitignore index 311841f9bed..6be9de41ae8 100644 --- a/.gitignore +++ b/.gitignore @@ -190,6 +190,7 @@ /gitweb/static/gitweb.min.* /config-list.h /command-list.h +/hook-list.h *.tar.gz *.dsc *.deb diff --git a/Makefile b/Makefile index ae256672780..ed06b4e9634 100644 --- a/Makefile +++ b/Makefile @@ -824,6 +824,8 @@ XDIFF_LIB = xdiff/lib.a GENERATED_H += command-list.h GENERATED_H += config-list.h +GENERATED_H += hook-list.h + .PHONY: generated-hdrs generated-hdrs: $(GENERATED_H) @@ -2231,7 +2233,9 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h -builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX +hook.sp hook.s hook.o: hook-list.h + +builtin/help.sp builtin/help.s builtin/help.o: config-list.h hook-list.h GIT-PREFIX builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \ '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ @@ -2264,6 +2268,10 @@ command-list.h: $(wildcard Documentation/git*.txt) $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \ command-list.txt >$@+ && mv $@+ $@ +hook-list.h: generate-hooklist.sh Documentation/githooks.txt + $(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh \ + >$@+ && mv $@+ $@ + SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\ $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\ diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 941c8d5e270..a7a1fcb8a7a 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -4,6 +4,7 @@ #include "help.h" #include "compat/compiler.h" #include "hook.h" +#include "hook-list.h" static void get_system_info(struct strbuf *sys_info) @@ -41,39 +42,7 @@ static void get_system_info(struct strbuf *sys_info) static void get_populated_hooks(struct strbuf *hook_info, int nongit) { - /* - * NEEDSWORK: Doesn't look like there is a list of all possible hooks; - * so below is a transcription of `git help hooks`. Later, this should - * be replaced with some programmatically generated list (generated from - * doc or else taken from some library which tells us about all the - * hooks) - */ - static const char *hook[] = { - "applypatch-msg", - "pre-applypatch", - "post-applypatch", - "pre-commit", - "pre-merge-commit", - "prepare-commit-msg", - "commit-msg", - "post-commit", - "pre-rebase", - "post-checkout", - "post-merge", - "pre-push", - "pre-receive", - "update", - "post-receive", - "post-update", - "push-to-checkout", - "pre-auto-gc", - "post-rewrite", - "sendemail-validate", - "fsmonitor-watchman", - "p4-pre-submit", - "post-index-change", - }; - int i; + const char **p; if (nongit) { strbuf_addstr(hook_info, @@ -81,9 +50,12 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) return; } - for (i = 0; i < ARRAY_SIZE(hook); i++) - if (hook_exists(hook[i])) - strbuf_addf(hook_info, "%s\n", hook[i]); + for (p = hook_name_list; *p; p++) { + const char *hook = *p; + + if (hook_exists(hook)) + strbuf_addf(hook_info, "%s\n", hook); + } } static const char * const bugreport_usage[] = { diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 171b4124afe..fd1399c440f 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -624,6 +624,13 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h) OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h) endif() +if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h) + message("Generating hook-list.h") + execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h) +endif() + include_directories(${CMAKE_BINARY_DIR}) #build diff --git a/generate-hooklist.sh b/generate-hooklist.sh new file mode 100755 index 00000000000..6d4e56d1a31 --- /dev/null +++ b/generate-hooklist.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Usage: ./generate-hooklist.sh >hook-list.h + +cat < X-Patchwork-Id: 12471605 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 C33B9C4320E for ; Thu, 2 Sep 2021 13:12:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3AB1610D0 for ; Thu, 2 Sep 2021 13:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345117AbhIBNNC (ORCPT ); Thu, 2 Sep 2021 09:13:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344993AbhIBNMw (ORCPT ); Thu, 2 Sep 2021 09:12:52 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB64AC0613CF for ; Thu, 2 Sep 2021 06:11:51 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id l7-20020a1c2507000000b002e6be5d86b3so1332738wml.3 for ; Thu, 02 Sep 2021 06:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U+yvHBppsqppIjFZGS/2tKKcBQLPGB/CQ/oJDNJTHr4=; b=Z7EKXqhQXkusJ0ItCuUV6vcQ6Rqjc2jbNR9lRhSRm45krFdITncpiySPLatlT3zYOZ Q0A104GuQaMVYfqAbn3IQvaEgl4e3jJJUTPJ30gw5Z2GuD3VuKNT6HB+miBQK7FqRCN1 a2rv1cwf5eTfZNOm4TTkYL8bPgdQLK9fXQKqaNNCJwXUHXgij9m6MykFn1brTrMh7wBz 5i09omkgAzd4HS09G3XHcQMxdC4Awp0j08eZ1RvIlsW8nWWdiNXthexlqKPQqzEAVE5u MCq6//u3NHWT9fXrp3u4wOfiYP4oyDa5/AbWggb5iQoxXz37RT2lgYTyE73v0ypUuw6a qiYA== 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=U+yvHBppsqppIjFZGS/2tKKcBQLPGB/CQ/oJDNJTHr4=; b=hfpYnO+jNL4Ae9c1FYJEaQoRTD2K/Xj3FEUCW03x/QFRRIcKh7C+ixRvGKFp3EVpXN tjwRiVousSGuhjL0GKYIB3CO0DYRbKgWs2qNKYK8F6wSet7+ZNzN03uEXCA8JdNOe92o WW2nqp5zJln6tTwjeO4XhX6VXiXC2CLJy8KKVBEE7A2NxY1YHKN3ZUrHr1NCoSa0zpFv 9Vh6uwxNb8jvw5z4Fn/JyzF4P4+Sx4w0bYkVwDMBtJdlc/Csf0VK0uE7+in2a5nbmTXN VTcULdyo5uqo91gdVNjORqyqbIAvmilx+q6BBCOrd85riyM2/UOF0LpYk5D8n8qz18Pg N/3w== X-Gm-Message-State: AOAM531M6dfFfaT21UFnV6ruNwIFVrlP2ObKxDrIK2fG2mCQm+5+c5I6 uezYkM7uuKhgip0GjoG3tE8ZshRsbF8uFQ== X-Google-Smtp-Source: ABdhPJxo/WPzSbMryQG9rpxXzR1BKIcsQZuGhJ4mkUFs1IfujCZfvzAkPkoOetG29qSPtqnIVDdnQQ== X-Received: by 2002:a1c:2042:: with SMTP id g63mr3142539wmg.27.1630588309926; Thu, 02 Sep 2021 06:11:49 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:49 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 08/36] hook: add 'run' subcommand Date: Thu, 2 Sep 2021 15:11:08 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer In order to enable hooks to be run as an external process, by a standalone Git command, or by tools which wrap Git, provide an external means to run all configured hook commands for a given hook event. Most of our hooks require more complex functionality than this, but let's start with the bare minimum required to support our simplest hooks. In terms of implementation the usage_with_options() and "goto usage" pattern here mirrors that of builtin/{commit-graph,multi-pack-index}.c. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- .gitignore | 1 + Documentation/git-hook.txt | 38 +++++++++++ Documentation/githooks.txt | 4 ++ Makefile | 1 + builtin.h | 1 + builtin/hook.c | 90 ++++++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + hook.c | 101 +++++++++++++++++++++++++++++ hook.h | 39 +++++++++++ t/t1800-hook.sh | 128 +++++++++++++++++++++++++++++++++++++ 11 files changed, 405 insertions(+) create mode 100644 Documentation/git-hook.txt create mode 100644 builtin/hook.c create mode 100755 t/t1800-hook.sh diff --git a/.gitignore b/.gitignore index 6be9de41ae8..66189ca3cdc 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,7 @@ /git-grep /git-hash-object /git-help +/git-hook /git-http-backend /git-http-fetch /git-http-push diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt new file mode 100644 index 00000000000..660d6a992a0 --- /dev/null +++ b/Documentation/git-hook.txt @@ -0,0 +1,38 @@ +git-hook(1) +=========== + +NAME +---- +git-hook - run git hooks + +SYNOPSIS +-------- +[verse] +'git hook' run [-- ] + +DESCRIPTION +----------- + +This command is an interface to git hooks (see linkgit:githooks[5]). +Currently it only provides a convenience wrapper for running hooks for +use by git itself. In the future it might gain other functionality. + +SUBCOMMANDS +----------- + +run:: + Run the `` hook. See linkgit:githooks[5] for + the hook names we support. ++ +Any positional arguments to the hook should be passed after an +optional `--` (or `--end-of-options`, see linkgit:gitcli[7]). The +arguments (if any) differ by hook name, see linkgit:githooks[5] for +what those are. + +SEE ALSO +-------- +linkgit:githooks[5] + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index b51959ff941..a16e62bc8c8 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -698,6 +698,10 @@ and "0" meaning they were not. Only one parameter should be set to "1" when the hook runs. The hook running passing "1", "1" should not be possible. +SEE ALSO +-------- +linkgit:git-hook[1] + GIT --- Part of the linkgit:git[1] suite diff --git a/Makefile b/Makefile index ed06b4e9634..bbd416511a3 100644 --- a/Makefile +++ b/Makefile @@ -1115,6 +1115,7 @@ BUILTIN_OBJS += builtin/get-tar-commit-id.o BUILTIN_OBJS += builtin/grep.o BUILTIN_OBJS += builtin/hash-object.o BUILTIN_OBJS += builtin/help.o +BUILTIN_OBJS += builtin/hook.o BUILTIN_OBJS += builtin/index-pack.o BUILTIN_OBJS += builtin/init-db.o BUILTIN_OBJS += builtin/interpret-trailers.o diff --git a/builtin.h b/builtin.h index 16ecd5586f0..91740c15149 100644 --- a/builtin.h +++ b/builtin.h @@ -164,6 +164,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix); int cmd_grep(int argc, const char **argv, const char *prefix); int cmd_hash_object(int argc, const char **argv, const char *prefix); int cmd_help(int argc, const char **argv, const char *prefix); +int cmd_hook(int argc, const char **argv, const char *prefix); int cmd_index_pack(int argc, const char **argv, const char *prefix); int cmd_init_db(int argc, const char **argv, const char *prefix); int cmd_interpret_trailers(int argc, const char **argv, const char *prefix); diff --git a/builtin/hook.c b/builtin/hook.c new file mode 100644 index 00000000000..012a2973b38 --- /dev/null +++ b/builtin/hook.c @@ -0,0 +1,90 @@ +#include "cache.h" +#include "builtin.h" +#include "config.h" +#include "hook.h" +#include "parse-options.h" +#include "strbuf.h" +#include "strvec.h" + +#define BUILTIN_HOOK_RUN_USAGE \ + N_("git hook run [-- ]") + +static const char * const builtin_hook_usage[] = { + BUILTIN_HOOK_RUN_USAGE, + NULL +}; + +static const char * const builtin_hook_run_usage[] = { + BUILTIN_HOOK_RUN_USAGE, + NULL +}; + +static int run(int argc, const char **argv, const char *prefix) +{ + int i; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + const char *hook_name; + const char *hook_path; + struct option run_options[] = { + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, run_options, + builtin_hook_run_usage, + PARSE_OPT_KEEP_DASHDASH); + + if (!argc) + goto usage; + + /* + * Having a -- for "run" when providing is + * mandatory. + */ + if (argc > 1 && strcmp(argv[1], "--") && + strcmp(argv[1], "--end-of-options")) + goto usage; + + /* Add our arguments, start after -- */ + for (i = 2 ; i < argc; i++) + strvec_push(&opt.args, argv[i]); + + /* Need to take into account core.hooksPath */ + git_config(git_default_config, NULL); + + /* + * We are not using a plain run_hooks() because we'd like to + * detect missing hooks. Let's find it ourselves and call + * run_hooks() instead. + */ + hook_name = argv[0]; + hook_path = find_hook(hook_name); + if (!hook_path) { + error("cannot find a hook named %s", hook_name); + return 1; + } + + ret = run_hooks(hook_name, hook_path, &opt); + run_hooks_opt_clear(&opt); + return ret; +usage: + usage_with_options(builtin_hook_run_usage, run_options); +} + +int cmd_hook(int argc, const char **argv, const char *prefix) +{ + struct option builtin_hook_options[] = { + OPT_END(), + }; + + argc = parse_options(argc, argv, NULL, builtin_hook_options, + builtin_hook_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (!argc) + goto usage; + + if (!strcmp(argv[0], "run")) + return run(argc, argv, prefix); + +usage: + usage_with_options(builtin_hook_usage, builtin_hook_options); +} diff --git a/command-list.txt b/command-list.txt index a289f09ed6f..9ccd8e5aebe 100644 --- a/command-list.txt +++ b/command-list.txt @@ -103,6 +103,7 @@ git-grep mainporcelain info git-gui mainporcelain git-hash-object plumbingmanipulators git-help ancillaryinterrogators complete +git-hook mainporcelain git-http-backend synchingrepositories git-http-fetch synchelpers git-http-push synchelpers diff --git a/git.c b/git.c index 18bed9a9964..540909c391f 100644 --- a/git.c +++ b/git.c @@ -538,6 +538,7 @@ static struct cmd_struct commands[] = { { "grep", cmd_grep, RUN_SETUP_GENTLY }, { "hash-object", cmd_hash_object }, { "help", cmd_help }, + { "hook", cmd_hook, RUN_SETUP }, { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "init", cmd_init_db }, { "init-db", cmd_init_db }, diff --git a/hook.c b/hook.c index 97cd799a320..dd67801c962 100644 --- a/hook.c +++ b/hook.c @@ -1,6 +1,7 @@ #include "cache.h" #include "hook.h" #include "run-command.h" +#include "config.h" const char *find_hook(const char *name) { @@ -40,3 +41,103 @@ int hook_exists(const char *name) { return !!find_hook(name); } + +void run_hooks_opt_clear(struct run_hooks_opt *o) +{ + strvec_clear(&o->env); + strvec_clear(&o->args); +} + +static int pick_next_hook(struct child_process *cp, + struct strbuf *out, + void *pp_cb, + void **pp_task_cb) +{ + struct hook_cb_data *hook_cb = pp_cb; + struct hook *run_me = hook_cb->run_me; + + if (!run_me) + return 0; + + cp->no_stdin = 1; + cp->env = hook_cb->options->env.v; + cp->stdout_to_stderr = 1; + cp->trace2_hook_name = hook_cb->hook_name; + + /* add command */ + strvec_push(&cp->args, run_me->hook_path); + + /* + * add passed-in argv, without expanding - let the user get back + * exactly what they put in + */ + strvec_pushv(&cp->args, hook_cb->options->args.v); + + /* Provide context for errors if necessary */ + *pp_task_cb = run_me; + + /* + * This pick_next_hook() will be called again, we're only + * running one hook, so indicate that no more work will be + * done. + */ + hook_cb->run_me = NULL; + + return 1; +} + +static int notify_start_failure(struct strbuf *out, + void *pp_cb, + void *pp_task_cp) +{ + struct hook_cb_data *hook_cb = pp_cb; + struct hook *attempted = pp_task_cp; + + hook_cb->rc |= 1; + + strbuf_addf(out, _("Couldn't start hook '%s'\n"), + attempted->hook_path); + + return 1; +} + +static int notify_hook_finished(int result, + struct strbuf *out, + void *pp_cb, + void *pp_task_cb) +{ + struct hook_cb_data *hook_cb = pp_cb; + + hook_cb->rc |= result; + + return 0; +} + +int run_hooks(const char *hook_name, const char *hook_path, + struct run_hooks_opt *options) +{ + struct hook my_hook = { + .hook_path = hook_path, + }; + struct hook_cb_data cb_data = { + .rc = 0, + .hook_name = hook_name, + .options = options, + }; + int jobs = 1; + + if (!options) + BUG("a struct run_hooks_opt must be provided to run_hooks"); + + cb_data.run_me = &my_hook; + + run_processes_parallel_tr2(jobs, + pick_next_hook, + notify_start_failure, + notify_hook_finished, + &cb_data, + "hook", + hook_name); + + return cb_data.rc; +} diff --git a/hook.h b/hook.h index 368754b1201..d5bc1dc74c9 100644 --- a/hook.h +++ b/hook.h @@ -1,5 +1,33 @@ #ifndef HOOK_H #define HOOK_H +#include "strvec.h" + +struct hook { + /* The path to the hook */ + const char *hook_path; +}; + +struct run_hooks_opt +{ + /* Environment vars to be set for each hook */ + struct strvec env; + + /* Args to be passed to each hook */ + struct strvec args; +}; + +#define RUN_HOOKS_OPT_INIT { \ + .env = STRVEC_INIT, \ + .args = STRVEC_INIT, \ +} + +struct hook_cb_data { + /* rc reflects the cumulative failure state */ + int rc; + const char *hook_name; + struct hook *run_me; + struct run_hooks_opt *options; +}; /** * Returns the path to the hook file, or NULL if the hook is missing @@ -13,4 +41,15 @@ const char *find_hook(const char *name); */ int hook_exists(const char *hookname); +/** + * Clear data from an initialized "struct run_hooks-opt". + */ +void run_hooks_opt_clear(struct run_hooks_opt *o); + +/** + * Takes an already resolved hook found via find_hook() and runs + * it. Does not call run_hooks_opt_clear() for you. + */ +int run_hooks(const char *hookname, const char *hook_path, + struct run_hooks_opt *options); #endif diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh new file mode 100755 index 00000000000..d0a3796f28e --- /dev/null +++ b/t/t1800-hook.sh @@ -0,0 +1,128 @@ +#!/bin/sh + +test_description='git-hook command' + +. ./test-lib.sh + +test_expect_success 'git hook usage' ' + test_expect_code 129 git hook && + test_expect_code 129 git hook run && + test_expect_code 129 git hook run -h && + test_expect_code 129 git hook run --unknown 2>err && + grep "unknown option" err +' + +test_expect_success 'git hook run: nonexistent hook' ' + cat >stderr.expect <<-\EOF && + error: cannot find a hook named test-hook + EOF + test_expect_code 1 git hook run test-hook 2>stderr.actual && + test_cmp stderr.expect stderr.actual +' + +test_expect_success 'git hook run: basic' ' + write_script .git/hooks/test-hook <<-EOF && + echo Test hook + EOF + + cat >expect <<-\EOF && + Test hook + EOF + git hook run test-hook 2>actual && + test_cmp expect actual +' + +test_expect_success 'git hook run: stdout and stderr both write to our stderr' ' + write_script .git/hooks/test-hook <<-EOF && + echo >&1 Will end up on stderr + echo >&2 Will end up on stderr + EOF + + cat >stderr.expect <<-\EOF && + Will end up on stderr + Will end up on stderr + EOF + git hook run test-hook >stdout.actual 2>stderr.actual && + test_cmp stderr.expect stderr.actual && + test_must_be_empty stdout.actual +' + +test_expect_success 'git hook run: exit codes are passed along' ' + write_script .git/hooks/test-hook <<-EOF && + exit 1 + EOF + + test_expect_code 1 git hook run test-hook && + + write_script .git/hooks/test-hook <<-EOF && + exit 2 + EOF + + test_expect_code 2 git hook run test-hook && + + write_script .git/hooks/test-hook <<-EOF && + exit 128 + EOF + + test_expect_code 128 git hook run test-hook && + + write_script .git/hooks/test-hook <<-EOF && + exit 129 + EOF + + test_expect_code 129 git hook run test-hook +' + +test_expect_success 'git hook run arg u ments without -- is not allowed' ' + test_expect_code 129 git hook run test-hook arg u ments +' + +test_expect_success 'git hook run -- pass arguments' ' + write_script .git/hooks/test-hook <<-\EOF && + echo $1 + echo $2 + EOF + + cat >expect <<-EOF && + arg + u ments + EOF + + git hook run test-hook -- arg "u ments" 2>actual && + test_cmp expect actual +' + +test_expect_success 'git hook run -- out-of-repo runs excluded' ' + write_script .git/hooks/test-hook <<-EOF && + echo Test hook + EOF + + nongit test_must_fail git hook run test-hook +' + +test_expect_success 'git -c core.hooksPath= hook run' ' + mkdir my-hooks && + write_script my-hooks/test-hook <<-\EOF && + echo Hook ran $1 >>actual + EOF + + cat >expect <<-\EOF && + Test hook + Hook ran one + Hook ran two + Hook ran three + Hook ran four + EOF + + # Test various ways of specifying the path. See also + # t1350-config-hooks-path.sh + >actual && + git hook run test-hook -- ignored 2>>actual && + git -c core.hooksPath=my-hooks hook run test-hook -- one 2>>actual && + git -c core.hooksPath=my-hooks/ hook run test-hook -- two 2>>actual && + git -c core.hooksPath="$PWD/my-hooks" hook run test-hook -- three 2>>actual && + git -c core.hooksPath="$PWD/my-hooks/" hook run test-hook -- four 2>>actual && + test_cmp expect actual +' + +test_done From patchwork Thu Sep 2 13:11:09 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: 12471607 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 3B749C432BE for ; Thu, 2 Sep 2021 13:12:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22594610E5 for ; Thu, 2 Sep 2021 13:12:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345135AbhIBNND (ORCPT ); Thu, 2 Sep 2021 09:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345048AbhIBNMw (ORCPT ); Thu, 2 Sep 2021 09:12:52 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BF1CC0613D9 for ; Thu, 2 Sep 2021 06:11:53 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id x2-20020a1c7c02000000b002e6f1f69a1eso1401769wmc.5 for ; Thu, 02 Sep 2021 06:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VofH2jXtB6F+iDTJF+KVD2kDW0u+vrl3bs2Z463U/k4=; b=bLn8/i+U9PSC1xjqaGhlIuDwFLWxyyUTsZSrjltpEyzX8vF2kwSKamAHf4PlxyTMqx eaV+Ma6U4DJyx6hQmg1ct0JMStrl/A1KbYH6RePIULd9Q4pDass7p/2w7vLBjM7QuMgW 3cfeDNJzmHJ6+kHae+0/ExNgnzGXXSU1hERnIpe5nbplEceOqllBfeyQT8Mh8q7nClaT 2Ln1dPU8lZQl7Fc23BlqUA8qARKuWEpwh4Wnb4M3wZHYP6yQo3nakfUXZ5uKZDhcVVU5 WZPtuFn0aX9hxWJahACNImONFOnRcMBJOm+c+BEJr5HRCaVaSBqvzlimqdG1nM51tVtj qOkw== 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=VofH2jXtB6F+iDTJF+KVD2kDW0u+vrl3bs2Z463U/k4=; b=NVUbWahWh66QaNOu2qemdY6WZB3St8H0uHbYvAIVBJWZDOEtQDSmmxunbX+KJaNnr3 eB6Rjtly65LdCJV8zNHFodfyAashKleJRZU8iGMwsH4M/Aemg1x3QLg1MQDgk6eX4uZf vA1MtfjX1qUdYfSV2/MeQd6PXP61y7jx9abm9kPK5kn7+Zf3R6gAemfN5xLk14pGgwzQ Vxgg31x7jwxfll5c+1JGuY+8zPJNayj3Cm2TxFvrySTqmVAom9R7JALg7cT6HHlr2cMC aKPmqvkWoG6anpDWmXnbH9fdpWvDhrRr1Ocx9DbYv7zAG7U9nyWQae/wGr8E3yGuy0VP /U/A== X-Gm-Message-State: AOAM5308WjssFWpG4lY8G2jNJd9u01RoBugwhj+nuUcPHgT5ClXHVhzs DLP+UN6NYNsSTaW3P/SmAd7HGyHLo6q10Q== X-Google-Smtp-Source: ABdhPJxI7V5+rOQ/dA9+hZ4IIDaayT6NFQFewTnTGiLUdqsy0g557UPqnDeB7VdFOJbtrP72qrfDag== X-Received: by 2002:a1c:7506:: with SMTP id o6mr3267783wmc.112.1630588311095; Thu, 02 Sep 2021 06:11:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 09/36] gc: use hook library for pre-auto-gc hook Date: Thu, 2 Sep 2021 15:11:09 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the pre-auto-gc hook away from run-command.h to and over to the new hook.h library. To do this introduce a simple run_hooks_oneshot() wrapper, we'll be using it extensively for these simple cases of wanting to run a single hook under a given name, and having it free the memory we allocate for us. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 3 ++- hook.c | 23 +++++++++++++++++++++++ hook.h | 13 +++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index 6ce5ca45126..c91a0786836 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -32,6 +32,7 @@ #include "remote.h" #include "object-store.h" #include "exec-cmd.h" +#include "hook.h" #define FAILED_RUN "failed to run %s" @@ -394,7 +395,7 @@ static int need_to_gc(void) else return 0; - if (run_hook_le(NULL, "pre-auto-gc", NULL)) + if (run_hooks_oneshot("pre-auto-gc", NULL)) return 0; return 1; } diff --git a/hook.c b/hook.c index dd67801c962..1776895289e 100644 --- a/hook.c +++ b/hook.c @@ -141,3 +141,26 @@ int run_hooks(const char *hook_name, const char *hook_path, return cb_data.rc; } + +int run_hooks_oneshot(const char *hook_name, struct run_hooks_opt *options) +{ + const char *hook_path; + int ret; + struct run_hooks_opt hook_opt_scratch = RUN_HOOKS_OPT_INIT; + + if (!options) + options = &hook_opt_scratch; + + hook_path = find_hook(hook_name); + if (!hook_path) { + ret = 0; + goto cleanup; + } + + ret = run_hooks(hook_name, hook_path, options); + +cleanup: + run_hooks_opt_clear(options); + + return ret; +} diff --git a/hook.h b/hook.h index d5bc1dc74c9..b7a106a6e2b 100644 --- a/hook.h +++ b/hook.h @@ -49,7 +49,20 @@ void run_hooks_opt_clear(struct run_hooks_opt *o); /** * Takes an already resolved hook found via find_hook() and runs * it. Does not call run_hooks_opt_clear() for you. + * + * See run_hooks_oneshot() for the simpler one-shot API. */ int run_hooks(const char *hookname, const char *hook_path, struct run_hooks_opt *options); + +/** + * Calls find_hook() on your "hook_name" and runs the hooks (if any) + * with run_hooks(). + * + * If "options" is provided calls run_hooks_opt_clear() on it for + * you. If "options" is NULL the default options from + * RUN_HOOKS_OPT_INIT will be used. + */ +int run_hooks_oneshot(const char *hook_name, struct run_hooks_opt *options); + #endif From patchwork Thu Sep 2 13:11:10 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: 12471609 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 20E40C4320E for ; Thu, 2 Sep 2021 13:12:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A9D0610D0 for ; Thu, 2 Sep 2021 13:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345085AbhIBNNH (ORCPT ); Thu, 2 Sep 2021 09:13:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345070AbhIBNMx (ORCPT ); Thu, 2 Sep 2021 09:12:53 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EC12C0617AF for ; Thu, 2 Sep 2021 06:11:54 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id v20-20020a1cf714000000b002e71f4d2026so1102349wmh.1 for ; Thu, 02 Sep 2021 06:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GW/Y1V7q0QExsDkiwHKKYGiE4lHKcaBesB56xZbXBW8=; b=SGKvN15S5P7wIu38NjLZV+fZ2UFx6kjU3jWBnJwF8XKjA6hNpwziy+KUMDBaldFbtt BudLdHlBRSD4RvH27ZoutdNQx6RyN6XfwSwHuYXGMmUBFDwQMItp72fPYrY6I9o3g50v 0kIUsqFhqcd3ELeCIlS4vNybfgg8jxElbxWI4IhLoXbRf2hTzfab4LXJTin4MrXEEOLj Xx5OZJ+dDpa+1+LCoxcpUg+c2dmUaobJPDHA7j6SCigLLGHSpbkG6kiXjFQBrptd6W3v yq1pgP18rVvrBHT1Mo3Hr7+xmSYLRydKLnpV7kxRtWblYzbuKyKvq+wJc26TDERPziW+ CmjA== 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=GW/Y1V7q0QExsDkiwHKKYGiE4lHKcaBesB56xZbXBW8=; b=JeESic8hZwPVjMFQ9xr5+o6Vs/8btt9YjOPX1fZ5YcZZ318gogU24317NNcAfz7/fZ AX8m83o7YNNs11aIQTTi3XF4RIpqIpk3JlfdJA0Oq9R99ij4S3jyVMLbUOjSveOcapii QPxNECZbETmzpP56HiZyWAUTus5zsrpfAsxudxZpAZf3i++xvWFuYbzPjjtpJJpFXtCq kGBfuJ94IOBigpHHmBC2dQHaayPC2LXZAfn35fSmUBDKHvyqUh84EJIycGb8xv7d1eGs 3SyMNnr5r9UXVe6ZDo+JYlZljNjZtU3li0XEXfviSjM56B1X7KkfhqfE4SPyh83XT2zw s9qw== X-Gm-Message-State: AOAM533nW8b0HZ1DeL16ZmTzFLI5vavkla+HrYAAuZqq6UUdEpaSV6I4 TYJxwXBROgASJiTQlDC1r2tdfl6VIXgGTg== X-Google-Smtp-Source: ABdhPJyp9+cqHE37k3rYu1JXbZ1VLmbacVaIFtpZytGN6iVw5fIfKi8YDJpiVaSnLdW8Ig2mufAvkA== X-Received: by 2002:a1c:4e11:: with SMTP id g17mr3167869wmh.2.1630588312510; Thu, 02 Sep 2021 06:11:52 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 10/36] rebase: convert pre-rebase to use hook.h Date: Thu, 2 Sep 2021 15:11:10 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the pre-rebase hook away from run-command.h to and over to the new hook.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index c284a7ace19..ee68a1df492 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -28,6 +28,7 @@ #include "sequencer.h" #include "rebase-interactive.h" #include "reset.h" +#include "hook.h" #define DEFAULT_REFLOG_ACTION "rebase" @@ -1313,6 +1314,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) char *squash_onto_name = NULL; int reschedule_failed_exec = -1; int allow_preemptive_ff = 1; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; struct option builtin_rebase_options[] = { OPT_STRING(0, "onto", &options.onto_name, N_("revision"), @@ -2022,9 +2024,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } /* If a hook exists, give it a chance to interrupt*/ + strvec_pushl(&hook_opt.args, options.upstream_arg, argc ? argv[0] : NULL, NULL); if (!ok_to_skip_pre_rebase && - run_hook_le(NULL, "pre-rebase", options.upstream_arg, - argc ? argv[0] : NULL, NULL)) + run_hooks_oneshot("pre-rebase", &hook_opt)) die(_("The pre-rebase hook refused to rebase.")); if (options.flags & REBASE_DIFFSTAT) { From patchwork Thu Sep 2 13:11:11 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: 12471611 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 77447C432BE for ; Thu, 2 Sep 2021 13:12:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A083610D0 for ; Thu, 2 Sep 2021 13:12:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345015AbhIBNNI (ORCPT ); Thu, 2 Sep 2021 09:13:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345038AbhIBNMx (ORCPT ); Thu, 2 Sep 2021 09:12:53 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5149BC061757 for ; Thu, 2 Sep 2021 06:11:55 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id g138so1245294wmg.4 for ; Thu, 02 Sep 2021 06:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vqudbvsIDF4vFKwNIJw+taDNmKQyPMXTCSUvyhpQYrU=; b=hhNXrM/48OMKRrxWhFjtkI/dVXX0vK4giucjtDwzhN2PBOkWi0TQ7AYUF2GoaZ8QHS sYGxrqypnfifrNBwIDmXB7c9U2ukEi6VUe/dYWSd0zN/dqWbRUZtCpNX5yKRnY2HrK/T El7zU3W+UeeagyKUVY4KMwJanF1R/Ln58MuaV8x8az5JzZrUamRPO+iRPhntkJtvcbjS 43SCZ9y2GGLeUHIj/IWugqdDEHHrl4Z6gQBoz0FP5P5ErbgkD8vofuwU3Y+b4UusOG34 DiDRIiuwH/e/6mWUy1HfjiZImFysDIsV5FqPkQXWW7AsuledVDZYbTYMPtWVo+LwTArb t3rA== 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=vqudbvsIDF4vFKwNIJw+taDNmKQyPMXTCSUvyhpQYrU=; b=ZY6fdPTNeWJsqfoEkFqHvoZiodg7eKWXtuu9iZdhvW/CSq7kn4/FjzANXr6/KFfbJ3 7ij1f7Y3URKbFxOczDMBQxkFNOmnlfgKH3xEtkZ8EYTomedZffvg1njcY0bQL0Fxqh2e Kyk8cF2jkv4N3dqRnMeINTDXa5Aw1agPIBRajCNwpjAU2i1uhwxdgrKvM4S35Cjd9kpD a+Hr6Uzl/SKMdCSCYcBFuttYyQ7IsODaO8u9f90EsoQrsi91yJ3AAqiiZzOEhmuWTW6J 1aVkabHEu8OepVFbpO+h12ZulEHrohhSbeb3Ep21JU4UfaCr9IzHJ5AAuRX21hMKiRMe yefw== X-Gm-Message-State: AOAM533r+lXk89kP20lFVkDVLx9gIv5APCuxvKtGHPImuAHDl9uA4Twh OiaiVeOpoYMIkRs8pmG4wCh+oPF+4tfzEg== X-Google-Smtp-Source: ABdhPJxMqgCxodeT1BfUvpxYprZeJDgTNGz2fQfzuBPaMFNlGA7nm3T3dB/XKPQVUbFGZeBlRnY7kQ== X-Received: by 2002:a05:600c:298:: with SMTP id 24mr3029232wmk.172.1630588313661; Thu, 02 Sep 2021 06:11:53 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:53 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 11/36] am: convert applypatch to use hook.h Date: Thu, 2 Sep 2021 15:11:11 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Teach pre-applypatch, post-applypatch, and applypatch-msg to use the hook.h library instead of the run-command.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index c603f3cebdf..e444b18b64a 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -446,9 +446,11 @@ static void am_destroy(const struct am_state *state) static int run_applypatch_msg_hook(struct am_state *state) { int ret; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; assert(state->msg); - ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL); + strvec_push(&opt.args, am_path(state, "final-commit")); + ret = run_hooks_oneshot("applypatch-msg", &opt); if (!ret) { FREE_AND_NULL(state->msg); @@ -1609,7 +1611,7 @@ static void do_commit(const struct am_state *state) const char *reflog_msg, *author, *committer = NULL; struct strbuf sb = STRBUF_INIT; - if (run_hook_le(NULL, "pre-applypatch", NULL)) + if (run_hooks_oneshot("pre-applypatch", NULL)) exit(1); if (write_cache_as_tree(&tree, 0, NULL)) @@ -1661,7 +1663,7 @@ static void do_commit(const struct am_state *state) fclose(fp); } - run_hook_le(NULL, "post-applypatch", NULL); + run_hooks_oneshot("post-applypatch", NULL); strbuf_release(&sb); } From patchwork Thu Sep 2 13:11:12 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: 12471613 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 2B7A9C4320A for ; Thu, 2 Sep 2021 13:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12C7F6108E for ; Thu, 2 Sep 2021 13:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345105AbhIBNNN (ORCPT ); Thu, 2 Sep 2021 09:13:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345082AbhIBNMz (ORCPT ); Thu, 2 Sep 2021 09:12:55 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93891C0613C1 for ; Thu, 2 Sep 2021 06:11:56 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 192-20020a1c04c9000000b002f7a4ab0a49so1124024wme.0 for ; Thu, 02 Sep 2021 06:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j6lLU7KPI7myWBptiKDozkWIaYddu8OyRR5UIjYaeXY=; b=ToSqp71VnXiTJLk0CvFyBdH3piJT/O7PiHtXVX3h+D4BwrPhSH1FgUNxawUfkpZSJg ovTsJoKJf7uR7rynWM/EmZ4W24SYFku8l9KyUBC0BuMUsVgtjZ2xejGKjUAixKFVoFVd s4iydh1ZBKQ3gTP5kYA4F9QR3fPQSFb7VHIAN0Jx+9Jxe7mSeCXGkhJ3c3mUyf0rSYI9 n5W0AJTFKYp4C+tf+s/i+FOs77yzkfUzIjyDWBZVgcP7vinZwYHPFoAzCLgC4o9iB/GN sjKx6WHQfxM+K/WPhNZvA88ntbPXL+UE+3RexTVkDRLr9PN7cA4zPMJIo3a5dAgD5v6J 33pg== 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=j6lLU7KPI7myWBptiKDozkWIaYddu8OyRR5UIjYaeXY=; b=ggYzKBkwUOxAmdWXdehR5aOsRGUV4FQWw7cMutn3g0DP+VrdUpSv+ts7F/4WkzD5TI ZwrQiAw9XWTINaJV213UaTN2LiWWbMLgqlvBkh0AzzyVVTXTl3DxKf10hL7Dbg9Y32X8 CVgH+Yl7cD0YHerYRcN9oq9q5mQ60MIDt8oQfk06IumCKoRpoWoOkgnTS9I/B15Arv7D 1ydc3QtJ9g0fhuip8BO09uJ7Hnb/Hq24RC5h/S0Z2rO8ObjC5KEWoXCLGiz33jJTSLxq qqcj0Ln93ZHLlYvNSIqlpPjFKCrRD11PQj1ImSY9PD3BIJqQfjXg5bgnMFnj9Jk/bEDd h71A== X-Gm-Message-State: AOAM531mAadWdQTY3IvE6dWsPMxxzDjfByJ4H14unGIPwgB5IuT/5AY+ eYPzXBwuFB2Ljn+yhRuyk8Cf71wW/FmlWw== X-Google-Smtp-Source: ABdhPJw6XOgNZidNKefzyy8B7e4U30bP485iIUlvCCOYYMzairkMw7vIcs8N230xH4crycl7Vy/AwA== X-Received: by 2002:a1c:3954:: with SMTP id g81mr3076787wma.125.1630588314778; Thu, 02 Sep 2021 06:11:54 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:54 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 12/36] hooks: convert 'post-checkout' hook to hook library Date: Thu, 2 Sep 2021 15:11:12 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the running of the 'post-checkout' hook away from run-command.h to the new hook.h library. For "worktree" this requires a change to it to run the hooks from a given directory. We could strictly speaking skip the "absolute_path" flag and just check if "dir" is specified, but let's split them up for clarity, as well as for any future user who'd like to set "dir" but not implicitly change the argument to an absolute path. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/checkout.c | 14 +++++++++----- builtin/clone.c | 6 ++++-- builtin/worktree.c | 28 ++++++++++++---------------- hook.c | 9 +++++++++ hook.h | 9 +++++++++ read-cache.c | 1 + reset.c | 14 ++++++++++---- 7 files changed, 54 insertions(+), 27 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index b5d477919a7..863b02a7d7c 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -9,6 +9,7 @@ #include "config.h" #include "diff.h" #include "dir.h" +#include "hook.h" #include "ll-merge.h" #include "lockfile.h" #include "merge-recursive.h" @@ -106,13 +107,16 @@ struct branch_info { static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit, int changed) { - return run_hook_le(NULL, "post-checkout", - oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()), - oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()), - changed ? "1" : "0", NULL); + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + /* "new_commit" can be NULL when checking out from the index before a commit exists. */ - + strvec_pushl(&opt.args, + oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()), + oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()), + changed ? "1" : "0", + NULL); + return run_hooks_oneshot("post-checkout", &opt); } static int update_some(const struct object_id *oid, struct strbuf *base, diff --git a/builtin/clone.c b/builtin/clone.c index 66fe66679c8..27fc05ee511 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -32,6 +32,7 @@ #include "connected.h" #include "packfile.h" #include "list-objects-filter-options.h" +#include "hook.h" /* * Overall FIXMEs: @@ -775,6 +776,7 @@ static int checkout(int submodule_progress) struct tree *tree; struct tree_desc t; int err = 0; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; if (option_no_checkout) return 0; @@ -820,8 +822,8 @@ static int checkout(int submodule_progress) if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); - err |= run_hook_le(NULL, "post-checkout", oid_to_hex(null_oid()), - oid_to_hex(&oid), "1", NULL); + strvec_pushl(&hook_opt.args, oid_to_hex(null_oid()), oid_to_hex(&oid), "1", NULL); + err |= run_hooks_oneshot("post-checkout", &hook_opt); if (!err && (option_recurse_submodules.nr > 0)) { struct strvec args = STRVEC_INIT; diff --git a/builtin/worktree.c b/builtin/worktree.c index d22ece93e1a..330867c19bf 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -382,22 +382,18 @@ static int add_worktree(const char *path, const char *refname, * is_junk is cleared, but do return appropriate code when hook fails. */ if (!ret && opts->checkout) { - const char *hook = find_hook("post-checkout"); - if (hook) { - const char *env[] = { "GIT_DIR", "GIT_WORK_TREE", NULL }; - cp.git_cmd = 0; - cp.no_stdin = 1; - cp.stdout_to_stderr = 1; - cp.dir = path; - cp.env = env; - cp.argv = NULL; - cp.trace2_hook_name = "post-checkout"; - strvec_pushl(&cp.args, absolute_path(hook), - oid_to_hex(null_oid()), - oid_to_hex(&commit->object.oid), - "1", NULL); - ret = run_command(&cp); - } + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + + strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL); + strvec_pushl(&opt.args, + oid_to_hex(null_oid()), + oid_to_hex(&commit->object.oid), + "1", + NULL); + opt.dir = path; + opt.absolute_path = 1; + + ret = run_hooks_oneshot("post-checkout", &opt); } strvec_clear(&child_env); diff --git a/hook.c b/hook.c index 1776895289e..8a923e52c1b 100644 --- a/hook.c +++ b/hook.c @@ -63,6 +63,7 @@ static int pick_next_hook(struct child_process *cp, cp->env = hook_cb->options->env.v; cp->stdout_to_stderr = 1; cp->trace2_hook_name = hook_cb->hook_name; + cp->dir = hook_cb->options->dir; /* add command */ strvec_push(&cp->args, run_me->hook_path); @@ -116,6 +117,7 @@ static int notify_hook_finished(int result, int run_hooks(const char *hook_name, const char *hook_path, struct run_hooks_opt *options) { + struct strbuf abs_path = STRBUF_INIT; struct hook my_hook = { .hook_path = hook_path, }; @@ -129,6 +131,10 @@ int run_hooks(const char *hook_name, const char *hook_path, if (!options) BUG("a struct run_hooks_opt must be provided to run_hooks"); + if (options->absolute_path) { + strbuf_add_absolute_path(&abs_path, hook_path); + my_hook.hook_path = abs_path.buf; + } cb_data.run_me = &my_hook; run_processes_parallel_tr2(jobs, @@ -139,6 +145,9 @@ int run_hooks(const char *hook_name, const char *hook_path, "hook", hook_name); + if (options->absolute_path) + strbuf_release(&abs_path); + return cb_data.rc; } diff --git a/hook.h b/hook.h index b7a106a6e2b..3edd937e198 100644 --- a/hook.h +++ b/hook.h @@ -14,6 +14,15 @@ struct run_hooks_opt /* Args to be passed to each hook */ struct strvec args; + + /* + * Resolve and run the "absolute_path(hook)" instead of + * "hook". Used for "git worktree" hooks + */ + int absolute_path; + + /* Path to initial working directory for subprocess */ + const char *dir; }; #define RUN_HOOKS_OPT_INIT { \ diff --git a/read-cache.c b/read-cache.c index 9048ef9e905..7a9ffea0885 100644 --- a/read-cache.c +++ b/read-cache.c @@ -28,6 +28,7 @@ #include "sparse-index.h" #include "csum-file.h" #include "promisor-remote.h" +#include "hook.h" /* Mask for the name length in ce_flags in the on-disk index */ diff --git a/reset.c b/reset.c index 79310ae071b..1237ced8a58 100644 --- a/reset.c +++ b/reset.c @@ -7,6 +7,7 @@ #include "tree-walk.h" #include "tree.h" #include "unpack-trees.h" +#include "hook.h" int reset_head(struct repository *r, struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -125,10 +126,15 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, ret = create_symref("HEAD", switch_to_branch, reflog_head); } - if (run_hook) - run_hook_le(NULL, "post-checkout", - oid_to_hex(orig ? orig : null_oid()), - oid_to_hex(oid), "1", NULL); + if (run_hook) { + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + strvec_pushl(&opt.args, + oid_to_hex(orig ? orig : null_oid()), + oid_to_hex(oid), + "1", + NULL); + run_hooks_oneshot("post-checkout", &opt); + } leave_reset_head: strbuf_release(&msg); From patchwork Thu Sep 2 13:11:13 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: 12471615 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 25FAFC43214 for ; Thu, 2 Sep 2021 13:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C0FF6108E for ; Thu, 2 Sep 2021 13:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345066AbhIBNNO (ORCPT ); Thu, 2 Sep 2021 09:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345098AbhIBNM6 (ORCPT ); Thu, 2 Sep 2021 09:12:58 -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 533E6C0612E7 for ; Thu, 2 Sep 2021 06:11:57 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id q11so2847100wrr.9 for ; Thu, 02 Sep 2021 06:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/862uM2Rfvv2d2PwcMBW3WgabjsMKg8Eef8rLg40Tnw=; b=gDobLURoX1Eauxvcs7ERpe2oJFXADlXUetHxXnReo3BRH0PbvVAc4pQdlMuLQ/kl+g t6nitciG0WJhE6y1oIL6yYRFl/EYi9NLKpxiaySO3MgpqfmawqtpKrR1+JTo2TKggEET C0PY/oGSkGlJRvO+s/hvGIBnqPGh3tjUZ7WLqBF2n5oXs2XAm347M77MouhDAA1gEKjx sB++9n/qgaPYBLRwgVFn0rczH6sHPeixFVEZ4qphcVfMhXDVLnAazJbppDhK8NS1WFRM v1nxlJ9ALOLVMFqeIZbcS7OWsm/dkuZ6fbgj2ioN79WiYE8cDT3xtazljaIsCq2qbQbc 0GQg== 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=/862uM2Rfvv2d2PwcMBW3WgabjsMKg8Eef8rLg40Tnw=; b=mewTYdDY5S8sd6zxtwsGbCB0fibruN/aXCrP/Vuo0Z6frXBLqEjgrqyQbu5vuTwAyR bXKiEpXpiUJrAQ1bU1yZVvnI32m8ffUIlDSxzcmi9+IKNrr/Vm8KAXm7xhFRvqWzl298 rq/q8pVvoHqSoErhsQ4/NnUgdlfRg0nekLsiv+pZSi0ZVhS8JxxwS5fQhSaq2yZ5W6Re MuwW157VHIO8tMQhjMpper3XI4Fvt9gknULz5eER3t+sbfZegGMC/hQOpsI8aNJbISUy rKr6nWVjpWkM+mAq2ad9G6abOSup2buA932btu4e/SCbnwy9McK2D2P12+9zcWSMymMN mr2A== X-Gm-Message-State: AOAM532QvLNMgzKPJ0L93xiy0mlcO5OlLMKHt/n8sWtcAC6Ky1WaGwXW 5OOhfOgyW/zI9xG+Jt7gULAmTcwH5y0adQ== X-Google-Smtp-Source: ABdhPJzHShn4K8aTqrTMJVgT/g6/GnQsYHgB9ORNUoJqYwxDXr7QwZtZfxLYHe0HSp9wIIS0/2vbxw== X-Received: by 2002:adf:b748:: with SMTP id n8mr3656033wre.133.1630588315728; Thu, 02 Sep 2021 06:11:55 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:55 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 13/36] merge: convert post-merge to use hook.h Date: Thu, 2 Sep 2021 15:11:13 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Teach post-merge to use the hook.h library instead of the run-command.h library to run hooks. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index d75a438298b..ca9b3ba4827 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -448,6 +448,7 @@ static void finish(struct commit *head_commit, const struct object_id *new_head, const char *msg) { struct strbuf reflog_message = STRBUF_INIT; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; const struct object_id *head = &head_commit->object.oid; if (!msg) @@ -489,7 +490,8 @@ static void finish(struct commit *head_commit, } /* Run a post-merge hook */ - run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL); + strvec_push(&opt.args, squash ? "1" : "0"); + run_hooks_oneshot("post-merge", &opt); apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); From patchwork Thu Sep 2 13:11:14 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: 12471617 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 3346AC432BE for ; Thu, 2 Sep 2021 13:12:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FD33610D2 for ; Thu, 2 Sep 2021 13:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345161AbhIBNNP (ORCPT ); Thu, 2 Sep 2021 09:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345103AbhIBNM6 (ORCPT ); Thu, 2 Sep 2021 09:12:58 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C9BAC06129E for ; Thu, 2 Sep 2021 06:11:58 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id x6so2834482wrv.13 for ; Thu, 02 Sep 2021 06:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wDrE0FPvVH6LBUMt6J/72sA7CngBppk7QOSN1unW+bE=; b=GLwI3iFzq/GZGoJT1l/zK64ZdZxDAmylCsChsuQAs4OvzN9sF6LG7vYikv/NTcPDuu HW+9t09LTk6qKGUAQi+VdbO1qxLmsG39tWit2/jEGlB1aiMgz9CxOfQ2rrZ7PT6XsgJ9 zMJq4gnwj3r8AmnGd0khcDOxqIvfkNwBwat8DB41Rfz+0BmiADk4QFib6f8aQPdy7tsN 7M48GDCgr1+S6n0nGagk9yglQvIyJjkMApmN3VyA7I+EY1CVg6507stU+Hk32UYrJKdm YdZfbL6lF7tfC5tAJltL7d7xgtOEHtDUlME7l7u39jWx4AYq38RTIJK2Mxo7mA0edtC7 6aMw== 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=wDrE0FPvVH6LBUMt6J/72sA7CngBppk7QOSN1unW+bE=; b=PfgRaA1fuRtZsrqCP5Weln9KISA4Jjro1zfTGNbWzLFUnVibNuYiMVTrIxsW9jJfhY MrjQshBFzjFBGbMAzVlQwpl8QoeeBqDn87Pq5pX6wyjQut9cJwbAYVP6JXoFcOgLeGWE IK13UYWqU3u1HnSzBm7/Ej7DNGLISPBUiM6CZ6zjgQcElFrjWhyVdgp5nhhmb9cSawCk bFXs29S57lEi+7y1Bh+DM4m0ofWH1kuMeNQMn0EDZ5MT0ru70xGkxqCLFgNtFUstUMsi ACT3BTd4Ck0O+kY2g4kEnPQRaJruiW/cODRktR1O3BK4VZlglCWmLrlR0LDmRgP7mNpI SamQ== X-Gm-Message-State: AOAM5309UEpXTm0wQb1s10+xyzwRZhPxeiXGHL18TAw6RnOcSuUCqCWG GOgCz78HTIB5LA9Pg3I/+Pgu5KyO/tFQgw== X-Google-Smtp-Source: ABdhPJxQNZOW2snnhx4toCByIWOMlltCeR1NF+hGmm5J/drp0t8Ljhsg/zzoyVwK8eNiBhAzKdnqVQ== X-Received: by 2002:adf:ce85:: with SMTP id r5mr3594434wrn.323.1630588317027; Thu, 02 Sep 2021 06:11:57 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:56 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 14/36] git hook run: add an --ignore-missing flag Date: Thu, 2 Sep 2021 15:11:14 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org For certain one-shot hooks we'd like to optimistically run them, and not complain if they don't exist. This will be used by send-email in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-hook.txt | 10 +++++++++- builtin/hook.c | 10 ++++++++-- t/t1800-hook.sh | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt index 660d6a992a0..097fb9de63b 100644 --- a/Documentation/git-hook.txt +++ b/Documentation/git-hook.txt @@ -8,7 +8,7 @@ git-hook - run git hooks SYNOPSIS -------- [verse] -'git hook' run [-- ] +'git hook' run [--ignore-missing] [-- ] DESCRIPTION ----------- @@ -29,6 +29,14 @@ optional `--` (or `--end-of-options`, see linkgit:gitcli[7]). The arguments (if any) differ by hook name, see linkgit:githooks[5] for what those are. +OPTIONS +------- + +--ignore-missing:: + Ignore any missing hook by quietly returning zero. Used for + tools that want to do a blind one-shot run of a hook that may + or may not be present. + SEE ALSO -------- linkgit:githooks[5] diff --git a/builtin/hook.c b/builtin/hook.c index 012a2973b38..76d49e672f4 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -7,7 +7,7 @@ #include "strvec.h" #define BUILTIN_HOOK_RUN_USAGE \ - N_("git hook run [-- ]") + N_("git hook run [--ignore-missing] [-- ]") static const char * const builtin_hook_usage[] = { BUILTIN_HOOK_RUN_USAGE, @@ -23,9 +23,12 @@ static int run(int argc, const char **argv, const char *prefix) { int i; struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + int ignore_missing = 0; const char *hook_name; const char *hook_path; struct option run_options[] = { + OPT_BOOL(0, "ignore-missing", &ignore_missing, + N_("exit quietly with a zero exit code if the requested hook cannot be found")), OPT_END(), }; int ret; @@ -55,9 +58,12 @@ static int run(int argc, const char **argv, const char *prefix) /* * We are not using a plain run_hooks() because we'd like to * detect missing hooks. Let's find it ourselves and call - * run_hooks() instead. + * run_hooks() instead... */ hook_name = argv[0]; + if (ignore_missing) + /* ... act like a plain run_hooks() under --ignore-missing */ + return run_hooks_oneshot(hook_name, &opt); hook_path = find_hook(hook_name); if (!hook_path) { error("cannot find a hook named %s", hook_name); diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index d0a3796f28e..feb95b8fc8d 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -20,6 +20,11 @@ test_expect_success 'git hook run: nonexistent hook' ' test_cmp stderr.expect stderr.actual ' +test_expect_success 'git hook run: nonexistent hook with --ignore-missing' ' + git hook run --ignore-missing does-not-exist 2>stderr.actual && + test_must_be_empty stderr.actual +' + test_expect_success 'git hook run: basic' ' write_script .git/hooks/test-hook <<-EOF && echo Test hook From patchwork Thu Sep 2 13:11:15 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: 12471619 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 2F088C432BE for ; Thu, 2 Sep 2021 13:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18A366108E for ; Thu, 2 Sep 2021 13:12:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345167AbhIBNNQ (ORCPT ); Thu, 2 Sep 2021 09:13:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345125AbhIBNND (ORCPT ); Thu, 2 Sep 2021 09:13:03 -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 0ABD3C0612A6 for ; Thu, 2 Sep 2021 06:12:00 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id i6so2864933wrv.2 for ; Thu, 02 Sep 2021 06:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=joo/s8DEOqX7PV/Qs2fEu8tKGCO39ibpaiHqibIa79I=; b=Tt3odRUTT2af/rC3nqDv8nXFZRJ148Q0kJNGU7fteZ15ZkmR1QvGXcJAsQmO4hQ7f6 Kc+HIM42N3TJbfwhqtEnqjtLWk4p/Q38oelOfLTf1H3YF3Qn3PL3nXB6lioUEo/NkMuf p46kuNrmY4yUeNYhj290f86N4X7EWuIfOMrXsLc++iVJXoZtsiqEvGV902gGvFluMp5M Y0kOu+bdPfkXBbT/hbC2KHsLZV7XRBU5qk8WJ4YE5MedAALTiQgkvwFsIXpM+luUEQuI gWSkTtCkEBrxaA/4OekYE0up3iKuNp53/QEr24tX+6lh126u5OmdKRnCycHjYEis241k LPpg== 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=joo/s8DEOqX7PV/Qs2fEu8tKGCO39ibpaiHqibIa79I=; b=Vhr6bdKwCXuaDRElAXP1m5k3UXoXTBZUkCoV/nAQMlEvEnAUzaPTPTfDi7ja/muW/E zgfPLHx5xkYdCrtpvmKIPnW+/jDhOVlJlgOE7p8t/yZ22zMhYUIzl5LKbC1p2f2HfZBY wA7/vIJx2urbOazLCXR3kDew3IYRNL8wZK1sFfTpgus6XMBekIQwB7qo5Ii1rsNUx83v Zy0U5VukWbM3rynCPgjJ01NN974H9nqBWhGiyjISiFgxuLxv+6aqBXX+9CCh36TyYBCT u74YsUyBcgw1CaHtHp4KjlmO4826a58kVPEjl21bqvgFgwE8mzEboF9APMaC9GI0HrCL TF0w== X-Gm-Message-State: AOAM531sKvPPL9OAUDufKvAGaIQOko6ZTWkbdEO5bYc3VUuX5EdeitxK EuyPm9zLYoODkiyoL6VvRbU4v+lkBcJIyQ== X-Google-Smtp-Source: ABdhPJwZdYsrALT+AXKXcDctfoTjEK2IsnoKC6DU9h6vtw8zncsbCcIcY/yyC29ABS3tvQIe0kAEoA== X-Received: by 2002:a5d:55cd:: with SMTP id i13mr3635016wrw.366.1630588318143; Thu, 02 Sep 2021 06:11:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:57 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 15/36] send-email: use 'git hook run' for 'sendemail-validate' Date: Thu, 2 Sep 2021 15:11:15 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Change the "sendmail-validate" hook to be run via the "git hook run" wrapper instead of via a direct invocation. This is the smallest possibly change to get "send-email" using "git hook run". We still check the hook itself with "-x", and set a "GIT_DIR" variable, both of which are asserted by our tests. We'll need to get rid of this special behavior if we start running N hooks, but for now let's be as close to bug-for-bug compatible as possible. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 20 ++++++++++++-------- t/t9001-send-email.sh | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index e65d969d0bb..126850d974b 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -195,13 +195,13 @@ sub format_2822_time { my $editor; sub system_or_msg { - my ($args, $msg) = @_; + my ($args, $msg, $cmd_name) = @_; system(@$args); my $signalled = $? & 127; my $exit_code = $? >> 8; return unless $signalled or $exit_code; - my @sprintf_args = ($args->[0], $exit_code); + my @sprintf_args = ($cmd_name ? $cmd_name : $args->[0], $exit_code); if (defined $msg) { # Quiet the 'redundant' warning category, except we # need to support down to Perl 5.8, so we can't do a @@ -2031,10 +2031,10 @@ sub validate_patch { my ($fn, $xfer_encoding) = @_; if ($repo) { + my $hook_name = 'sendemail-validate'; my $hooks_path = $repo->command_oneline('rev-parse', '--git-path', 'hooks'); require File::Spec; - my $validate_hook = File::Spec->catfile($hooks_path, - 'sendemail-validate'); + my $validate_hook = File::Spec->catfile($hooks_path, $hook_name); my $hook_error; if (-x $validate_hook) { require Cwd; @@ -2044,13 +2044,17 @@ sub validate_patch { chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); - $hook_error = system_or_msg([$validate_hook, $target]); + my @validate_hook = ("git", "hook", "run", "--ignore-missing", $hook_name, "--", $target); + $hook_error = system_or_msg(\@validate_hook, undef, + "git hook run $hook_name -- "); chdir($cwd_save) or die("chdir: $!"); } if ($hook_error) { - die sprintf(__("fatal: %s: rejected by sendemail-validate hook\n" . - "%s\n" . - "warning: no patches were sent\n"), $fn, $hook_error); + $hook_error = sprintf(__("fatal: %s: rejected by %s hook\n" . + $hook_error . "\n" . + "warning: no patches were sent\n"), + $fn, $hook_name); + die $hook_error; } } diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 57fc10e7f82..9ec7d75f0ff 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -539,7 +539,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 '"'"'my-hooks/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual @@ -558,7 +558,7 @@ 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 '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual From patchwork Thu Sep 2 13:11:16 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: 12471621 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 34967C432BE for ; Thu, 2 Sep 2021 13:12:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E9BD6108E for ; Thu, 2 Sep 2021 13:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345177AbhIBNNW (ORCPT ); Thu, 2 Sep 2021 09:13:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345126AbhIBNND (ORCPT ); Thu, 2 Sep 2021 09:13:03 -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 320C7C061796 for ; Thu, 2 Sep 2021 06:12:01 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id z4so2847229wrr.6 for ; Thu, 02 Sep 2021 06:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sAUDjTwIMDtKGi+zJ2dRl4kFDwzwtB7YeDDf17yCEdI=; b=XZxy/7/8QcQf5W9SG4xnRz5mmzw6K/m1mxL+MCljfp5mI0J+AoTBRkGjK7VrHhGTNc VKJS8GZXBlUHFeBB9C9tYRJExE3MSgM4ZuJenvQkw0OBJfv3rEqyRyWs8F7m4/oSj8L3 VB5dvVsNKESEI9cVVESjTKtL7x0LpXaR0zAtixybXSe14Sxu84WlNJcF1xEsH9TodQk8 KpIsfocK1+JYUlflQnAZlNuY3dn1KbB6wfyj672m8dDS1c/gJNPTzBl3DzrPeI1HJIsI WAkZXkvbGxkz63hKV5ejdtYIjWVRbiGJpjTPkqxUxY2F23WcBMvGFBOm+hR7Alp8emaD nZ7Q== 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=sAUDjTwIMDtKGi+zJ2dRl4kFDwzwtB7YeDDf17yCEdI=; b=IyB4NfNkgs75GnjLPNW2l8HFwlvLxRixtwAHM1aEKjCXrYCU78N5wFHDEyGl8HTVIL yq7zYflOFDt7Z4mITGTp4ElzxE2ZaOOrFa7RYDz743e2ZlBF74hOF5xlh1buwHd1rbH8 bVEGvCc8vwIgLUOjH6BBv1jS3IZn52f/xU0Y9q9ocTtm/IGc8bgMREc7nPtS+H8Debkl Q6EVd2Ps8qGledcM0fPtSKQtXCCuaiSavE0QdK3TbKdWaw6fh79s2hCZXs+NStSMLBdg ULoWvW/XTGLrnXriRSC6GxEOVN++74gbKp9pAVCmTgoq2uTANW9P19S6o0QbN0/vojBu F5wQ== X-Gm-Message-State: AOAM533JKidRyRqXUS3hTPN7qWK5mzg7BFluyx3ZBn2QMVPxWHa5HjmG bg6OjUSTZljp+aC6d01vFGg1MTOkt+Edsw== X-Google-Smtp-Source: ABdhPJzs8vgJPpUImKtXIIl1y48JoEXwZeMtsjDWfrsI0/PvBWFLhkEAx7Dm3lDi4EuSKpbLh5ntng== X-Received: by 2002:adf:fd8c:: with SMTP id d12mr3641720wrr.21.1630588319532; Thu, 02 Sep 2021 06:11:59 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:11:58 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 16/36] git-p4: use 'git hook' to run hooks Date: Thu, 2 Sep 2021 15:11:16 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Instead of duplicating the behavior of run-command.h:run_hook_le() in Python, we can directly call 'git hook run'. We emulate the existence check with the --ignore-missing flag. As this is the last hook execution in git.git to not go through "git hook run" or the hook.[ch] library we can now be absolutely sure that our assertion in hook.c that only hooks known by the generated (from githooks(5)) hook-list.h are permitted. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- git-p4.py | 72 ++++++------------------------------------------------- 1 file changed, 7 insertions(+), 65 deletions(-) diff --git a/git-p4.py b/git-p4.py index 2b4500226aa..1f24cbf0bca 100755 --- a/git-p4.py +++ b/git-p4.py @@ -207,71 +207,13 @@ def decode_path(path): return path def run_git_hook(cmd, param=[]): - """Execute a hook if the hook exists.""" - if verbose: - sys.stderr.write("Looking for hook: %s\n" % cmd) - sys.stderr.flush() - - hooks_path = gitConfig("core.hooksPath") - if len(hooks_path) <= 0: - hooks_path = os.path.join(os.environ["GIT_DIR"], "hooks") - - if not isinstance(param, list): - param=[param] - - # resolve hook file name, OS depdenent - hook_file = os.path.join(hooks_path, cmd) - if platform.system() == 'Windows': - if not os.path.isfile(hook_file): - # look for the file with an extension - files = glob.glob(hook_file + ".*") - if not files: - return True - files.sort() - hook_file = files.pop() - while hook_file.upper().endswith(".SAMPLE"): - # The file is a sample hook. We don't want it - if len(files) > 0: - hook_file = files.pop() - else: - return True - - if not os.path.isfile(hook_file) or not os.access(hook_file, os.X_OK): - return True - - return run_hook_command(hook_file, param) == 0 - -def run_hook_command(cmd, param): - """Executes a git hook command - cmd = the command line file to be executed. This can be - a file that is run by OS association. - - param = a list of parameters to pass to the cmd command - - On windows, the extension is checked to see if it should - be run with the Git for Windows Bash shell. If there - is no file extension, the file is deemed a bash shell - and will be handed off to sh.exe. Otherwise, Windows - will be called with the shell to handle the file assocation. - - For non Windows operating systems, the file is called - as an executable. - """ - cli = [cmd] + param - use_shell = False - if platform.system() == 'Windows': - (root,ext) = os.path.splitext(cmd) - if ext == "": - exe_path = os.environ.get("EXEPATH") - if exe_path is None: - exe_path = "" - else: - exe_path = os.path.join(exe_path, "bin") - cli = [os.path.join(exe_path, "SH.EXE")] + cli - else: - use_shell = True - return subprocess.call(cli, shell=use_shell) - + """args are specified with -a -a -a """ + args = ['git', 'hook', 'run', '--ignore-missing', cmd] + if param: + args.append("--") + for p in param: + args.append(p) + return subprocess.call(args) == 0 def write_pipe(c, stdin): if verbose: From patchwork Thu Sep 2 13:11:17 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: 12471623 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 47774C432BE for ; Thu, 2 Sep 2021 13:12:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B1D16108E for ; Thu, 2 Sep 2021 13:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345193AbhIBNNg (ORCPT ); Thu, 2 Sep 2021 09:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345134AbhIBNND (ORCPT ); Thu, 2 Sep 2021 09:13:03 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D987C0612A7 for ; Thu, 2 Sep 2021 06:12:02 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id b10so2915216wru.0 for ; Thu, 02 Sep 2021 06:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xo+rXtd5NZVQ5e01Rdl5+TrwkeWvb51b+GFIkIRqKBo=; b=Ar33kEKW5yj+d2sIl7QvcBqzGmz7tQfbzCz7RWM5kjmQ/zNaj0EynYWvZQy+A+Re9C ZPfUzfWC2yswXSz3S/a7XNWCVxnfJn7mOyBmd2q8efGK3zq/ATgU9xzFR8fIfI2bFlEL yKjLB1anguBT8bWtkbBaoi9wcGUIJWqiOzFH7Ow3/FvBB3QxnTVwEeyqJF3YghLdcgbF d6cmaT6HerObIrLU0D6l9m5SUEqxNLatJNw1ZIcMoYdWAJqYOBk9sLWJhtgmhHTIikcK rw6QTVDYMngTpRnxGtiBKVwfGRiMpcOiAjcBOSnPFSd3cotwKmqdA1BwfahMYpYswK4s C+XQ== 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=Xo+rXtd5NZVQ5e01Rdl5+TrwkeWvb51b+GFIkIRqKBo=; b=Dd5ed/GEIQGZfSVNk1YsW7tFXt2Hoh8uPF6+i1XvVhZJvfnakJ4/CA3cCuFDPVGEy1 rj4IpGU9skR0OdBb10Ue8BaOV0UWO0J/iLw2aAUIWsBBpTBuIkWyF5PgyJ1+UPwkelXh qdAnrpPy/a8r3r46XyUfBBNMs3MEr9N2NiK18SrCms+WVvz5E5mo5/y7irq59tbz/gJT Z/GrlcSkJ6UfKSQUsGb0kKznAlMuOMWZT00Pr3PpZ8nmF5zLwS6uDrstOuci6CZ8Q16S LYMGNbnq34BDQ54CApOEAb2hJU6QwoMDzdqyhfxHqL7El+l/4sw0jjUgbIyC7Kedsst6 todw== X-Gm-Message-State: AOAM530DE/hEk3ONzCsH78YSeGfKXiNNoKPy/iZBK0tYAAgE4peDk80I HwQ5zECIhrt7of+pUgnmnpLuX9HYH8aAQg== X-Google-Smtp-Source: ABdhPJzDVbZSnhhAzLLXzull2Vm995SPNmjshJ7/CpPMoB+/v2QjaE6pKbv+EVbkrnVXXmjHEODNhQ== X-Received: by 2002:adf:804a:: with SMTP id 68mr3692580wrk.236.1630588320483; Thu, 02 Sep 2021 06:12:00 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:00 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 17/36] commit: convert {pre-commit,prepare-commit-msg} hook to hook.h Date: Thu, 2 Sep 2021 15:11:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move these hooks hook away from run-command.h to and over to the new hook.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- commit.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/commit.c b/commit.c index 143f472c0f2..63d7943a86d 100644 --- a/commit.c +++ b/commit.c @@ -21,6 +21,7 @@ #include "commit-reach.h" #include "run-command.h" #include "shallow.h" +#include "hook.h" static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **); @@ -1698,22 +1699,22 @@ size_t ignore_non_trailer(const char *buf, size_t len) int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) { - struct strvec hook_env = STRVEC_INIT; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; va_list args; - int ret; + const char *arg; - strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); + strvec_pushf(&opt.env, "GIT_INDEX_FILE=%s", index_file); /* * Let the hook know that no editor will be launched. */ if (!editor_is_used) - strvec_push(&hook_env, "GIT_EDITOR=:"); + strvec_push(&opt.env, "GIT_EDITOR=:"); va_start(args, name); - ret = run_hook_ve(hook_env.v, name, args); + while ((arg = va_arg(args, const char *))) + strvec_push(&opt.args, arg); va_end(args); - strvec_clear(&hook_env); - return ret; + return run_hooks_oneshot(name, &opt); } From patchwork Thu Sep 2 13:11:18 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: 12471625 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 03340C4320A for ; Thu, 2 Sep 2021 13:12:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E28F5610D2 for ; Thu, 2 Sep 2021 13:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345134AbhIBNNh (ORCPT ); Thu, 2 Sep 2021 09:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345055AbhIBNNE (ORCPT ); Thu, 2 Sep 2021 09:13:04 -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 25ECDC0612A9 for ; Thu, 2 Sep 2021 06:12:03 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id g18so2840299wrc.11 for ; Thu, 02 Sep 2021 06:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TBLvehO8O+oegJdV/7voBg3ClvqSb4B5JkMTiDKXPNU=; b=crzgBJQmbgSB2dQj0AinkC50Oo1OZKsvhsfGYnhzH2ZyHWaAT0zRCEnFKAZmkeX4CD HbS7Y0p0DFLpdF0SqsfMpZ/Fk8/UD0dzVWbWirK78++zBX7tAPCIqkPKnPDd+wvq1Ob7 vNnMcO0oMA6uvk50jJ8OopGZ+EU33j3hXWtfCSn8pueZscr5ercMoH00/qoNxbttV7a9 ad+TioOUxs4k1zsI9mQ1g23ZEHBJ5H2ePGgZP4hkwbXfINSXucBlvvh4MWIb6SwBhGUN c74r62w2my2GlC3VmFmFwN+3vt7lpoPhBrEXbP6th8PjvnSl0uwNTzccqWBkFAOqdqZd yfyA== 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=TBLvehO8O+oegJdV/7voBg3ClvqSb4B5JkMTiDKXPNU=; b=DajEXuZNKnpcAP07I3mT7/Q+uSsL0r1FWh1D0v6glJ5cxx0dCvVEthYZ/i6PhkIYLk UjVAq90eNKTkaY0/u9AABKmzrQR6JzBVY9ruYy69XbaTL83eT+wRNyr++nyhiUsOu8Pc GBqB8v5eYYwZIqecidcDEOHTZZ0VNNpVcj0FpZZmU6vjQZVJlAxW+m3RFb/8OSk3yizN Vgkmdx6PWCTfMwnIDfH/lggQs0R3A1HuHoV9ZaBKBLF1lvIPKc+N5PotlOdxTeDO5sP1 pA/iuMzUmMYa2vKstFL73HTAdH1PlDUtKuhycbgCqTtF/ry9zTPfeMqpwanTUovL5L6r C74A== X-Gm-Message-State: AOAM533ix3v8CzZ0yYtGvpkXSZd/1qAt7ZGHLjJX/VttbJq57acEEfPA Dvqbsc5pbl2znvABjBV9+/1CUR/mJZaZPQ== X-Google-Smtp-Source: ABdhPJySv68fct8YAdKDz/FqDf0KfacIYWMLsK840YyfEJs91TOeRDS0EL9UUjY4DWHbtuiVTaQ/7Q== X-Received: by 2002:a5d:456b:: with SMTP id a11mr3674555wrc.291.1630588321476; Thu, 02 Sep 2021 06:12:01 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:00 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 18/36] read-cache: convert post-index-change to use hook.h Date: Thu, 2 Sep 2021 15:11:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the post-index-change hook away from run-command.h to and over to the new hook.h library. This removes the last direct user of run_hook_ve(), so we can make the function static now. It'll be removed entirely soon. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- read-cache.c | 10 +++++++--- run-command.c | 2 +- run-command.h | 1 - 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/read-cache.c b/read-cache.c index 7a9ffea0885..875f6c1dea5 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3069,6 +3069,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l { int ret; int was_full = !istate->sparse_index; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; ret = convert_to_sparse(istate); @@ -3097,9 +3098,12 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l else ret = close_lock_file_gently(lock); - run_hook_le(NULL, "post-index-change", - istate->updated_workdir ? "1" : "0", - istate->updated_skipworktree ? "1" : "0", NULL); + strvec_pushl(&hook_opt.args, + istate->updated_workdir ? "1" : "0", + istate->updated_skipworktree ? "1" : "0", + NULL); + run_hooks_oneshot("post-index-change", &hook_opt); + istate->updated_workdir = 0; istate->updated_skipworktree = 0; diff --git a/run-command.c b/run-command.c index 352f5be1646..b4341ba1c7b 100644 --- a/run-command.c +++ b/run-command.c @@ -1320,7 +1320,7 @@ int async_with_fork(void) #endif } -int run_hook_ve(const char *const *env, const char *name, va_list args) +static int run_hook_ve(const char *const *env, const char *name, va_list args) { struct child_process hook = CHILD_PROCESS_INIT; const char *p; diff --git a/run-command.h b/run-command.h index f76b740f927..7a867d41217 100644 --- a/run-command.h +++ b/run-command.h @@ -219,7 +219,6 @@ int run_command(struct child_process *); */ LAST_ARG_MUST_BE_NULL int run_hook_le(const char *const *env, const char *name, ...); -int run_hook_ve(const char *const *env, const char *name, va_list args); /* * Trigger an auto-gc From patchwork Thu Sep 2 13:11:19 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: 12471627 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 2FC5DC432BE for ; Thu, 2 Sep 2021 13:12:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15CFF610A0 for ; Thu, 2 Sep 2021 13:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345137AbhIBNNo (ORCPT ); Thu, 2 Sep 2021 09:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345153AbhIBNNG (ORCPT ); Thu, 2 Sep 2021 09:13:06 -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 3092BC0612AF for ; Thu, 2 Sep 2021 06:12:04 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id n5so2832443wro.12 for ; Thu, 02 Sep 2021 06:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rGCm6nrGmv9HCK/cM2iwIEMU+OTEATUQPfDN6FWPKjA=; b=i2CHxPsH9PlRK9AfAQvp+7sG8HnIqY0fZbynIY/QX3iP0/5pH9Lu6hZi6Eq+aGjwsq Tm/5VrogF2S/cVyN/qOkExPf1Y02TF3gV4XCVOBgbkwDsXLto7CmzXpmM8jwCTMoRe1/ 63ZVHzfXTyY44vnFn/rJqRrFs7/pIok/kq3LM0NrHuZPOjkdkjmMKRsh9YCWZMQ5DpvZ R3WqsGSxsFzynMhPxD0b4h+tkkLyy7SMopxVBZGUgDI7wIrJJqeNEuERN/5tGErKmx/x pxwQFEWgav4+88rcHhtriZgV6pabkmMPQugZyDrEp0NgEBGUOD30WmhRyH+fGOScqMHz /pUA== 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=rGCm6nrGmv9HCK/cM2iwIEMU+OTEATUQPfDN6FWPKjA=; b=rnqJnPlP5lZeJOj7NZ6m7yx6zsgVZ4qyXkNZXDusjlX71bsfUuujaDRzXW28lzPzsr /D2Akt96YpcXSP1yx0ePRaQmsNG4UzqqSbNnsprlfX/z/HY8F4DQkZGpNliRHojGplpw SJG8sdCm3mpboIpkGvTkcL7qYrM+glLJC7fuTBjReyZmWEPg6EIBi1U50wg0yC3iz094 kjRjhiwnrKcpHhlFO6kCpWR1kMbpRJSEY57iLfwQ2usmwyGFTQXO2MISaYrxs0El7Whl oJBH21a+LNc08SnsiGVHe0p9FenwL2yF95vimBQE58TdqSJnF78iUkdujGZcRYDTpli9 JwJA== X-Gm-Message-State: AOAM532bNXliop6rVx+9979NWmdlwniccht4Jx7bvNiOrZq+l3yHY9Lp C/Ty8qVJCsjK1pDR6vaH4JP3/AKgNVG4Lg== X-Google-Smtp-Source: ABdhPJyT8M5Yi+kmNdP6bZvlzQpiPmh3J5I0QE7h3mXoyXOo1t0E1NL+j+MqKJHmZASKMoa9jgRQvQ== X-Received: by 2002:a5d:6a08:: with SMTP id m8mr3708336wru.269.1630588322507; Thu, 02 Sep 2021 06:12:02 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:02 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 19/36] receive-pack: convert push-to-checkout hook to hook.h Date: Thu, 2 Sep 2021 15:11:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the push-to-checkout hook away from run-command.h to and over to the new hook.h library. This removes the last direct user of run_hook_le(), so we could remove that function now, but let's leave that to a follow-up cleanup commit. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/receive-pack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 91fa799b66e..a7d03bbc7d3 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1435,9 +1435,12 @@ static const char *push_to_checkout(unsigned char *hash, struct strvec *env, const char *work_tree) { + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); - if (run_hook_le(env->v, push_to_checkout_hook, - hash_to_hex(hash), NULL)) + strvec_pushv(&opt.env, env->v); + strvec_push(&opt.args, hash_to_hex(hash)); + if (run_hooks_oneshot(push_to_checkout_hook, &opt)) return "push-to-checkout hook declined"; else return NULL; From patchwork Thu Sep 2 13:11:20 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: 12471629 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 D962AC4320E for ; Thu, 2 Sep 2021 13:12:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C04BC610A0 for ; Thu, 2 Sep 2021 13:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345093AbhIBNNp (ORCPT ); Thu, 2 Sep 2021 09:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345152AbhIBNNG (ORCPT ); Thu, 2 Sep 2021 09:13:06 -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 6E968C061575 for ; Thu, 2 Sep 2021 06:12:05 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id m9so2881308wrb.1 for ; Thu, 02 Sep 2021 06:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7qvkw2rh1v07dKjdJW16zWvEdglTDlF1uoylnzvQ8e4=; b=YOscLXrVvrxoqYxh7CIsIDXZBHn/L1RTH3YHftgKGfOh8KxsWrXTX20jheOm7VZOYO W0cKes5SAnfCvt64N2o1GbMRfa0LLJf1cBdGi7fPXzeUx/7T0llUCcVGWTknj/gfwwvV ZT5zY59bBwCld/ZcvaMK2JwUyPoR9Hvf8Jb7xqtJ3QX4OStqq9CwnYNEHWYrZErTcov9 a2DjOwnaaRPkuDPGZStcRfUdXFZrIfLjoWcbAvZGO9x9Uu2OgEzzBDL0ME7PdcMjQilA tsfFGGe609nj6aL28/ySfcONW2FU39F1wVg9DBvrRbODGRiOXBJG6micAJjub3lqu68A QMQQ== 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=7qvkw2rh1v07dKjdJW16zWvEdglTDlF1uoylnzvQ8e4=; b=HQqeqZbd/EG3bjcvcaexKhYyWgD2qWtecExWuzTunowFq+NQahzTejZK7vUF+Y1kML NIC75kcsI1fj2UcGVIKDlicjRYBCmVELPErcOJX2GylmtCGTysopBW0iKFO3N85xz+X8 uu1Lz9cvCbORsqPiIliQvz4nrpo06mlGfcmGsk7AGobZq2NzD9ykOOnU6I42oS3F1EZG jl8cpfnOW9RAt/QqME7EOB03gc8jzjUUVA/sfCqgGM1dYWdWj+2gGySOfwrhXp+CmQCO GhAB8vqbRg6rm8r2z++cCyJpE1Jcj5zVbrPwePW5KjViHPeIrEKGqbtL6mQUeDMJ53B2 v19A== X-Gm-Message-State: AOAM530qB2ciHQbih1Sjg21AW2QR4mv0Yzo0SVEGd3C0IaayPhhFtE+X aY6+dzeiRbfOSW+6AH+yuTNpiWNJx2FTrg== X-Google-Smtp-Source: ABdhPJw92MiI2lu9zGu0cE66M6xXMBs+rHGMGx6CZ3DNzyoOwyCW4GXn+iO0QFHr1uJKZtvvsv+G4g== X-Received: by 2002:adf:f9cb:: with SMTP id w11mr3805812wrr.382.1630588323742; Thu, 02 Sep 2021 06:12:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 20/36] run-command: remove old run_hook_{le,ve}() hook API Date: Thu, 2 Sep 2021 15:11:20 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer The new hook.h library has replaced all run-command.h hook-related functionality. So let's delete this dead code. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- run-command.c | 32 -------------------------------- run-command.h | 16 ---------------- 2 files changed, 48 deletions(-) diff --git a/run-command.c b/run-command.c index b4341ba1c7b..1399243de8a 100644 --- a/run-command.c +++ b/run-command.c @@ -1320,38 +1320,6 @@ int async_with_fork(void) #endif } -static int run_hook_ve(const char *const *env, const char *name, va_list args) -{ - struct child_process hook = CHILD_PROCESS_INIT; - const char *p; - - p = find_hook(name); - if (!p) - return 0; - - strvec_push(&hook.args, p); - while ((p = va_arg(args, const char *))) - strvec_push(&hook.args, p); - hook.env = env; - hook.no_stdin = 1; - hook.stdout_to_stderr = 1; - hook.trace2_hook_name = name; - - return run_command(&hook); -} - -int run_hook_le(const char *const *env, const char *name, ...) -{ - va_list args; - int ret; - - va_start(args, name); - ret = run_hook_ve(env, name, args); - va_end(args); - - return ret; -} - struct io_pump { /* initialized by caller */ int fd; diff --git a/run-command.h b/run-command.h index 7a867d41217..cfb6887e4ae 100644 --- a/run-command.h +++ b/run-command.h @@ -204,22 +204,6 @@ int finish_command_in_signal(struct child_process *); */ int run_command(struct child_process *); -/** - * Run a hook. - * The first argument is a pathname to an index file, or NULL - * if the hook uses the default index file or no index is needed. - * The second argument is the name of the hook. - * The further arguments correspond to the hook arguments. - * The last argument has to be NULL to terminate the arguments list. - * If the hook does not exist or is not executable, the return - * value will be zero. - * If it is executable, the hook will be executed and the exit - * status of the hook is returned. - * On execution, .stdout_to_stderr and .no_stdin will be set. - */ -LAST_ARG_MUST_BE_NULL -int run_hook_le(const char *const *env, const char *name, ...); - /* * Trigger an auto-gc */ From patchwork Thu Sep 2 13:11:21 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: 12471631 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 EAFA8C432BE for ; Thu, 2 Sep 2021 13:12:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D667D610A0 for ; Thu, 2 Sep 2021 13:12:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345157AbhIBNNr (ORCPT ); Thu, 2 Sep 2021 09:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345116AbhIBNNP (ORCPT ); Thu, 2 Sep 2021 09:13:15 -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 C1669C061764 for ; Thu, 2 Sep 2021 06:12:06 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id n5so2832713wro.12 for ; Thu, 02 Sep 2021 06:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OnSrfzXP7u8eONAF7Ui2nz6Z6wCNrBu3vN14jd+MMt8=; b=dpvVcUA81jw6JOYbKd69HQizPU1ON6pwmxp9VreCnoVDcN6VbSRFlCMa1sEDDucv+I mABUX5Z5JIfbyc59bHW3CkpxN1V6f1lNKM2ss+SFqA/EJv8DZHwvTo8dshPcGGSJ41IX dPBr0ghfM/H/rUDW5AhWZRjDRfCIc5iMyYFoeo6tMa3UHf44WIIcmmcB5q0C9535NU5P qo1OzaOztxEHaiVJN4fVvP/gOdotqIn1pe0nPblUA/3ImMjSoYQXeiDkTYxVffRAryvp xufNTZRf/e58g2NFEQT9XlPOFTrAZI7h+UGdfMHWzM5q9wImt3mZA3+KyYQemZGV9u/n WaAw== 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=OnSrfzXP7u8eONAF7Ui2nz6Z6wCNrBu3vN14jd+MMt8=; b=B/TmRGnA550jJLcNg+Vc7RXU/0JQYdKU3ItOVuUmr5iKFcJH6Y/L6AzZ75Z5PIoFNr f1WFZieizFRAPEy8YNytfacb4GaIyIGlp3pwACFxSvMhhCcOpR3AivoUC/TUScOAHtyx l8tv9VPoQw1opbNDqzp4I9xeduJ775j/JA2PvoV4mw5Wh7f7ibp66EFt8HKdeI3uIwVJ /gaURlDE6A1owyDw8yuCouZ2OMSRzmbFQflR7OGVM+vSpabzSKw+DRNgsVFFw1vpRNut mJYs0HIN2dHehizsWJPNiEwalc4tIXlle6ou35LalFOHeKFqLyjUKG45lPYUYGZrNn/x YpUA== X-Gm-Message-State: AOAM530VUJmoRYd0KtmKgHN7xVRr2n/H4h3kyBkThKKavgjNAUwVJODu 0foFWIp8FPfpIFiEniWNoSlE3CwYH2+NtQ== X-Google-Smtp-Source: ABdhPJzWXFC0xXqMG/0umT0veWH6HV6wP63jIRs2eWGFOn4Z52+onM/SUKwLdpWYoLX2Iz02qp9mYA== X-Received: by 2002:a5d:6cb0:: with SMTP id a16mr3694670wra.245.1630588325112; Thu, 02 Sep 2021 06:12:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:04 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 21/36] run-command: allow stdin for run_processes_parallel Date: Thu, 2 Sep 2021 15:11:21 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer While it makes sense not to inherit stdin from the parent process to avoid deadlocking, it's not necessary to completely ban stdin to children. An informed user should be able to configure stdin safely. By setting `some_child.process.no_stdin=1` before calling `get_next_task()` we provide a reasonable default behavior but enable users to set up stdin streaming for themselves during the callback. `some_child.process.stdout_to_stderr`, however, remains unmodifiable by `get_next_task()` - the rest of the run_processes_parallel() API depends on child output in stderr. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- run-command.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/run-command.c b/run-command.c index 1399243de8a..482ee2d76c6 100644 --- a/run-command.c +++ b/run-command.c @@ -1627,6 +1627,14 @@ static int pp_start_one(struct parallel_processes *pp) if (i == pp->max_processes) BUG("bookkeeping is hard"); + /* + * By default, do not inherit stdin from the parent process - otherwise, + * all children would share stdin! Users may overwrite this to provide + * something to the child's stdin by having their 'get_next_task' + * callback assign 0 to .no_stdin and an appropriate integer to .in. + */ + pp->children[i].process.no_stdin = 1; + code = pp->get_next_task(&pp->children[i].process, &pp->children[i].err, pp->data, @@ -1638,7 +1646,6 @@ static int pp_start_one(struct parallel_processes *pp) } pp->children[i].process.err = -1; pp->children[i].process.stdout_to_stderr = 1; - pp->children[i].process.no_stdin = 1; if (start_command(&pp->children[i].process)) { code = pp->start_failure(&pp->children[i].err, From patchwork Thu Sep 2 13:11:22 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: 12471633 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 B31ECC4320E for ; Thu, 2 Sep 2021 13:12:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A9C26108E for ; Thu, 2 Sep 2021 13:12:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345055AbhIBNNu (ORCPT ); Thu, 2 Sep 2021 09:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345187AbhIBNNg (ORCPT ); Thu, 2 Sep 2021 09:13:36 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06B1EC06122F for ; Thu, 2 Sep 2021 06:12:08 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id u26-20020a05600c441a00b002f66b2d8603so1406019wmn.4 for ; Thu, 02 Sep 2021 06:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=umhyauEdB2R62gDQ8HSg3xeXESPuOWe9JF+PMQM5mec=; b=Q5i6eifVhY7EMZ16wOGMTKyQPjzCPW7OXJy9FL0HXfHKgF70eX/Z7fBxf+iA37s7NR NdTSmVSn6qL78BUA0GnNClt/JxzEUIa6GUoUcEvt5FGypGHjrj+4Pe3wn0wlSY9i+GI5 T8cET6rZg0pINvM3EwiCpXwaZMbphtrhhrl4L6opqbb17ebKdqq7nk3rXWjqvOsL7HbW GgMDxIHf+1XLht59RB3fVngpQZmmfZlKKGtOxMSFMr/7BGJWv9N/Q4hckTdV9mK6o1YK t46GXCVOpQYU4KKDTGvlTgUDbojHYJan4n7pR4hfFom/+8GTDXv7hiNt3v/P0leL0tdz AcbQ== 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=umhyauEdB2R62gDQ8HSg3xeXESPuOWe9JF+PMQM5mec=; b=frnl0dxyRg4pW2aHa6yRkir5q16M6ChdeBI3A/Z+g32IdZSBl3RYfd5QoYyE6pwNrG Qy2ExsMGNfvDRFL7i4nuTx1uNrM4GDd2SlLhy9IEVDc2k11a2F5CXaluMvCoPvMB3iCZ wSc0WZs3z8Y0LOF2A/U41DR+ax8XGe7/mo+Iy/Usjw/OJQ8J+V5BuM3HcEOSoS32QNax 5sQXZma6PF+PV3gIy+uf5BnbxjFaPFlPSI42qYUL2oVoPPoBqiOhgFyonTq0SQzS0RzH uD5yaiAd+6cJy3nt+gShn+jb6HuPIAuVdzpiYHEw+5EK01vvP2Ei0YfUD0T/hLJxgB7Q z4CQ== X-Gm-Message-State: AOAM531G3Bo11I8ujbeJVqBBzy23dSSarrmbQ3v9qbHYA38/LAFl0do1 wA+XPq9Nw0NVpNy3N3egI0FDqkk/yG2i+Q== X-Google-Smtp-Source: ABdhPJw312t8R0i6vH5EkYRuXzOMIAR84yreGVaNpiBgPVP4md50gCOHhIehAHirfMIAtwpN1zGFVg== X-Received: by 2002:a7b:cb8c:: with SMTP id m12mr3133675wmi.77.1630588326236; Thu, 02 Sep 2021 06:12:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 22/36] hook: support passing stdin to hooks Date: Thu, 2 Sep 2021 15:11:22 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Some hooks (such as post-rewrite) need to take input via stdin. Previously, callers provided stdin to hooks by setting run-command.h:child_process.in, which takes a FD. Callers would open the file in question themselves before calling run-command(). However, since we will now need to seek to the front of the file and read it again for every hook which runs, hook.h:run_command() takes a path and handles FD management itself. Since this file is opened for read only, it should not prevent later parallel execution support. On the frontend, this is supported by asking for a file path, rather than by reading stdin. Reading directly from stdin would involve caching the entire stdin (to memory or to disk) and reading it back from the beginning to each hook. We'd want to support cases like insufficient memory or storage for the file. While this may prove useful later, for now the path of least resistance is to just ask the user to make this interim file themselves. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-hook.txt | 7 ++++++- builtin/hook.c | 4 +++- hook.c | 8 +++++++- hook.h | 3 +++ t/t1800-hook.sh | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt index 097fb9de63b..fa68c1f3912 100644 --- a/Documentation/git-hook.txt +++ b/Documentation/git-hook.txt @@ -8,7 +8,7 @@ git-hook - run git hooks SYNOPSIS -------- [verse] -'git hook' run [--ignore-missing] [-- ] +'git hook' run [--to-stdin=] [--ignore-missing] [-- ] DESCRIPTION ----------- @@ -32,6 +32,11 @@ what those are. OPTIONS ------- +--to-stdin:: + For "run"; Specify a file which will be streamed into the + hook's stdin. The hook will receive the entire file from + beginning to EOF. + --ignore-missing:: Ignore any missing hook by quietly returning zero. Used for tools that want to do a blind one-shot run of a hook that may diff --git a/builtin/hook.c b/builtin/hook.c index 76d49e672f4..fae69068201 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -7,7 +7,7 @@ #include "strvec.h" #define BUILTIN_HOOK_RUN_USAGE \ - N_("git hook run [--ignore-missing] [-- ]") + N_("git hook run [--ignore-missing] [--to-stdin=] [-- ]") static const char * const builtin_hook_usage[] = { BUILTIN_HOOK_RUN_USAGE, @@ -29,6 +29,8 @@ static int run(int argc, const char **argv, const char *prefix) struct option run_options[] = { OPT_BOOL(0, "ignore-missing", &ignore_missing, N_("exit quietly with a zero exit code if the requested hook cannot be found")), + OPT_STRING(0, "to-stdin", &opt.path_to_stdin, N_("path"), + N_("file to read into hooks' stdin")), OPT_END(), }; int ret; diff --git a/hook.c b/hook.c index 8a923e52c1b..d156b0dc800 100644 --- a/hook.c +++ b/hook.c @@ -59,7 +59,13 @@ static int pick_next_hook(struct child_process *cp, if (!run_me) return 0; - cp->no_stdin = 1; + /* reopen the file for stdin; run_command closes it. */ + if (hook_cb->options->path_to_stdin) { + cp->no_stdin = 0; + cp->in = xopen(hook_cb->options->path_to_stdin, O_RDONLY); + } else { + cp->no_stdin = 1; + } cp->env = hook_cb->options->env.v; cp->stdout_to_stderr = 1; cp->trace2_hook_name = hook_cb->hook_name; diff --git a/hook.h b/hook.h index 3edd937e198..253725e197b 100644 --- a/hook.h +++ b/hook.h @@ -23,6 +23,9 @@ struct run_hooks_opt /* Path to initial working directory for subprocess */ const char *dir; + + /* Path to file which should be piped to stdin for each hook */ + const char *path_to_stdin; }; #define RUN_HOOKS_OPT_INIT { \ diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index feb95b8fc8d..6431b19e392 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -130,4 +130,22 @@ test_expect_success 'git -c core.hooksPath= hook run' ' test_cmp expect actual ' +test_expect_success 'stdin to hooks' ' + write_script .git/hooks/test-hook <<-\EOF && + echo BEGIN stdin + cat + echo END stdin + EOF + + cat >expect <<-EOF && + BEGIN stdin + hello + END stdin + EOF + + echo hello >input && + git hook run --to-stdin=input test-hook 2>actual && + test_cmp expect actual +' + test_done From patchwork Thu Sep 2 13:11:23 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: 12471635 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 512CCC432BE for ; Thu, 2 Sep 2021 13:12:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AD57610E5 for ; Thu, 2 Sep 2021 13:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345006AbhIBNNv (ORCPT ); Thu, 2 Sep 2021 09:13:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345140AbhIBNNh (ORCPT ); Thu, 2 Sep 2021 09:13:37 -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 B81E6C061292 for ; Thu, 2 Sep 2021 06:12:09 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id m9so2881665wrb.1 for ; Thu, 02 Sep 2021 06:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WbBEgRoVviqwmYntD7MhzCT8yKMCfzYqqmViRdFsBWk=; b=bUWlhnEuVYMtFxcBC1HRyxr04LKUtH7pGDA19XOq9cQ25idKZgQkgfJ/Hyv3bc1+cI 3iiM/UFaYZgKjKmg1tq7QsEc0yipxuSymFWdD91aMJEDa1Hr34mxkCXVmfZ3B9v9D8qY OKSsAfNT+EvYI61dvKnGKfLXkYyZDtu9EhZ9H/ethvfJjqlOcJGNvJEMSJZlsDDuvK0o HqxB+iONdACaMeqQTvsPg9cEUngXeO/+HU8vrV8H3EA+3AB07Z4sVFlY2o3dC+0ZNbiQ STK1WezKwp5J5KbCEdRWOiG2GzFYF6r/pSKzNZvIixkW68+5+DIvZeeETDrOn3VFd/aT /N6w== 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=WbBEgRoVviqwmYntD7MhzCT8yKMCfzYqqmViRdFsBWk=; b=EgXhAUMhAo2cdRHV5eH8P7o3CKDboqryo5F6CGbB9I2ePWh1Zs29WLY2y8La57Ne/e f0nABxFZpe2qFzX2y+HJGvKf/RB4arJtvdWQbPUJZgLzn4TC60HBNnNbsgnfJb29BUHQ yWnEWYLdZhQzLgaujux7XF7I9wHouGIXlfuNolzjLbTl4MgOIejRqncL0C9kGhkMe+bz itRojCu8gC3v3tfwBEwVRYwJWe7EJHkfmk4rGBJeABran0QrtWXP4JQb+5aDy8DWBTyk l536pxRThT4ZZphsI5Rlkn4GJgzO1+BWOf9gI3fPYZ/aHRfIgNSJfby8TOcooVet6JQj GRAA== X-Gm-Message-State: AOAM533pcib5/CY97RM+HwAh4ofvzfUVUTl6HrkK3p2B0EaciBGIgTfR /AuvVv/fHNhUIQC0kFk2JkIHBKcAT44qsA== X-Google-Smtp-Source: ABdhPJzMeGgTvQU7mwdXCQSJEArhaLxhG0LM+lb7sdE55tb0pECM5HSwIwLiEW/MraesZS19aWku1g== X-Received: by 2002:adf:c184:: with SMTP id x4mr3780159wre.266.1630588327480; Thu, 02 Sep 2021 06:12:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 23/36] am: convert 'post-rewrite' hook to hook.h Date: Thu, 2 Sep 2021 15:11:23 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index e444b18b64a..9e3d4d9ab44 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -467,24 +467,12 @@ static int run_applypatch_msg_hook(struct am_state *state) */ static int run_post_rewrite_hook(const struct am_state *state) { - struct child_process cp = CHILD_PROCESS_INIT; - const char *hook = find_hook("post-rewrite"); - int ret; - - if (!hook) - return 0; - - strvec_push(&cp.args, hook); - strvec_push(&cp.args, "rebase"); - - cp.in = xopen(am_path(state, "rewritten"), O_RDONLY); - cp.stdout_to_stderr = 1; - cp.trace2_hook_name = "post-rewrite"; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; - ret = run_command(&cp); + strvec_push(&opt.args, "rebase"); + opt.path_to_stdin = am_path(state, "rewritten"); - close(cp.in); - return ret; + return run_hooks_oneshot("post-rewrite", &opt); } /** From patchwork Thu Sep 2 13:11:24 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: 12471637 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 6CDC4C432BE for ; Thu, 2 Sep 2021 13:12:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5423D6108E for ; Thu, 2 Sep 2021 13:12:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345223AbhIBNNw (ORCPT ); Thu, 2 Sep 2021 09:13:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345145AbhIBNNn (ORCPT ); Thu, 2 Sep 2021 09:13:43 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF54C0612A4 for ; Thu, 2 Sep 2021 06:12:11 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id v10so2855693wrd.4 for ; Thu, 02 Sep 2021 06:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h1n2lBVFFvzwmpKaHJ/cBboK1g18RxJd1kUSpIHdmDU=; b=aMCheC508S0q67XG8siBXMj8qgtsyJcBOXORMxne0LxOnoKU+hJo0CcTOe9Uv0mdkk a7ZirKFCRs6EKS4KfEO6aBTFwm0nWqFPBHhNX+ifkGMRSPqCwN8UHEEhhXwNwZyBCCAd 1OaF8ES/GVLzoORqVXLtMoHMlv76gLRPss9PbLshstxIEeD3DwogDus0s4U/Ra+xnWUf 5Epc2ObhBapRq0gnkjwjauA1Z8WjR67DEVYBw+17M8ZOJ0uJSkD0P+hIEKNezbHm4IDK K6fBVAhG78+xC+Uf4Ps4oM2PTq3e4W3mBArXGyOFBRQLeLbz4ElVpQ3rsEvVcFySKU+G bavQ== 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=h1n2lBVFFvzwmpKaHJ/cBboK1g18RxJd1kUSpIHdmDU=; b=CbDQZYHb0M9LgG7rhP+I3GYo37hzTBNseCtisFph8ZlegepRtc6bJJk/Rc3OYf3Qpl N6jHMrzQBW9ww7DL4Ph6gm/e/ngfuwvOWCLG5nHGslExKOyU6VSVsiXCpJ+Z9K+IL/WF ghQ8J9iLPFAnC4MqAgpjlzatSkH9GdTzdenh2YAK+0SU7uHnIdSnvl8ej24dNdFpgZF0 SrP4DoEPPt2M9hnlSSr/+PoxlJVT0Uo7hNZ1oKL+ZARDVJKBVxbE1p5SxPn6RRd22WN3 NhyJkQowCLxi/vIdIQ9sEzeM5DB+XRN+kP2z8Hpb6PmioabUYNkOKECOXQ4UrAcL1mPW YpCg== X-Gm-Message-State: AOAM532lw34FLfn7bO7EInGfpuALP0EjDwdf6nCDHbGTIjCfbSknyMyA r9gOb2jdg/H4J63YH8gjOdD385wT2bLMRA== X-Google-Smtp-Source: ABdhPJxXiJlPzXee0M7NfNJTap/Upfc8+54mdj8sEtEQRenApUfLq+JjnRrjViw4fq2vJVJorxl7YQ== X-Received: by 2002:a5d:6286:: with SMTP id k6mr3586159wru.103.1630588329285; Thu, 02 Sep 2021 06:12:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:08 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 24/36] run-command: add stdin callback for parallelization Date: Thu, 2 Sep 2021 15:11:24 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer If a user of the run_processes_parallel() API wants to pipe a large amount of information to stdin of each parallel command, that information could exceed the buffer of the pipe allocated for that process's stdin. Generally this is solved by repeatedly writing to child_process.in between calls to start_command() and finish_command(); run_processes_parallel() did not provide users an opportunity to access child_process at that time. Because the data might be extremely large (for example, a list of all refs received during a push from a client) simply taking a string_list or strbuf is not as scalable as using a callback; the rest of the run_processes_parallel() API also uses callbacks, so making this feature match the rest of the API reduces mental load on the user. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fetch.c | 1 + builtin/submodule--helper.c | 2 +- hook.c | 1 + run-command.c | 54 +++++++++++++++++++++++++++++++++++-- run-command.h | 17 +++++++++++- submodule.c | 1 + t/helper/test-run-command.c | 31 ++++++++++++++++++--- t/t0061-run-command.sh | 30 +++++++++++++++++++++ 8 files changed, 129 insertions(+), 8 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index e064687dbdc..b18ada08842 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1819,6 +1819,7 @@ static int fetch_multiple(struct string_list *list, int max_children) result = run_processes_parallel_tr2(max_children, &fetch_next_remote, &fetch_failed_to_start, + NULL, &fetch_finished, &state, "fetch", "parallel/fetch"); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ef2776a9e45..0b73739c160 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2311,7 +2311,7 @@ static int update_submodules(struct submodule_update_clone *suc) int i; run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, - update_clone_start_failure, + update_clone_start_failure, NULL, update_clone_task_finished, suc, "submodule", "parallel/update"); diff --git a/hook.c b/hook.c index d156b0dc800..45983d08aed 100644 --- a/hook.c +++ b/hook.c @@ -146,6 +146,7 @@ int run_hooks(const char *hook_name, const char *hook_path, run_processes_parallel_tr2(jobs, pick_next_hook, notify_start_failure, + NULL, notify_hook_finished, &cb_data, "hook", diff --git a/run-command.c b/run-command.c index 482ee2d76c6..f1616858d18 100644 --- a/run-command.c +++ b/run-command.c @@ -1492,6 +1492,7 @@ struct parallel_processes { get_next_task_fn get_next_task; start_failure_fn start_failure; + feed_pipe_fn feed_pipe; task_finished_fn task_finished; struct { @@ -1519,6 +1520,13 @@ static int default_start_failure(struct strbuf *out, return 0; } +static int default_feed_pipe(struct strbuf *pipe, + void *pp_cb, + void *pp_task_cb) +{ + return 1; +} + static int default_task_finished(int result, struct strbuf *out, void *pp_cb, @@ -1549,6 +1557,7 @@ static void pp_init(struct parallel_processes *pp, int n, get_next_task_fn get_next_task, start_failure_fn start_failure, + feed_pipe_fn feed_pipe, task_finished_fn task_finished, void *data) { @@ -1567,6 +1576,7 @@ static void pp_init(struct parallel_processes *pp, pp->get_next_task = get_next_task; pp->start_failure = start_failure ? start_failure : default_start_failure; + pp->feed_pipe = feed_pipe ? feed_pipe : default_feed_pipe; pp->task_finished = task_finished ? task_finished : default_task_finished; pp->nr_processes = 0; @@ -1664,6 +1674,37 @@ static int pp_start_one(struct parallel_processes *pp) return 0; } +static void pp_buffer_stdin(struct parallel_processes *pp) +{ + int i; + struct strbuf sb = STRBUF_INIT; + + /* Buffer stdin for each pipe. */ + for (i = 0; i < pp->max_processes; i++) { + if (pp->children[i].state == GIT_CP_WORKING && + pp->children[i].process.in > 0) { + int done; + strbuf_reset(&sb); + done = pp->feed_pipe(&sb, pp->data, + pp->children[i].data); + if (sb.len) { + if (write_in_full(pp->children[i].process.in, + sb.buf, sb.len) < 0) { + if (errno != EPIPE) + die_errno("write"); + done = 1; + } + } + if (done) { + close(pp->children[i].process.in); + pp->children[i].process.in = 0; + } + } + } + + strbuf_release(&sb); +} + static void pp_buffer_stderr(struct parallel_processes *pp, int output_timeout) { int i; @@ -1728,6 +1769,7 @@ static int pp_collect_finished(struct parallel_processes *pp) pp->nr_processes--; pp->children[i].state = GIT_CP_FREE; pp->pfd[i].fd = -1; + pp->children[i].process.in = 0; child_process_init(&pp->children[i].process); if (i != pp->output_owner) { @@ -1761,6 +1803,7 @@ static int pp_collect_finished(struct parallel_processes *pp) int run_processes_parallel(int n, get_next_task_fn get_next_task, start_failure_fn start_failure, + feed_pipe_fn feed_pipe, task_finished_fn task_finished, void *pp_cb) { @@ -1769,7 +1812,9 @@ int run_processes_parallel(int n, int spawn_cap = 4; struct parallel_processes pp; - pp_init(&pp, n, get_next_task, start_failure, task_finished, pp_cb); + sigchain_push(SIGPIPE, SIG_IGN); + + pp_init(&pp, n, get_next_task, start_failure, feed_pipe, task_finished, pp_cb); while (1) { for (i = 0; i < spawn_cap && !pp.shutdown && @@ -1786,6 +1831,7 @@ int run_processes_parallel(int n, } if (!pp.nr_processes) break; + pp_buffer_stdin(&pp); pp_buffer_stderr(&pp, output_timeout); pp_output(&pp); code = pp_collect_finished(&pp); @@ -1797,11 +1843,15 @@ int run_processes_parallel(int n, } pp_cleanup(&pp); + + sigchain_pop(SIGPIPE); + return 0; } int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task, start_failure_fn start_failure, + feed_pipe_fn feed_pipe, task_finished_fn task_finished, void *pp_cb, const char *tr2_category, const char *tr2_label) { @@ -1811,7 +1861,7 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task, ((n < 1) ? online_cpus() : n)); result = run_processes_parallel(n, get_next_task, start_failure, - task_finished, pp_cb); + feed_pipe, task_finished, pp_cb); trace2_region_leave(tr2_category, tr2_label, NULL); diff --git a/run-command.h b/run-command.h index cfb6887e4ae..80d394664ae 100644 --- a/run-command.h +++ b/run-command.h @@ -422,6 +422,20 @@ typedef int (*start_failure_fn)(struct strbuf *out, void *pp_cb, void *pp_task_cb); +/** + * This callback is called repeatedly on every child process who requests + * start_command() to create a pipe by setting child_process.in < 0. + * + * pp_cb is the callback cookie as passed into run_processes_parallel, and + * pp_task_cb is the callback cookie as passed into get_next_task_fn. + * The contents of 'send' will be read into the pipe and passed to the pipe. + * + * Return nonzero to close the pipe. + */ +typedef int (*feed_pipe_fn)(struct strbuf *pipe, + void *pp_cb, + void *pp_task_cb); + /** * This callback is called on every child process that finished processing. * @@ -456,10 +470,11 @@ typedef int (*task_finished_fn)(int result, int run_processes_parallel(int n, get_next_task_fn, start_failure_fn, + feed_pipe_fn, task_finished_fn, void *pp_cb); int run_processes_parallel_tr2(int n, get_next_task_fn, start_failure_fn, - task_finished_fn, void *pp_cb, + feed_pipe_fn, task_finished_fn, void *pp_cb, const char *tr2_category, const char *tr2_label); /** diff --git a/submodule.c b/submodule.c index 8e611fe1dbf..db1700a502d 100644 --- a/submodule.c +++ b/submodule.c @@ -1632,6 +1632,7 @@ int fetch_populated_submodules(struct repository *r, run_processes_parallel_tr2(max_parallel_jobs, get_next_submodule, fetch_start_failure, + NULL, fetch_finish, &spf, "submodule", "parallel/fetch"); diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 7ae03dc7123..9348184d303 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -32,8 +32,13 @@ static int parallel_next(struct child_process *cp, return 0; strvec_pushv(&cp->args, d->argv); + cp->in = d->in; + cp->no_stdin = d->no_stdin; strbuf_addstr(err, "preloaded output of a child\n"); number_callbacks++; + + *task_cb = xmalloc(sizeof(int)); + *(int*)(*task_cb) = 2; return 1; } @@ -55,6 +60,17 @@ static int task_finished(int result, return 1; } +static int test_stdin(struct strbuf *pipe, void *cb, void *task_cb) +{ + int *lines_remaining = task_cb; + + if (*lines_remaining) + strbuf_addf(pipe, "sample stdin %d\n", --(*lines_remaining)); + + return !(*lines_remaining); +} + + struct testsuite { struct string_list tests, failed; int next; @@ -185,7 +201,7 @@ static int testsuite(int argc, const char **argv) suite.tests.nr, max_jobs); ret = run_processes_parallel(max_jobs, next_test, test_failed, - test_finished, &suite); + test_stdin, test_finished, &suite); if (suite.failed.nr > 0) { ret = 1; @@ -413,15 +429,22 @@ int cmd__run_command(int argc, const char **argv) if (!strcmp(argv[1], "run-command-parallel")) exit(run_processes_parallel(jobs, parallel_next, - NULL, NULL, &proc)); + NULL, NULL, NULL, &proc)); if (!strcmp(argv[1], "run-command-abort")) exit(run_processes_parallel(jobs, parallel_next, - NULL, task_finished, &proc)); + NULL, NULL, task_finished, &proc)); if (!strcmp(argv[1], "run-command-no-jobs")) exit(run_processes_parallel(jobs, no_job, - NULL, task_finished, &proc)); + NULL, NULL, task_finished, &proc)); + + if (!strcmp(argv[1], "run-command-stdin")) { + proc.in = -1; + proc.no_stdin = 0; + exit (run_processes_parallel(jobs, parallel_next, NULL, + test_stdin, NULL, &proc)); + } fprintf(stderr, "check usage\n"); return 1; diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh index 7d599675e35..87759482ad1 100755 --- a/t/t0061-run-command.sh +++ b/t/t0061-run-command.sh @@ -143,6 +143,36 @@ test_expect_success 'run_command runs in parallel with more tasks than jobs avai test_cmp expect actual ' +cat >expect <<-EOF +preloaded output of a child +listening for stdin: +sample stdin 1 +sample stdin 0 +preloaded output of a child +listening for stdin: +sample stdin 1 +sample stdin 0 +preloaded output of a child +listening for stdin: +sample stdin 1 +sample stdin 0 +preloaded output of a child +listening for stdin: +sample stdin 1 +sample stdin 0 +EOF + +test_expect_success 'run_command listens to stdin' ' + write_script stdin-script <<-\EOF && + echo "listening for stdin:" + while read line; do + echo "$line" + done + EOF + test-tool run-command run-command-stdin 2 ./stdin-script 2>actual && + test_cmp expect actual +' + cat >expect <<-EOF preloaded output of a child asking for a quick stop From patchwork Thu Sep 2 13:11:25 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: 12471639 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 9590BC4320E for ; Thu, 2 Sep 2021 13:12:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CC536108E for ; Thu, 2 Sep 2021 13:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345242AbhIBNNy (ORCPT ); Thu, 2 Sep 2021 09:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345202AbhIBNNn (ORCPT ); Thu, 2 Sep 2021 09:13:43 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29297C0611C1 for ; Thu, 2 Sep 2021 06:12:12 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id u15-20020a05600c19cf00b002f6445b8f55so1358316wmq.0 for ; Thu, 02 Sep 2021 06:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KWG5vXKfLP8KTYdKLFxVfjCBoaVIl1IIARXbcD3D/Tc=; b=HDc8Cb7HqX913ki9N4Gnztk819FeeIoqmGLTy3cn1XtbxEiPNqms9Gzk4U74x504L8 rhzqgstd6h1Y1lG/q1JacI46NBtwpFkmsN/CPxXlvfZkf2qeLrdQLuq0KuYdehOTFmiF yPzRu+dF3dGBxViORq6r8k08reLI6VKHeFv0bVj6aUpDQHWNVgXOHYKEfPk+749Ses7J zcv8z8N13UplhjnecLHl37Kp+jIzEfyxgx+zKUmmrOT0GZJL9cDvz8oNjyhY4r2pa39t RPl5zpvxXxfQK+Dlc/A26b618ysgcvcju6CH/ysQTc55p/5MvjlWrMZBzYi9qOf5+8ns VDIg== 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=KWG5vXKfLP8KTYdKLFxVfjCBoaVIl1IIARXbcD3D/Tc=; b=n62erbz9VFSBQz21dmUXLBYwXM0K6Zltabo9l+okbn4ef42CcULM8SF8ggWfUQ9zxM YJJKZt9zDt8V5i3GMvKacytiPZkAC5ozkV4hse/dLlxV7hWWqKE3LunqGvr1/ofk885d /Q1E3yLJ0JczD8h7ZbnPvEYy94P7ZrvJgkuTzdAW1syyn3d7hTow/4wzj1q1jXbBSEic bzd/NWk9WUjo30V0Ssj1OsGcIEQhofo0IFU7arSdve1RgYtacxRT/fVAyh379gUd1krP BqI6XHmoWtmKsKwcEac8F6C1r7Ugq45rvCL/SDbAuLsEb1iDmyX/PtE+z5kZy/bVQiq/ mogQ== X-Gm-Message-State: AOAM532u0FsccI5KEezmqVHyOVe0NNC3hJbQGoAfccn6W7N1BycThafm 7HwAs8cAstwRmEhAF5O6BviMJ84/Wyaq+w== X-Google-Smtp-Source: ABdhPJwDxYhlbF/G1elJPoyiiJPWICw1TR9PpSv9wpHRwPQVoQD+o72I59jmggAgk7sGaIJjD11x4A== X-Received: by 2002:a05:600c:298:: with SMTP id 24mr3030540wmk.172.1630588330467; Thu, 02 Sep 2021 06:12:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:09 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 25/36] hook: provide stdin by string_list or callback Date: Thu, 2 Sep 2021 15:11:25 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer In cases where a hook requires only a small amount of information via stdin, it should be simple for users to provide a string_list alone. But in more complicated cases where the stdin is too large to hold in memory, let's instead provide a callback the users can populate line after line. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- hook.c | 33 ++++++++++++++++++++++++++++++++- hook.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/hook.c b/hook.c index 45983d08aed..7a6ef527443 100644 --- a/hook.c +++ b/hook.c @@ -48,6 +48,29 @@ void run_hooks_opt_clear(struct run_hooks_opt *o) strvec_clear(&o->args); } +int pipe_from_string_list(struct strbuf *pipe, void *pp_cb, void *pp_task_cb) +{ + int *item_idx; + struct hook *ctx = pp_task_cb; + struct hook_cb_data *hook_cb = pp_cb; + struct string_list *to_pipe = hook_cb->options->feed_pipe_ctx; + + /* Bootstrap the state manager if necessary. */ + if (!ctx->feed_pipe_cb_data) { + ctx->feed_pipe_cb_data = xmalloc(sizeof(unsigned int)); + *(int*)ctx->feed_pipe_cb_data = 0; + } + + item_idx = ctx->feed_pipe_cb_data; + + if (*item_idx < to_pipe->nr) { + strbuf_addf(pipe, "%s\n", to_pipe->items[*item_idx].string); + (*item_idx)++; + return 0; + } + return 1; +} + static int pick_next_hook(struct child_process *cp, struct strbuf *out, void *pp_cb, @@ -63,6 +86,10 @@ static int pick_next_hook(struct child_process *cp, if (hook_cb->options->path_to_stdin) { cp->no_stdin = 0; cp->in = xopen(hook_cb->options->path_to_stdin, O_RDONLY); + } else if (hook_cb->options->feed_pipe) { + /* ask for start_command() to make a pipe for us */ + cp->in = -1; + cp->no_stdin = 0; } else { cp->no_stdin = 1; } @@ -146,7 +173,7 @@ int run_hooks(const char *hook_name, const char *hook_path, run_processes_parallel_tr2(jobs, pick_next_hook, notify_start_failure, - NULL, + options->feed_pipe, notify_hook_finished, &cb_data, "hook", @@ -154,6 +181,7 @@ int run_hooks(const char *hook_name, const char *hook_path, if (options->absolute_path) strbuf_release(&abs_path); + free(my_hook.feed_pipe_cb_data); return cb_data.rc; } @@ -167,6 +195,9 @@ int run_hooks_oneshot(const char *hook_name, struct run_hooks_opt *options) if (!options) options = &hook_opt_scratch; + if (options->path_to_stdin && options->feed_pipe) + BUG("choose only one method to populate stdin"); + hook_path = find_hook(hook_name); if (!hook_path) { ret = 0; diff --git a/hook.h b/hook.h index 253725e197b..4e26b8d658d 100644 --- a/hook.h +++ b/hook.h @@ -1,10 +1,18 @@ #ifndef HOOK_H #define HOOK_H +#include "strbuf.h" #include "strvec.h" +#include "run-command.h" struct hook { /* The path to the hook */ const char *hook_path; + + /* + * Use this to keep state for your feed_pipe_fn if you are using + * run_hooks_opt.feed_pipe. Otherwise, do not touch it. + */ + void *feed_pipe_cb_data; }; struct run_hooks_opt @@ -26,6 +34,19 @@ struct run_hooks_opt /* Path to file which should be piped to stdin for each hook */ const char *path_to_stdin; + + /* + * Callback and state pointer to ask for more content to pipe to stdin. + * Will be called repeatedly, for each hook. See + * hook.c:pipe_from_stdin() for an example. Keep per-hook state in + * hook.feed_pipe_cb_data (per process). Keep initialization context in + * feed_pipe_ctx (shared by all processes). + * + * See 'pipe_from_string_list()' for info about how to specify a + * string_list as the stdin input instead of writing your own handler. + */ + feed_pipe_fn feed_pipe; + void *feed_pipe_ctx; }; #define RUN_HOOKS_OPT_INIT { \ @@ -77,4 +98,12 @@ int run_hooks(const char *hookname, const char *hook_path, */ int run_hooks_oneshot(const char *hook_name, struct run_hooks_opt *options); +/** + * To specify a 'struct string_list', set 'run_hooks_opt.feed_pipe_ctx' to the + * string_list and set 'run_hooks_opt.feed_pipe' to pipe_from_string_list(). + * This will pipe each string in the list to stdin, separated by newlines. (Do + * not inject your own newlines.) + */ +int pipe_from_string_list(struct strbuf *pipe, void *pp_cb, void *pp_task_cb); + #endif From patchwork Thu Sep 2 13:11:26 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: 12471641 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 022DEC432BE for ; Thu, 2 Sep 2021 13:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1374610A0 for ; Thu, 2 Sep 2021 13:13:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345187AbhIBNN5 (ORCPT ); Thu, 2 Sep 2021 09:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234277AbhIBNNt (ORCPT ); Thu, 2 Sep 2021 09:13:49 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58FE5C0611FB for ; Thu, 2 Sep 2021 06:12:13 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso1419599wmb.2 for ; Thu, 02 Sep 2021 06:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QQ0UavLqYGrpqz8s1YOftq10mN8wCzrE0MmrJsADMCo=; b=nXnBPZmZu+f6BFWiOV0q7TNY0zl1bNUHDfXcn3byIcB+enVeftqV9yBtbU1zfunNs+ /Rw9ORgA8+rZruj9V3n3n4cvEjyQMlXcneLhd+yHPBQviEq/PSAMme8q8tItsfrVSsx+ NubFQp7YUj5qpRk3E+ZuYe8Qu4Wwzd1KNScsJGvMDIU25dhmYYq/Ld5tn2wLxqmJ5MSf mJcntIM4X1nA6owDY8WRzc9JWpyUyL9tTz4iwaRAWWD/18rs28klreimSe5K0piyqtK5 bIl+EQsMBDPzoold3eqPypP2DnG2FQQy2NBagXNeNm7rfvfRz4AelKzcaXvetUU1P5Ja V2Hw== 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=QQ0UavLqYGrpqz8s1YOftq10mN8wCzrE0MmrJsADMCo=; b=Gt7Wb6bwHNuIyj8rfolBIz5kW34nE2Qf2TWATvGgsDGTnwp3BqsaIr6IOS2cH1SgUq Y2bMtxhRoCuyW4BKxlu+VLDH2GJxJ0OdYeA/lWwaGHvCqTSVjOtFzE2kPJMHmC2wyFFA q8whzP8JufUJV/C/KI+U3BqRtzcmbeO97mAjWJwwmy9AsPShQ/xRzgii1b4r5vO2K26S 9iyzyCxSmY4haM57wIMPBRAnVxpnY4lrkuGiX1qkZ/durKWtAvLy4nehDOG+aYNcHx+H GPY5Zsw9MTlY2CcvDndfe5FNxmPttTbCHx10XaDzLBiAwtuQZAZNPoatPYu+7BsDrLv1 MxGQ== X-Gm-Message-State: AOAM5315vk2+gZzCoOqtgYHOM4HBBN+ETnYKffQCjvbdkXul57Q8YMs2 s/S30hCBLuXZdLFqObEiw1TmkEG3Tf4wdw== X-Google-Smtp-Source: ABdhPJw62rGJt65K5J3aowyDo7H9pK9wn4GKro4I9p8cEcyHLI5v6Kt2e+euS2v2GMsd57BMWOtxBw== X-Received: by 2002:a05:600c:5102:: with SMTP id o2mr3033827wms.104.1630588331664; Thu, 02 Sep 2021 06:12:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 26/36] hook: convert 'post-rewrite' hook in sequencer.c to hook.h Date: Thu, 2 Sep 2021 15:11:26 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer By using 'hook.h' for 'post-rewrite', we simplify hook invocations by not needing to put together our own 'struct child_process'. The signal handling that's being removed by this commit now takes place in run-command.h:run_processes_parallel(), so it is OK to remove them here. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 79 ++++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/sequencer.c b/sequencer.c index 8999edf8d7b..549b583b277 100644 --- a/sequencer.c +++ b/sequencer.c @@ -35,6 +35,7 @@ #include "commit-reach.h" #include "rebase-interactive.h" #include "reset.h" +#include "string-list.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@ -1147,33 +1148,27 @@ int update_head_with_reflog(const struct commit *old_head, static int run_rewrite_hook(const struct object_id *oldoid, const struct object_id *newoid) { - struct child_process proc = CHILD_PROCESS_INIT; - const char *argv[3]; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + struct strbuf tmp = STRBUF_INIT; + struct string_list to_stdin = STRING_LIST_INIT_DUP; int code; - struct strbuf sb = STRBUF_INIT; - argv[0] = find_hook("post-rewrite"); - if (!argv[0]) - return 0; + strvec_push(&opt.args, "amend"); - argv[1] = "amend"; - argv[2] = NULL; - - proc.argv = argv; - proc.in = -1; - proc.stdout_to_stderr = 1; - proc.trace2_hook_name = "post-rewrite"; - - code = start_command(&proc); - if (code) - return code; - strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid)); - sigchain_push(SIGPIPE, SIG_IGN); - write_in_full(proc.in, sb.buf, sb.len); - close(proc.in); - strbuf_release(&sb); - sigchain_pop(SIGPIPE); - return finish_command(&proc); + strbuf_addf(&tmp, + "%s %s", + oid_to_hex(oldoid), + oid_to_hex(newoid)); + string_list_append(&to_stdin, tmp.buf); + + opt.feed_pipe = pipe_from_string_list; + opt.feed_pipe_ctx = &to_stdin; + + code = run_hooks_oneshot("post-rewrite", &opt); + + strbuf_release(&tmp); + string_list_clear(&to_stdin, 0); + return code; } void commit_post_rewrite(struct repository *r, @@ -4526,30 +4521,20 @@ static int pick_commits(struct repository *r, flush_rewritten_pending(); if (!stat(rebase_path_rewritten_list(), &st) && st.st_size > 0) { - struct child_process child = CHILD_PROCESS_INIT; - const char *post_rewrite_hook = - find_hook("post-rewrite"); - - child.in = open(rebase_path_rewritten_list(), O_RDONLY); - child.git_cmd = 1; - strvec_push(&child.args, "notes"); - strvec_push(&child.args, "copy"); - strvec_push(&child.args, "--for-rewrite=rebase"); + struct child_process notes_cp = CHILD_PROCESS_INIT; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; + + notes_cp.in = open(rebase_path_rewritten_list(), O_RDONLY); + notes_cp.git_cmd = 1; + strvec_push(¬es_cp.args, "notes"); + strvec_push(¬es_cp.args, "copy"); + strvec_push(¬es_cp.args, "--for-rewrite=rebase"); /* we don't care if this copying failed */ - run_command(&child); - - if (post_rewrite_hook) { - struct child_process hook = CHILD_PROCESS_INIT; - - hook.in = open(rebase_path_rewritten_list(), - O_RDONLY); - hook.stdout_to_stderr = 1; - hook.trace2_hook_name = "post-rewrite"; - strvec_push(&hook.args, post_rewrite_hook); - strvec_push(&hook.args, "rebase"); - /* we don't care if this hook failed */ - run_command(&hook); - } + run_command(¬es_cp); + + hook_opt.path_to_stdin = rebase_path_rewritten_list(); + strvec_push(&hook_opt.args, "rebase"); + run_hooks_oneshot("post-rewrite", &hook_opt); } apply_autostash(rebase_path_autostash()); From patchwork Thu Sep 2 13:11:27 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: 12471645 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 56213C4320A for ; Thu, 2 Sep 2021 13:13:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E2CE6108E for ; Thu, 2 Sep 2021 13:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345209AbhIBNOK (ORCPT ); Thu, 2 Sep 2021 09:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345182AbhIBNNt (ORCPT ); Thu, 2 Sep 2021 09:13:49 -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 63FDFC0611BC for ; Thu, 2 Sep 2021 06:12:14 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id e26so1251745wmk.2 for ; Thu, 02 Sep 2021 06:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=olypxuI2oX+Z9/4FTiGEAEVgrnYFdmv2uO5BZ0kFp7k=; b=Tc1lZu9KqTVlUd2TC7uhKn0UWaLIid4FrInenJyRUVK6+ZJlI9r0EU/nwZ/h/CTvcU 0ZO4DbB+nIv4mzKRKW4drrAbz2nf8FKGasNWkMyi+MbW7qBj+1lKNinApUpdrnt0ltxv zvTJ11Pil5cK+cttGMrnydSuJ98ITpmdBU6myL9ghvggHTwZUOauxeBWILXcRxjdbjxk p3rOnRdKys9gWpQr1m8Wy3SYf/grO56Qk+X4y4dDuS+oyo/DiEKKl3x63dOYIS6AldeX MCc5OBMUFpu4F7CvZzlDw/ENQ54r74o5mgbGYfC8ofFpRXjTlvhmKw4dqoML6xg0jXgg S4Ow== 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=olypxuI2oX+Z9/4FTiGEAEVgrnYFdmv2uO5BZ0kFp7k=; b=kzIRPAtBWdKsxATyNdSXgCofK74W/SXE7nuR2Bq6fKuY8NDBoFYwKmij76e6tCVLFh Vy+uKOqey2uKvWqTgj/sO6J02LFoM2RJ57KqJpC1yz//By253uFmxIiW0JcQ58ub/qM8 UZzUXaCar4f4NTdZKvttRBTCpn0ajveEOrRkXXFZOLwUI2zqTMfb39HsSzgN9qDvIAJm 9B55PX21oaz2MHgeIZEXFGHrAt/a3Znq3FhJ7GISHa1MWSg9rUO/r1EXPH+cjO2rep/S 2ulb7tEmcKrW6Fx07MVxRkGx2ZbUTd1l2ucqwyNT+LlxZaBU/Zrd3mYDLO/FchCEY4pb VO0g== X-Gm-Message-State: AOAM533xybWNqkNVsTLV3aahyaoyBMqxsf4eBnAdjPFoBPzkA4NvCoHF OfGvAjB2aUzR49a0N0P01YuQsd4Srst60g== X-Google-Smtp-Source: ABdhPJx4D4MoRmt8GgdgXeaioHSRWHI9gNzublcmKmNNeYeuBeyrD6wW4Mzbm7mkTeri6pr9IVYCRQ== X-Received: by 2002:a7b:c4cb:: with SMTP id g11mr3144367wmk.80.1630588332652; Thu, 02 Sep 2021 06:12:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 27/36] transport: convert pre-push hook to hook.h Date: Thu, 2 Sep 2021 15:11:27 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the pre-push hook away from run-command.h to and over to the new hook.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- transport.c | 56 ++++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/transport.c b/transport.c index 77e196f75f5..4ca8fc0391d 100644 --- a/transport.c +++ b/transport.c @@ -1203,63 +1203,35 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing) static int run_pre_push_hook(struct transport *transport, struct ref *remote_refs) { - int ret = 0, x; + int ret = 0; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; struct ref *r; - struct child_process proc = CHILD_PROCESS_INIT; - struct strbuf buf; - const char *argv[4]; - - if (!(argv[0] = find_hook("pre-push"))) - return 0; - - argv[1] = transport->remote->name; - argv[2] = transport->url; - argv[3] = NULL; - - proc.argv = argv; - proc.in = -1; - proc.trace2_hook_name = "pre-push"; - - if (start_command(&proc)) { - finish_command(&proc); - return -1; - } + struct string_list to_stdin = STRING_LIST_INIT_NODUP; - sigchain_push(SIGPIPE, SIG_IGN); - - strbuf_init(&buf, 256); + strvec_push(&opt.args, transport->remote->name); + strvec_push(&opt.args, transport->url); for (r = remote_refs; r; r = r->next) { + struct strbuf buf = STRBUF_INIT; + if (!r->peer_ref) continue; if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue; if (r->status == REF_STATUS_REJECT_STALE) continue; if (r->status == REF_STATUS_REJECT_REMOTE_UPDATED) continue; if (r->status == REF_STATUS_UPTODATE) continue; - strbuf_reset(&buf); - strbuf_addf( &buf, "%s %s %s %s\n", + strbuf_addf(&buf, "%s %s %s %s", r->peer_ref->name, oid_to_hex(&r->new_oid), r->name, oid_to_hex(&r->old_oid)); - - if (write_in_full(proc.in, buf.buf, buf.len) < 0) { - /* We do not mind if a hook does not read all refs. */ - if (errno != EPIPE) - ret = -1; - break; - } + string_list_append(&to_stdin, strbuf_detach(&buf, NULL)); } - strbuf_release(&buf); - - x = close(proc.in); - if (!ret) - ret = x; - - sigchain_pop(SIGPIPE); + opt.feed_pipe = pipe_from_string_list; + opt.feed_pipe_ctx = &to_stdin; - x = finish_command(&proc); - if (!ret) - ret = x; + ret = run_hooks_oneshot("pre-push", &opt); + to_stdin.strdup_strings = 1; + string_list_clear(&to_stdin, 0); return ret; } From patchwork Thu Sep 2 13:11:28 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: 12471643 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 66164C432BE for ; Thu, 2 Sep 2021 13:13:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A4936108E for ; Thu, 2 Sep 2021 13:13:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345293AbhIBNOC (ORCPT ); Thu, 2 Sep 2021 09:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345207AbhIBNNt (ORCPT ); Thu, 2 Sep 2021 09:13:49 -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 75484C0619F6 for ; Thu, 2 Sep 2021 06:12:15 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id z9-20020a7bc149000000b002e8861aff59so1432863wmi.0 for ; Thu, 02 Sep 2021 06:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HKcjdgoq9juBix53/qIEgCUDSBlrNwK94m/unX61Mbs=; b=CjduTw+El4UboPE9TfGEl3E3+KcQ0k9p+B5W8ZjXtOfI4Uq5wi1IGoTvSAnNnnL6L/ gcBor9/c+V5Zd3nX8e4JpaBz39gieAj/VbLr9XDN73qcZkE7l6E9CB7jat3ZHCz4rB/7 T7cTfU2PRMPlTT6VX2SwmzOG0LjvubceEe9RnmHljucyLhy3eFsd5qe5Ikp7donyFcfd Y1v5fek9EYx44nB0pLGq4xEyfrH1bmOVdOcPxYBgTYwXa2o7EhNerniC8LyYWK9PQ9OZ oaqkqRXLsHNcxkk84e6AATT13ZSmyyPXGOCrUPkJWYts9wjlwRJUU6Wim91nBqbqfgrg 6rOQ== 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=HKcjdgoq9juBix53/qIEgCUDSBlrNwK94m/unX61Mbs=; b=GxumHSZINsEYSemK8cX+wLsgznobjaADO5jP2f5nsipyXTgtXpqxHfZ32cVomtazpO lJf4sL9PN7efHnA7RA0G++maN3mFTuZ5f+KInG2nMMYXhIybT9lLsi1KfbpHrXbQDumr sZMbryQ+nxBIJ15jspyDAJP5nJCZ9NT5jRfmarriMVtwcpX50kknK3C+25pNtcvyy6nk 9j/eaSY8jBgHXcGGBErBNdD3zfq5jf7wQLx52FXJmKu3UHXa0NiphNwGBUo2WzvJqi5r C1Zl0P2mSqqfgEpzrwmzRXvf8vS8LMrbPpeDVVNrh5RDLcWZ7fHdcxZT57f8IWXj+ejS 79ZQ== X-Gm-Message-State: AOAM531sppbPs0ZzO7+Ve4jOeQ/CqInd9hiE7/U/jM2/TkpU2Ov/Zndu RK5kwDp4D3f1GUQD1p3f5yp0sxWcWPsSPA== X-Google-Smtp-Source: ABdhPJzkNQR0aJ032Z2YDTnXJX0rj0GO1V/0JiKOswTd/HAHb4tjFjZkX5fzvcs59yXCMEYmydHqGw== X-Received: by 2002:a05:600c:230a:: with SMTP id 10mr3063620wmo.79.1630588333842; Thu, 02 Sep 2021 06:12:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 28/36] hook tests: test for exact "pre-push" hook input Date: Thu, 2 Sep 2021 15:11:28 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Extend the tests added in ec55559f937 (push: Add support for pre-push hooks, 2013-01-13) to exhaustively test for the exact input we're expecting. This ensures that we e.g. don't miss a trailing newline. Appending to a file called "actual" is the established convention in this test for hooks, see the rest of the tests added in ec55559f937 (push: Add support for pre-push hooks, 2013-01-13). Let's follow that convention here. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5571-pre-push-hook.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh index ad8d5804f7b..d2857a6fbc0 100755 --- a/t/t5571-pre-push-hook.sh +++ b/t/t5571-pre-push-hook.sh @@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks" HOOK="$HOOKDIR/pre-push" mkdir -p "$HOOKDIR" write_script "$HOOK" </dev/null +cat >actual exit 0 EOF @@ -20,10 +20,16 @@ test_expect_success 'setup' ' git init --bare repo1 && git remote add parent1 repo1 && test_commit one && - git push parent1 HEAD:foreign + cat >expect <<-EOF && + HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero) + EOF + + test_when_finished "rm actual" && + git push parent1 HEAD:foreign && + test_cmp expect actual ' write_script "$HOOK" </dev/null +cat >actual exit 1 EOF @@ -32,11 +38,18 @@ export COMMIT1 test_expect_success 'push with failing hook' ' test_commit two && - test_must_fail git push parent1 HEAD + cat >expect <<-EOF && + HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero) + EOF + + test_when_finished "rm actual" && + test_must_fail git push parent1 HEAD && + test_cmp expect actual ' test_expect_success '--no-verify bypasses hook' ' - git push --no-verify parent1 HEAD + git push --no-verify parent1 HEAD && + test_path_is_missing actual ' COMMIT2="$(git rev-parse HEAD)" From patchwork Thu Sep 2 13:11:29 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: 12471653 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 CA89CC4320E for ; Thu, 2 Sep 2021 13:13:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7434610E5 for ; Thu, 2 Sep 2021 13:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345333AbhIBNOS (ORCPT ); Thu, 2 Sep 2021 09:14:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345131AbhIBNNt (ORCPT ); Thu, 2 Sep 2021 09:13:49 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35208C061796 for ; Thu, 2 Sep 2021 06:12:17 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso1323976wmi.5 for ; Thu, 02 Sep 2021 06:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=31NTqck4jecsTTDFZgv2PY1Imf9TS1NITPfBxfYfyaM=; b=Af+fGvnGpZCXq5nXD4EL0mPt1UJRr58i8LL3c3NaC6uFS+Bf7xq2Utw0Eel2lmSMQ1 XtfncfBjIWdmmwC/vK/xdSxnVbdssmQLTGySWrs1fZKDIP1V8alAXDy0uDWlfrpzuSTW AC5HsIM4iWrmMwaW6gLwuZRdj9yjI1+8G+s349alSRq6gQZTUZz/xg6BZHYtOVNd2d8h 0tuubSGQfFdoqFk71siSy9XH+Ii5JGRmnv+v8sz3xFyZUb4ZNgR+7XfpRD/IBcL5U47k 9dXQPr7kM9oRpaKkpwfoXFnYw3z629FuzFr7So5XU4SUPmvdRwxfLXzuaMPBd6Yexzvw yIKA== 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=31NTqck4jecsTTDFZgv2PY1Imf9TS1NITPfBxfYfyaM=; b=r5RbbmzTyFltJ4uqQoHxJfIG59RvSZ1Ir7k7w3jxcRpx2a8Xc5QQT6dQJhOHb+4WKv KcQ+IAqSAXpYxkV57Wh6PEbi/AqR/htsi2dgPTD+juRo8i6OOmNYM5v/o2NjN0JUTDP+ huWMbdE/Hs3xHTGIo60H1sqchoBAcRx6Vv4FhISd5iUwWdSSGWAKojBtK/t99q+H0Spv AOdSGNgVyhulXeNLmdQ60DB5Ls2UAMG+aXjGD+Rj99z53HdKLMzBIahcwr4XDM6J7US+ A7PO79CNoWOBJWj/gS2YbFNex0llmKQIhuRvjQj5Yh+Fp0EIHyWXAM1NJz2TzZmmf1ej RLQA== X-Gm-Message-State: AOAM531AYqCeLtyybV8tw6lli25xhBclZB+wJmtPxUyarlK4QC7dSpp5 ysCRnvub3+doEYDxruLxw0Wr703yuu3tTA== X-Google-Smtp-Source: ABdhPJyPW4u7e8/ojG89CHS3M2zKxIb4h0QZY6oZDSJj2tAIKfWPstPMmkVkx6aucrniiMGXs9ne4Q== X-Received: by 2002:a7b:c7c3:: with SMTP id z3mr3071365wmk.96.1630588335546; Thu, 02 Sep 2021 06:12:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 29/36] hook tests: use a modern style for "pre-push" tests Date: Thu, 2 Sep 2021 15:11:29 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Indent the here-docs and use "test_cmp" instead of "diff" in tests added in ec55559f937 (push: Add support for pre-push hooks, 2013-01-13). Let's also use the more typical "expect" instead of "expected" to be consistent with the rest of the test file. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5571-pre-push-hook.sh | 71 ++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh index d2857a6fbc0..cc1a3e23668 100755 --- a/t/t5571-pre-push-hook.sh +++ b/t/t5571-pre-push-hook.sh @@ -61,15 +61,15 @@ echo "$2" >>actual cat >>actual EOF -cat >expected <expect <<-EOF && + parent1 + repo1 + refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1 + EOF + git push parent1 main:foreign && - diff expected actual + test_cmp expect actual ' test_expect_success 'add a branch' ' @@ -80,49 +80,48 @@ test_expect_success 'add a branch' ' COMMIT3="$(git rev-parse HEAD)" export COMMIT3 -cat >expected <expect <<-EOF && + parent1 + repo1 + refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2 + EOF git push && - diff expected actual + test_cmp expect actual ' -cat >expected <expect <<-EOF && + parent1 + repo1 + refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID + HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID + EOF + git push parent1 one:tag1 HEAD~:refs/heads/prev && - diff expected actual + test_cmp expect actual ' -cat >expected <expect <<-EOF && + parent1 + repo1 + (delete) $ZERO_OID refs/heads/prev $COMMIT2 + EOF + git push parent1 :prev && - diff expected actual + test_cmp expect actual ' -cat >expected <expect <<-EOF && + repo1 + repo1 + HEAD $COMMIT3 refs/heads/other $ZERO_OID + EOF + git push repo1 HEAD && - diff expected actual + test_cmp expect actual ' test_expect_success 'set up many-ref tests' ' From patchwork Thu Sep 2 13:11:30 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: 12471651 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 B9249C4320A for ; Thu, 2 Sep 2021 13:13:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B00D6108E for ; Thu, 2 Sep 2021 13:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345323AbhIBNOR (ORCPT ); Thu, 2 Sep 2021 09:14:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345213AbhIBNNu (ORCPT ); Thu, 2 Sep 2021 09:13:50 -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 5D798C061140 for ; Thu, 2 Sep 2021 06:12:18 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id v10so2856235wrd.4 for ; Thu, 02 Sep 2021 06:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dTOmtGfxwClGIa/BmKDqSE/IJnx8G+p2LBhI1YVnoB8=; b=mrz65AMTtgyJ1h43xxvwHqwHGHjB9rMwVn1fwEa9t7FMzdKeAMb5gENH2Qk0YyqHqK NDS5A/mkPBXI5CkgYXYs9Zu7YTPxx+o/1Cfe/n6Uva8X+QiryyKKm0OBnDkNhqtKNuoI uHnQWQnj3X03c8/7C2c9hgk9LRrafez4CBuIWB3UZ7Mb8R7U2AbCPZ3eHv7n1iuEwMZz NH/K9WqQyT3ihi1j1IatGQBbbyY8O3866fgUxrQNVQmfsUEYbsn0RRkjzTlMbptqtCly WtxT0D74M9jVzPfVVPGpxtJxRYp2/JWbCfgNKR4Sr5PjsDhoA4HolQiGCn9drGco1U44 9NUA== 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=dTOmtGfxwClGIa/BmKDqSE/IJnx8G+p2LBhI1YVnoB8=; b=syzRZGtA4GeclLiKX43YtAeGCFpa8u46PMVNERRBym7pPTurMPMBtH9xtsE2WYEkO2 QuySTLt0binINVbiPrw29s3wLWCK5n79SJzEiGcbSjYJg8Bn8xnMv/7skEN67RF1SNiq CulOcf0FuHt3tRf2kkDT6DeSSF+Jq4CBQ3ZUX/xYQSk30k8arp5rmPc9oggprSD53NqK E0LI7zxpinJ9hHVTsawip9AO3oHJZcGLGHo8XbvFL7HJEgwG/IkOHEfqI1mALKeWlV78 f5gCbXBXxqMclt6n5bz0Nlp7l7DlCGlSk3BkbLtYrXQwBSb4Q3umkljpt2c1xefZGt8+ iROw== X-Gm-Message-State: AOAM532Ep4NWj66uTux8Op5JpPTMDimqm0Ppgn2AC5LSXSYJUGlL5jpe aB/OMxTVG4S+DiERAzLrc4gbETTTVIDDGA== X-Google-Smtp-Source: ABdhPJx4qiU/0MGrj5qqxVZXvyuakR2yOoTN/nq6HjApvIu15d8TxUXPEktxZjynba31Q6f7qW+p8g== X-Received: by 2002:adf:e910:: with SMTP id f16mr3714149wrm.393.1630588336619; Thu, 02 Sep 2021 06:12:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 30/36] reference-transaction: use hook.h to run hooks Date: Thu, 2 Sep 2021 15:11:30 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- refs.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/refs.c b/refs.c index 6211692eaae..73d4a939267 100644 --- a/refs.c +++ b/refs.c @@ -2062,47 +2062,33 @@ int ref_update_reject_duplicates(struct string_list *refnames, static int run_transaction_hook(struct ref_transaction *transaction, const char *state) { - struct child_process proc = CHILD_PROCESS_INIT; - struct strbuf buf = STRBUF_INIT; - const char *hook; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + struct string_list to_stdin = STRING_LIST_INIT_NODUP; int ret = 0, i; - hook = find_hook("reference-transaction"); - if (!hook) - return ret; - - strvec_pushl(&proc.args, hook, state, NULL); - proc.in = -1; - proc.stdout_to_stderr = 1; - proc.trace2_hook_name = "reference-transaction"; - - ret = start_command(&proc); - if (ret) + if (!hook_exists("reference-transaction")) return ret; - sigchain_push(SIGPIPE, SIG_IGN); + strvec_push(&opt.args, state); for (i = 0; i < transaction->nr; i++) { struct ref_update *update = transaction->updates[i]; + struct strbuf buf = STRBUF_INIT; - strbuf_reset(&buf); - strbuf_addf(&buf, "%s %s %s\n", + strbuf_addf(&buf, "%s %s %s", oid_to_hex(&update->old_oid), oid_to_hex(&update->new_oid), update->refname); - - if (write_in_full(proc.in, buf.buf, buf.len) < 0) { - if (errno != EPIPE) - ret = -1; - break; - } + string_list_append(&to_stdin, strbuf_detach(&buf, NULL)); } - close(proc.in); - sigchain_pop(SIGPIPE); - strbuf_release(&buf); + opt.feed_pipe = pipe_from_string_list; + opt.feed_pipe_ctx = &to_stdin; + + ret = run_hooks_oneshot("reference-transaction", &opt); + to_stdin.strdup_strings = 1; + string_list_clear(&to_stdin, 0); - ret |= finish_command(&proc); return ret; } From patchwork Thu Sep 2 13:11:31 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: 12471647 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 0E709C43214 for ; Thu, 2 Sep 2021 13:13:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4C016108E for ; Thu, 2 Sep 2021 13:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345205AbhIBNON (ORCPT ); Thu, 2 Sep 2021 09:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345215AbhIBNNv (ORCPT ); Thu, 2 Sep 2021 09:13:51 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA57CC061147 for ; Thu, 2 Sep 2021 06:12:19 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id o39-20020a05600c512700b002e74638b567so1345866wms.2 for ; Thu, 02 Sep 2021 06:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xmf2YvCFWQ+MBH9/Is0EbWNT4TWAV+YT4gBMT8bsF5k=; b=gpy1TFQIzk/7tENgboMkCLMNJOaWceuHk9HgCcgpxvio8dfm3vBqSTtjZqfdWNJOkt QiQaCIU7g/0LVJP+2iyt0APH9OdeVyVZQfJAQKGod/xGMwjxa4c9b8kFk0Y9zrLqi0VI 6gqiO/REUng1E8LFtbjHon1qQxcE7zLwKVPwoMSafZs1JQMjM5mRfsMhQQ0phGdwWmOi +yewIYfwjQ6C8GKaqHUFY7JgXU4y/qTP2Gf5tN83HHihKO4cxb3QqKBiw71NrZ/C0ohj pkPdX0fTRrSdXfbnkR28RHMqlfAFQoFSYzduPb6rLhMaZEBIc6QGErFD8CdBJwaUDZ0A hGbw== 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=Xmf2YvCFWQ+MBH9/Is0EbWNT4TWAV+YT4gBMT8bsF5k=; b=BSFe3+/qdSlW6JBr4Tk1zqYr/A6UwRvQ55Vb9RGACDbLIxJQBMWL44S8JOsa+dylNi uTDAN6mgRDuNHb09vUR/D5NAL7iKWVm4lFhpc4ejKv1B/Sf74EnnlFEKVNzPAStBWUzX WR1jhCeZPSalC+7wt86ps7Hcjn+JUjTU5yvDEdgkU2ouK2aES+F8yJ9+M4lWxyM01GIM yHDnUI4RCOoIzzGb/dEkNhuELPqTaZEytjrsQaeznpAEPbOJE0vjO9IQG8GWqJt+giH7 LT3vGeiI+LtR4eOpNsUnCdxxo/XD1iuoCXLc9SxB5ZMscTb1Mww8MEUsf3rXr2mzHogV tV0g== X-Gm-Message-State: AOAM532oufVCtBXCJ6dmB+l6pahZTMIuz0QJKuKDcQdOTkoMOoAGW1x0 rkOg7/Uuv3c13583flW14crI8zvXclRahQ== X-Google-Smtp-Source: ABdhPJzYwawZnnsr01CN+fRyOw9ETmP0w6QAqeHoEmWPm+wKBw+ztLBRY2n6vSzJ3H9kErm6oibk5A== X-Received: by 2002:a1c:7506:: with SMTP id o6mr3270135wmc.112.1630588337931; Thu, 02 Sep 2021 06:12:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:17 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 31/36] run-command: allow capturing of collated output Date: Thu, 2 Sep 2021 15:11:31 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Some callers, for example server-side hooks which wish to relay hook output to clients across a transport, want to capture what would normally print to stderr and do something else with it. Allow that via a callback. By calling the callback regardless of whether there's output available, we allow clients to send e.g. a keepalive if necessary. Because we expose a strbuf, not a fd or FILE*, there's no need to create a temporary pipe or similar - we can just skip the print to stderr and instead hand it to the caller. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fetch.c | 2 +- builtin/submodule--helper.c | 2 +- hook.c | 1 + run-command.c | 33 +++++++++++++++++++++++++-------- run-command.h | 18 +++++++++++++++++- submodule.c | 2 +- t/helper/test-run-command.c | 25 ++++++++++++++++++++----- t/t0061-run-command.sh | 7 +++++++ 8 files changed, 73 insertions(+), 17 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index b18ada08842..27b63ee5200 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1819,7 +1819,7 @@ static int fetch_multiple(struct string_list *list, int max_children) result = run_processes_parallel_tr2(max_children, &fetch_next_remote, &fetch_failed_to_start, - NULL, + NULL, NULL, &fetch_finished, &state, "fetch", "parallel/fetch"); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0b73739c160..fbceab08b0d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2311,7 +2311,7 @@ static int update_submodules(struct submodule_update_clone *suc) int i; run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, - update_clone_start_failure, NULL, + update_clone_start_failure, NULL, NULL, update_clone_task_finished, suc, "submodule", "parallel/update"); diff --git a/hook.c b/hook.c index 7a6ef527443..169287ad152 100644 --- a/hook.c +++ b/hook.c @@ -174,6 +174,7 @@ int run_hooks(const char *hook_name, const char *hook_path, pick_next_hook, notify_start_failure, options->feed_pipe, + NULL, notify_hook_finished, &cb_data, "hook", diff --git a/run-command.c b/run-command.c index f1616858d18..aacc336f951 100644 --- a/run-command.c +++ b/run-command.c @@ -1493,6 +1493,7 @@ struct parallel_processes { get_next_task_fn get_next_task; start_failure_fn start_failure; feed_pipe_fn feed_pipe; + consume_sideband_fn consume_sideband; task_finished_fn task_finished; struct { @@ -1558,6 +1559,7 @@ static void pp_init(struct parallel_processes *pp, get_next_task_fn get_next_task, start_failure_fn start_failure, feed_pipe_fn feed_pipe, + consume_sideband_fn consume_sideband, task_finished_fn task_finished, void *data) { @@ -1578,6 +1580,7 @@ static void pp_init(struct parallel_processes *pp, pp->start_failure = start_failure ? start_failure : default_start_failure; pp->feed_pipe = feed_pipe ? feed_pipe : default_feed_pipe; pp->task_finished = task_finished ? task_finished : default_task_finished; + pp->consume_sideband = consume_sideband; pp->nr_processes = 0; pp->output_owner = 0; @@ -1614,7 +1617,10 @@ static void pp_cleanup(struct parallel_processes *pp) * When get_next_task added messages to the buffer in its last * iteration, the buffered output is non empty. */ - strbuf_write(&pp->buffered_output, stderr); + if (pp->consume_sideband) + pp->consume_sideband(&pp->buffered_output, pp->data); + else + strbuf_write(&pp->buffered_output, stderr); strbuf_release(&pp->buffered_output); sigchain_pop_common(); @@ -1735,9 +1741,13 @@ static void pp_buffer_stderr(struct parallel_processes *pp, int output_timeout) static void pp_output(struct parallel_processes *pp) { int i = pp->output_owner; + if (pp->children[i].state == GIT_CP_WORKING && pp->children[i].err.len) { - strbuf_write(&pp->children[i].err, stderr); + if (pp->consume_sideband) + pp->consume_sideband(&pp->children[i].err, pp->data); + else + strbuf_write(&pp->children[i].err, stderr); strbuf_reset(&pp->children[i].err); } } @@ -1776,11 +1786,15 @@ static int pp_collect_finished(struct parallel_processes *pp) strbuf_addbuf(&pp->buffered_output, &pp->children[i].err); strbuf_reset(&pp->children[i].err); } else { - strbuf_write(&pp->children[i].err, stderr); + /* Output errors, then all other finished child processes */ + if (pp->consume_sideband) { + pp->consume_sideband(&pp->children[i].err, pp->data); + pp->consume_sideband(&pp->buffered_output, pp->data); + } else { + strbuf_write(&pp->children[i].err, stderr); + strbuf_write(&pp->buffered_output, stderr); + } strbuf_reset(&pp->children[i].err); - - /* Output all other finished child processes */ - strbuf_write(&pp->buffered_output, stderr); strbuf_reset(&pp->buffered_output); /* @@ -1804,6 +1818,7 @@ int run_processes_parallel(int n, get_next_task_fn get_next_task, start_failure_fn start_failure, feed_pipe_fn feed_pipe, + consume_sideband_fn consume_sideband, task_finished_fn task_finished, void *pp_cb) { @@ -1814,7 +1829,7 @@ int run_processes_parallel(int n, sigchain_push(SIGPIPE, SIG_IGN); - pp_init(&pp, n, get_next_task, start_failure, feed_pipe, task_finished, pp_cb); + pp_init(&pp, n, get_next_task, start_failure, feed_pipe, consume_sideband, task_finished, pp_cb); while (1) { for (i = 0; i < spawn_cap && !pp.shutdown && @@ -1852,6 +1867,7 @@ int run_processes_parallel(int n, int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task, start_failure_fn start_failure, feed_pipe_fn feed_pipe, + consume_sideband_fn consume_sideband, task_finished_fn task_finished, void *pp_cb, const char *tr2_category, const char *tr2_label) { @@ -1861,7 +1877,8 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task, ((n < 1) ? online_cpus() : n)); result = run_processes_parallel(n, get_next_task, start_failure, - feed_pipe, task_finished, pp_cb); + feed_pipe, consume_sideband, + task_finished, pp_cb); trace2_region_leave(tr2_category, tr2_label, NULL); diff --git a/run-command.h b/run-command.h index 80d394664ae..e321d23bbd2 100644 --- a/run-command.h +++ b/run-command.h @@ -436,6 +436,20 @@ typedef int (*feed_pipe_fn)(struct strbuf *pipe, void *pp_cb, void *pp_task_cb); +/** + * If this callback is provided, instead of collating process output to stderr, + * they will be collated into a new pipe. consume_sideband_fn will be called + * repeatedly. When output is available on that pipe, it will be contained in + * 'output'. But it will be called with an empty 'output' too, to allow for + * keepalives or similar operations if necessary. + * + * pp_cb is the callback cookie as passed into run_processes_parallel. + * + * Since this callback is provided with the collated output, no task cookie is + * provided. + */ +typedef void (*consume_sideband_fn)(struct strbuf *output, void *pp_cb); + /** * This callback is called on every child process that finished processing. * @@ -471,10 +485,12 @@ int run_processes_parallel(int n, get_next_task_fn, start_failure_fn, feed_pipe_fn, + consume_sideband_fn, task_finished_fn, void *pp_cb); int run_processes_parallel_tr2(int n, get_next_task_fn, start_failure_fn, - feed_pipe_fn, task_finished_fn, void *pp_cb, + feed_pipe_fn, consume_sideband_fn, + task_finished_fn, void *pp_cb, const char *tr2_category, const char *tr2_label); /** diff --git a/submodule.c b/submodule.c index db1700a502d..32364d8bd56 100644 --- a/submodule.c +++ b/submodule.c @@ -1632,7 +1632,7 @@ int fetch_populated_submodules(struct repository *r, run_processes_parallel_tr2(max_parallel_jobs, get_next_submodule, fetch_start_failure, - NULL, + NULL, NULL, fetch_finish, &spf, "submodule", "parallel/fetch"); diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 9348184d303..d53db6d11c4 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -51,6 +51,16 @@ static int no_job(struct child_process *cp, return 0; } +static void test_consume_sideband(struct strbuf *output, void *cb) +{ + FILE *sideband; + + sideband = fopen("./sideband", "a"); + + strbuf_write(output, sideband); + fclose(sideband); +} + static int task_finished(int result, struct strbuf *err, void *pp_cb, @@ -201,7 +211,7 @@ static int testsuite(int argc, const char **argv) suite.tests.nr, max_jobs); ret = run_processes_parallel(max_jobs, next_test, test_failed, - test_stdin, test_finished, &suite); + test_stdin, NULL, test_finished, &suite); if (suite.failed.nr > 0) { ret = 1; @@ -429,23 +439,28 @@ int cmd__run_command(int argc, const char **argv) if (!strcmp(argv[1], "run-command-parallel")) exit(run_processes_parallel(jobs, parallel_next, - NULL, NULL, NULL, &proc)); + NULL, NULL, NULL, NULL, &proc)); if (!strcmp(argv[1], "run-command-abort")) exit(run_processes_parallel(jobs, parallel_next, - NULL, NULL, task_finished, &proc)); + NULL, NULL, NULL, task_finished, &proc)); if (!strcmp(argv[1], "run-command-no-jobs")) exit(run_processes_parallel(jobs, no_job, - NULL, NULL, task_finished, &proc)); + NULL, NULL, NULL, task_finished, &proc)); if (!strcmp(argv[1], "run-command-stdin")) { proc.in = -1; proc.no_stdin = 0; exit (run_processes_parallel(jobs, parallel_next, NULL, - test_stdin, NULL, &proc)); + test_stdin, NULL, NULL, &proc)); } + if (!strcmp(argv[1], "run-command-sideband")) + exit(run_processes_parallel(jobs, parallel_next, NULL, NULL, + test_consume_sideband, NULL, + &proc)); + fprintf(stderr, "check usage\n"); return 1; } diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh index 87759482ad1..e99f6c7f445 100755 --- a/t/t0061-run-command.sh +++ b/t/t0061-run-command.sh @@ -143,6 +143,13 @@ test_expect_success 'run_command runs in parallel with more tasks than jobs avai test_cmp expect actual ' +test_expect_success 'run_command can divert output' ' + test_when_finished rm sideband && + test-tool run-command run-command-sideband 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && + test_must_be_empty actual && + test_cmp expect sideband +' + cat >expect <<-EOF preloaded output of a child listening for stdin: From patchwork Thu Sep 2 13:11:32 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: 12471649 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 6DF50C432BE for ; Thu, 2 Sep 2021 13:13:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57D1D610A0 for ; Thu, 2 Sep 2021 13:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345314AbhIBNON (ORCPT ); Thu, 2 Sep 2021 09:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345226AbhIBNNw (ORCPT ); Thu, 2 Sep 2021 09:13:52 -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 E66CBC06114B for ; Thu, 2 Sep 2021 06:12:20 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id k5-20020a05600c1c8500b002f76c42214bso1406892wms.3 for ; Thu, 02 Sep 2021 06:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mUewC8kYyqtcKMjvm6xu28EbYkmcIlakTlRv6tNfFyg=; b=PDw7tCEl15bYS2jgoVhPjNmYNm2euu4OqvWMW9wRM6BHfk1S4CeivnaNH9BabaanRt Urz3jO86FgxScqj2bOCyCqS1KEv49UpAImVxOOJLqBUwEHjFlKJ/eehJih8TcLePwdqZ s6isszQw7E7AfpNgudd4CAekGBGoVCIyokCZxLzOnOMQYdR9fqI/guGMTjg5BYSmYtJn XJ3xmRR/OA1w90QHRnZIwjAbhE4lOPCSGWDK+iEjduAZCxQ/11DKYU2IL/654H45JktA dSNvrHvCxe69ckuBXw4n1BtGDrYjf6NTWES9FHYSESe6neEtqUrX5HGrfRzBAUM9XhHL nStg== 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=mUewC8kYyqtcKMjvm6xu28EbYkmcIlakTlRv6tNfFyg=; b=OQsKnIazn87Ig6wgepdggf/olIze9sWFltSLyeSCEFIaLzmdk81U+To2GeDjrehzh2 F95nxPZMDvhXksz+Ok13XDujHqaAryOGts7WqRpA7aFN5ZHE5H369c7OqAk+ig69sECm wbNCcPjBJzhFzxjjcyjNelZ4j3pG+YhaLjBAW1KHKkLs8ULgJcbkHYKo8dLp8bhJqye/ WNKDn9lmDOFeZgWcR6E5qcKga1mTZSrz2uv44c5SrfwTDqcg07o++xOqtBjYzKKEyAQM ZaVM8E6Jno5Az4OFOEcguvMwWCXqCAE35rld/QuS94WHreDDINWMwmREQqPU7HcVBZb0 8UxQ== X-Gm-Message-State: AOAM5302j/spKW81xcp2r8dPZtVO8ZuzEyYiL4VAyn6xEEXySAbuHTPa 6P0E16AIXxd86lsjJEk/h6c+/BYqivQZRQ== X-Google-Smtp-Source: ABdhPJyF0dMwaERXC8BgGBBZtX8P2iw3FAcvR6II0lOPBY9aMC4glZC93EJqhuYtHfeWG9oB3asQgA== X-Received: by 2002:a1c:4e11:: with SMTP id g17mr3170126wmh.2.1630588339135; Thu, 02 Sep 2021 06:12:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:18 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 32/36] hooks: allow callers to capture output Date: Thu, 2 Sep 2021 15:11:32 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Some server-side hooks will require capturing output to send over sideband instead of printing directly to stderr. Expose that capability. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- hook.c | 3 ++- hook.h | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hook.c b/hook.c index 169287ad152..7f93fe40dba 100644 --- a/hook.c +++ b/hook.c @@ -174,12 +174,13 @@ int run_hooks(const char *hook_name, const char *hook_path, pick_next_hook, notify_start_failure, options->feed_pipe, - NULL, + options->consume_sideband, notify_hook_finished, &cb_data, "hook", hook_name); + if (options->absolute_path) strbuf_release(&abs_path); free(my_hook.feed_pipe_cb_data); diff --git a/hook.h b/hook.h index 4e26b8d658d..a85e3e6981b 100644 --- a/hook.h +++ b/hook.h @@ -47,6 +47,14 @@ struct run_hooks_opt */ feed_pipe_fn feed_pipe; void *feed_pipe_ctx; + + /* + * Populate this to capture output and prevent it from being printed to + * stderr. This will be passed directly through to + * run_command:run_parallel_processes(). See t/helper/test-run-command.c + * for an example. + */ + consume_sideband_fn consume_sideband; }; #define RUN_HOOKS_OPT_INIT { \ From patchwork Thu Sep 2 13:11:33 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: 12471655 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 04EC1C432BE for ; Thu, 2 Sep 2021 13:13:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E324D610D2 for ; Thu, 2 Sep 2021 13:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345145AbhIBNOW (ORCPT ); Thu, 2 Sep 2021 09:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345238AbhIBNNy (ORCPT ); Thu, 2 Sep 2021 09:13:54 -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 18F9CC06114E for ; Thu, 2 Sep 2021 06:12:22 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id g18so2841876wrc.11 for ; Thu, 02 Sep 2021 06:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4gV1lGLcuTnZQvsJ5UVp7qgZPpx4EebNPaokt06b/uo=; b=AyVBJvM6JmhtvIqqNfGWPgCB8xDPdVNRHI8MbI+CIlduBh1gooUFOjUCXg/yNQvLSd wAfPR/gKd22Wi56aOaIlg/7MD+5B+zu5zWnWJ9VWEgW0TtnbHq74IyX8b1McJDlYCXLY ywld8PtMAFlPUAXnSrT7AovVVJJtJcEB14aS1CLZARIRIuOtInJoVkBW5/NYCoHW5Gau t/WkRqrsrc66UZJosud9xbV95iZ9d+lUwMP2tB32b4KjLKfJi8b88X8NP9JfZ22Qyd14 kO2GnO4yOqVML9RU2f1s+C8vpdIe7mDMkHOYxFDnobN1FGa8S3/dMJsuAob8QaJP2WXZ Dv/w== 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=4gV1lGLcuTnZQvsJ5UVp7qgZPpx4EebNPaokt06b/uo=; b=he4LDY38UdNGooGw83vjrg4l7bwOiuDB/4FqpUdiVGwrQ6ZEmW9qUz6+ifx134J09B vG5lz2AWkZ5E9kAWClE9281i6v2T7tTg4cq+YpA/PaFDAIqFNL/Wzv/fo8kLyZnYqRO6 qiYAq7lHrFnQ8xKZu/oBwx25Vt4ySDqgoq5VQgLwdTqfMK9aXOeW/GEvDGTk5B9uSKhx +s0rfSydJkuRpqw+ZY4bmG3X+mboQV+1+S77Z5rfFCqxQnr3SrT+X+we32YuL3aKcW+D kKwAyG/1ZC28Kp75IMhrG3J81uJ28UmsCnakaY5vY4pUbRuggEU0QH2VsNwViFdPi6Gi 4NLw== X-Gm-Message-State: AOAM531cge5XUWaOfgs1CDVPbz8PPFd22BQuw99Z4/VEhrubGnUQgWmw FvFCqpAUfPp1HgxxVMogNvzhymnZdyYe9A== X-Google-Smtp-Source: ABdhPJz3VSeNsmfQVixXp2oPhNRz9glIlf3vLxJeQn+74OpB/a9pIYtLKqaktKCp2dOBlNjVsLMQPg== X-Received: by 2002:a5d:4fc7:: with SMTP id h7mr3659272wrw.333.1630588340363; Thu, 02 Sep 2021 06:12:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:19 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 33/36] receive-pack: convert 'update' hook to hook.h Date: Thu, 2 Sep 2021 15:11:33 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer This makes use of the new sideband API in hook.h added in the preceding commit. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/receive-pack.c | 62 ++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index a7d03bbc7d3..31ce4ece4e7 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -937,33 +937,53 @@ static int run_receive_hook(struct command *commands, return status; } -static int run_update_hook(struct command *cmd) +static void hook_output_to_sideband(struct strbuf *output, void *cb_data) { - const char *argv[5]; - struct child_process proc = CHILD_PROCESS_INIT; - int code; + int keepalive_active = 0; - argv[0] = find_hook("update"); - if (!argv[0]) - return 0; + if (keepalive_in_sec <= 0) + use_keepalive = KEEPALIVE_NEVER; + if (use_keepalive == KEEPALIVE_ALWAYS) + keepalive_active = 1; - argv[1] = cmd->ref_name; - argv[2] = oid_to_hex(&cmd->old_oid); - argv[3] = oid_to_hex(&cmd->new_oid); - argv[4] = NULL; + /* send a keepalive if there is no data to write */ + if (keepalive_active && !output->len) { + static const char buf[] = "0005\1"; + write_or_die(1, buf, sizeof(buf) - 1); + return; + } - proc.no_stdin = 1; - proc.stdout_to_stderr = 1; - proc.err = use_sideband ? -1 : 0; - proc.argv = argv; - proc.trace2_hook_name = "update"; + if (use_keepalive == KEEPALIVE_AFTER_NUL && !keepalive_active) { + const char *first_null = memchr(output->buf, '\0', output->len); + if (first_null) { + /* The null bit is excluded. */ + size_t before_null = first_null - output->buf; + size_t after_null = output->len - (before_null + 1); + keepalive_active = 1; + send_sideband(1, 2, output->buf, before_null, use_sideband); + send_sideband(1, 2, first_null + 1, after_null, use_sideband); + + return; + } + } + + send_sideband(1, 2, output->buf, output->len, use_sideband); +} + +static int run_update_hook(struct command *cmd) +{ + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + + strvec_pushl(&opt.args, + cmd->ref_name, + oid_to_hex(&cmd->old_oid), + oid_to_hex(&cmd->new_oid), + NULL); - code = start_command(&proc); - if (code) - return code; if (use_sideband) - copy_to_sideband(proc.err, -1, NULL); - return finish_command(&proc); + opt.consume_sideband = hook_output_to_sideband; + + return run_hooks_oneshot("update", &opt); } static struct command *find_command_by_refname(struct command *list, From patchwork Thu Sep 2 13:11:34 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: 12471657 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 24EDBC432BE for ; Thu, 2 Sep 2021 13:13:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 088C46108E for ; Thu, 2 Sep 2021 13:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345252AbhIBNOZ (ORCPT ); Thu, 2 Sep 2021 09:14:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345249AbhIBNNy (ORCPT ); Thu, 2 Sep 2021 09:13:54 -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 32167C061153 for ; Thu, 2 Sep 2021 06:12:23 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id u16so2867459wrn.5 for ; Thu, 02 Sep 2021 06:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f3Aptx88VzJU4nhBaEFhaOt5AUMCXSA+aMK+eoCZ5wk=; b=EdDEM0/iOWHhKWh54jSGDqILXdakbA/aC/Afe0t/P2ozTmpiBcPKefosjixCx6np3Z rGiD71FRJ7u7KTKK+z2jWNWMDnpDEiMM7smdKPVW9TtWKTLXsKa74qNn8FYvj4cFC+90 fFsItZs3yfSUPubXAmYfw7qunDenJYToxd/lDk1M1yovYVDqstRxO44PcN33s9N2jgpg e5P3w432Owb+jKYr74rMXxKW6M1QMUdrPWZJRkyQPazg3b66R/rFQzMuMn3jEofcdZTV 2CoHcf/qQDVV7/GuCmK1WHz11zCHNB2iDrHczBW1zrf2BnEc9Clo/wDTPDji6WDYJQbu 8Dbw== 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=f3Aptx88VzJU4nhBaEFhaOt5AUMCXSA+aMK+eoCZ5wk=; b=SYfanAop2zCQ6n6g8/bq5UDBm8LJu6PfKk3UQOr++oZxyhUcVjM9Zdmz+oKsCEBYRh zzo8WeYMNyT/o0PfTGJWUW1wIBjGNyfLOsCwT+5Ae1fXmOVXGoWUHHJJBhz9VwN8ybxV Vl0neUt5iayuyCHpF4bpjwoOtdSlh4yrXbNf+qnfC5RI0dYPLuIfQDOQnqqkV/c4wiKh IAaGYVaS1PNJIkIb1JKNUzB7gOR/er8p9rQEZhhrDS3hgbSL6Xq1mf96DWh4Nm97g91t 1zvRSeFTy6MZCXjuZdevhNX9odaePukNOaQMcLZWJSUHBIyZkowjpO7nCPvIeyCmwNr9 QK9Q== X-Gm-Message-State: AOAM533Yhd5rCx/yv8gBTcmc13bYl3nohHHOist6qMpX7QQlwUnRWZlh T+yVQ+fUCFPdFRarAV24/nLgiayUTb8LOw== X-Google-Smtp-Source: ABdhPJzf+rK0axWycxdM2SBvwMwuDIAw23LmtMRc+kIpjTFXmicXQo9/kFT1kz2pKDnXJPlTj1GtmA== X-Received: by 2002:adf:c18b:: with SMTP id x11mr3774666wre.204.1630588341532; Thu, 02 Sep 2021 06:12:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:20 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 34/36] post-update: use hook.h library Date: Thu, 2 Sep 2021 15:11:34 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/receive-pack.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 31ce4ece4e7..26e302aab85 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1650,33 +1650,20 @@ static const char *update(struct command *cmd, struct shallow_info *si) static void run_update_post_hook(struct command *commands) { struct command *cmd; - struct child_process proc = CHILD_PROCESS_INIT; - const char *hook; - - hook = find_hook("post-update"); - if (!hook) - return; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; for (cmd = commands; cmd; cmd = cmd->next) { if (cmd->error_string || cmd->did_not_exist) continue; - if (!proc.args.nr) - strvec_push(&proc.args, hook); - strvec_push(&proc.args, cmd->ref_name); + strvec_push(&opt.args, cmd->ref_name); } - if (!proc.args.nr) + if (!opt.args.nr) return; - proc.no_stdin = 1; - proc.stdout_to_stderr = 1; - proc.err = use_sideband ? -1 : 0; - proc.trace2_hook_name = "post-update"; + if (use_sideband) + opt.consume_sideband = hook_output_to_sideband; - if (!start_command(&proc)) { - if (use_sideband) - copy_to_sideband(proc.err, -1, NULL); - finish_command(&proc); - } + run_hooks_oneshot("post-update", &opt); } static void check_aliased_update_internal(struct command *cmd, From patchwork Thu Sep 2 13:11:35 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: 12471675 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 A7EF4C4320A for ; Thu, 2 Sep 2021 13:13:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9065E610A0 for ; Thu, 2 Sep 2021 13:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345260AbhIBNO3 (ORCPT ); Thu, 2 Sep 2021 09:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345255AbhIBNNz (ORCPT ); Thu, 2 Sep 2021 09:13:55 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85806C061156 for ; Thu, 2 Sep 2021 06:12:24 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id v10so2856672wrd.4 for ; Thu, 02 Sep 2021 06:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ankHZBSS/hYkjRio7NRLH5yibR6bVxdcJ1bWGv5vRn8=; b=fZXorH27Fz5bAQOTlBN6jB2FMROXPMEHZvLYzQ+bhc402q5aD/wnZP2+TcH/eXWQH7 LJi/NeVWkBuMt7l9AQJspbX8K6e1xfObfOTfeGFGHuFyBFMk5qCsx0HFP0Srm+h4zhFm ghfzLOJ21YVVxHTpn43KJyrqRdaf88D9CuHVdy4kJO7iBu5KksNf95ekV9OFagYLHMGO dyHyRHAxACB/g6hyO//SLSA5RNamudcntH/70NGzKWBDWq4v/eon4d03m56y2hIN6hTY MGxnFWRbfgQR2Yo27x3G9M5ZK6qUo5A75PG/uaLh4Vx3EcN275aWaHSD28NmFwUNc5aX m27Q== 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=ankHZBSS/hYkjRio7NRLH5yibR6bVxdcJ1bWGv5vRn8=; b=LEfyvDy7kE9vP7tMMKdP1A+iz0WgLcbE50f5bJx3cNcjj2RlbLM9XyCHDUAqpKg1WG ZEndvamacwyyndolkl23XFNsY+hSIc/ynthY5+gWt9NU4GrwMVEnbwwsQdA9rLA9GaQU 4n2NoRI1BJAN0rHdvL+SimOxdyTG+jW0LIXOvdYyKFgNjGHhFe/RvOQMWy6l5j5K3cDu mlSmqtWsqpGTBwmU8tEUlVFd3luldPWGxQKAxiir0oh1YMgfH9kJUw99F6TB1YHm3mGn 91Z+67KAOuxnrUaEJh6kvpnvp4Cz+reBZKwldUe/IVKKOrDmvT+EGM+0hPwMP/RHbxu5 j4/Q== X-Gm-Message-State: AOAM532RmDK+khC/lbwdqGyE0iyTHvPvyGbJ6BsL7OYRwTJsw1GMk+fw 9o3jl4EFhjC/0ot2oJ9D8bGWsUplqxcavQ== X-Google-Smtp-Source: ABdhPJy3N2UdUmdB9qHnQABE8Mh1AO3KGYByxh0aw2kP7Xx47HOyUXY032p3YTxi6ZQQU6y8FLgBgg== X-Received: by 2002:a5d:4c89:: with SMTP id z9mr3736450wrs.290.1630588342815; Thu, 02 Sep 2021 06:12:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 35/36] receive-pack: convert receive hooks to hook.h Date: Thu, 2 Sep 2021 15:11:35 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/receive-pack.c | 190 ++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 107 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 26e302aab85..c3984680d7f 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -747,7 +747,7 @@ static int check_cert_push_options(const struct string_list *push_options) return retval; } -static void prepare_push_cert_sha1(struct child_process *proc) +static void prepare_push_cert_sha1(struct run_hooks_opt *opt) { static int already_done; @@ -771,110 +771,42 @@ static void prepare_push_cert_sha1(struct child_process *proc) nonce_status = check_nonce(push_cert.buf, bogs); } if (!is_null_oid(&push_cert_oid)) { - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT=%s", + strvec_pushf(&opt->env, "GIT_PUSH_CERT=%s", oid_to_hex(&push_cert_oid)); - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s", + strvec_pushf(&opt->env, "GIT_PUSH_CERT_SIGNER=%s", sigcheck.signer ? sigcheck.signer : ""); - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s", + strvec_pushf(&opt->env, "GIT_PUSH_CERT_KEY=%s", sigcheck.key ? sigcheck.key : ""); - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c", + strvec_pushf(&opt->env, "GIT_PUSH_CERT_STATUS=%c", sigcheck.result); if (push_cert_nonce) { - strvec_pushf(&proc->env_array, + strvec_pushf(&opt->env, "GIT_PUSH_CERT_NONCE=%s", push_cert_nonce); - strvec_pushf(&proc->env_array, + strvec_pushf(&opt->env, "GIT_PUSH_CERT_NONCE_STATUS=%s", nonce_status); if (nonce_status == NONCE_SLOP) - strvec_pushf(&proc->env_array, + strvec_pushf(&opt->env, "GIT_PUSH_CERT_NONCE_SLOP=%ld", nonce_stamp_slop); } } } +struct receive_hook_feed_context { + struct command *cmd; + int skip_broken; +}; + struct receive_hook_feed_state { struct command *cmd; struct ref_push_report *report; int skip_broken; struct strbuf buf; - const struct string_list *push_options; }; -typedef int (*feed_fn)(void *, const char **, size_t *); -static int run_and_feed_hook(const char *hook_name, feed_fn feed, - struct receive_hook_feed_state *feed_state) -{ - struct child_process proc = CHILD_PROCESS_INIT; - struct async muxer; - const char *argv[2]; - int code; - - argv[0] = find_hook(hook_name); - if (!argv[0]) - return 0; - - argv[1] = NULL; - - proc.argv = argv; - proc.in = -1; - proc.stdout_to_stderr = 1; - proc.trace2_hook_name = hook_name; - - if (feed_state->push_options) { - int i; - for (i = 0; i < feed_state->push_options->nr; i++) - strvec_pushf(&proc.env_array, - "GIT_PUSH_OPTION_%d=%s", i, - feed_state->push_options->items[i].string); - strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%d", - feed_state->push_options->nr); - } else - strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT"); - - if (tmp_objdir) - strvec_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir)); - - if (use_sideband) { - memset(&muxer, 0, sizeof(muxer)); - muxer.proc = copy_to_sideband; - muxer.in = -1; - code = start_async(&muxer); - if (code) - return code; - proc.err = muxer.in; - } - - prepare_push_cert_sha1(&proc); - - code = start_command(&proc); - if (code) { - if (use_sideband) - finish_async(&muxer); - return code; - } - - sigchain_push(SIGPIPE, SIG_IGN); - - while (1) { - const char *buf; - size_t n; - if (feed(feed_state, &buf, &n)) - break; - if (write_in_full(proc.in, buf, n) < 0) - break; - } - close(proc.in); - if (use_sideband) - finish_async(&muxer); - - sigchain_pop(SIGPIPE); - - return finish_command(&proc); -} - -static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) +static int feed_receive_hook(void *state_) { struct receive_hook_feed_state *state = state_; struct command *cmd = state->cmd; @@ -883,9 +815,7 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) state->skip_broken && (cmd->error_string || cmd->did_not_exist)) cmd = cmd->next; if (!cmd) - return -1; /* EOF */ - if (!bufp) - return 0; /* OK, can feed something. */ + return 1; /* EOF - close the pipe*/ strbuf_reset(&state->buf); if (!state->report) state->report = cmd->report; @@ -909,32 +839,36 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) cmd->ref_name); state->cmd = cmd->next; } - if (bufp) { - *bufp = state->buf.buf; - *sizep = state->buf.len; - } return 0; } -static int run_receive_hook(struct command *commands, - const char *hook_name, - int skip_broken, - const struct string_list *push_options) +static int feed_receive_hook_cb(struct strbuf *pipe, void *pp_cb, void *pp_task_cb) { - struct receive_hook_feed_state state; - int status; - - strbuf_init(&state.buf, 0); - state.cmd = commands; - state.skip_broken = skip_broken; - state.report = NULL; - if (feed_receive_hook(&state, NULL, NULL)) - return 0; - state.cmd = commands; - state.push_options = push_options; - status = run_and_feed_hook(hook_name, feed_receive_hook, &state); - strbuf_release(&state.buf); - return status; + struct hook *hook = pp_task_cb; + struct receive_hook_feed_state *feed_state = hook->feed_pipe_cb_data; + int rc; + + /* first-time setup */ + if (!feed_state) { + struct hook_cb_data *hook_cb = pp_cb; + struct run_hooks_opt *opt = hook_cb->options; + struct receive_hook_feed_context *ctx = opt->feed_pipe_ctx; + if (!ctx) + BUG("run_hooks_opt.feed_pipe_ctx required for receive hook"); + + feed_state = xmalloc(sizeof(struct receive_hook_feed_state)); + strbuf_init(&feed_state->buf, 0); + feed_state->cmd = ctx->cmd; + feed_state->skip_broken = ctx->skip_broken; + feed_state->report = NULL; + + hook->feed_pipe_cb_data = feed_state; + } + + rc = feed_receive_hook(feed_state); + if (!rc) + strbuf_addbuf(pipe, &feed_state->buf); + return rc; } static void hook_output_to_sideband(struct strbuf *output, void *cb_data) @@ -970,6 +904,48 @@ static void hook_output_to_sideband(struct strbuf *output, void *cb_data) send_sideband(1, 2, output->buf, output->len, use_sideband); } +static int run_receive_hook(struct command *commands, + const char *hook_name, + int skip_broken, + const struct string_list *push_options) +{ + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + struct receive_hook_feed_context ctx; + struct command *iter = commands; + + /* if there are no valid commands, don't invoke the hook at all. */ + while (iter && skip_broken && (iter->error_string || iter->did_not_exist)) + iter = iter->next; + if (!iter) + return 0; + + if (push_options) { + int i; + for (i = 0; i < push_options->nr; i++) + strvec_pushf(&opt.env, "GIT_PUSH_OPTION_%d=%s", i, + push_options->items[i].string); + strvec_pushf(&opt.env, "GIT_PUSH_OPTION_COUNT=%d", push_options->nr); + } else + strvec_push(&opt.env, "GIT_PUSH_OPTION_COUNT"); + + if (tmp_objdir) + strvec_pushv(&opt.env, tmp_objdir_env(tmp_objdir)); + + prepare_push_cert_sha1(&opt); + + /* set up sideband printer */ + if (use_sideband) + opt.consume_sideband = hook_output_to_sideband; + + /* set up stdin callback */ + ctx.cmd = commands; + ctx.skip_broken = skip_broken; + opt.feed_pipe = feed_receive_hook_cb; + opt.feed_pipe_ctx = &ctx; + + return run_hooks_oneshot(hook_name, &opt); +} + static int run_update_hook(struct command *cmd) { struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; From patchwork Thu Sep 2 13:11:36 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: 12471677 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 85938C432BE for ; Thu, 2 Sep 2021 13:13:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FD25610D2 for ; Thu, 2 Sep 2021 13:13:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345367AbhIBNOe (ORCPT ); Thu, 2 Sep 2021 09:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345262AbhIBNN4 (ORCPT ); Thu, 2 Sep 2021 09:13:56 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20404C06115A for ; Thu, 2 Sep 2021 06:12:26 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id g18so2842225wrc.11 for ; Thu, 02 Sep 2021 06:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XOtL05/pqyZyFAu4+5PIVWUzJUsUsAULye5SJmvxWbE=; b=bGTxvHu9vdjsT7PQDtdaBkm+Z9KXj8qs5tEkg65vQmQKaCNR4WEQJlSnumwM6RLswe Q+sO4I5+6LUJodD86izbEcMj2aJuS8f8TSqQrFEznDm1RgnWKJVq22SxZ/VcQfNbbAn7 sT/o9uXDNL2lo101vfQSazFq6/R2VUQaEOiN2hwj3UlJd3W3ugGVSpuK6TthYSAspu10 LtYlD1wxNRpEXH7B4QgYt7TtnpVh0rYtRgdBhu+Pwv4m90sYeae4rfr8uNSMzeBrliSr dcFI/zeq9UuaU6wseoMcYXFPzb7qmAHHotKA6GR1mD/KK9J2tNJJG5Q7g9/UDmGwtHUm Ff8w== 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=XOtL05/pqyZyFAu4+5PIVWUzJUsUsAULye5SJmvxWbE=; b=n1ePf19e2RqJm4uzzc+/Qi9zZV9oTBkgmBtAQeW58z+F9mOUY7DkH01FaA+vQzQSzx zVy1eLEUn13X58TLp0abPlSqlMq721utztBEV5N4Jn3lYhVYuvX0YJNK+rfRnwZCuWH2 H/aHU7Cqvh2KvsGx2SwjKB0pNEv4eDHYC7Mx68RCSEcYu5p8W9jVIj8vgBxyT6Ge4XPc Wdurxbe6zslhN+2QMPs20iHJaD2eiDERDd0J6xG2jAROVO9FSbDz0eHWUhWuQFC/QCcM 6tq2/KZCUy38fMwUln+D+WIHO/Q+Ste8Ta7Z92k+nTiLGHnp3Sk4LuA2/JQOYfz0KSXz rkag== X-Gm-Message-State: AOAM533wnUfaENzL92LSUZtXZSkRoxAh0SKImOJpr0YxKAuGO2QR6v9b HIXjlQk+uJK4+xwQfVGL6NpPNqFA8u/5hQ== X-Google-Smtp-Source: ABdhPJwBay6OYBSewoz5ULfapFi2yfHMhEO6JroJtUfPU+no6JHUt+0VgUu7Le6oO6u3ZBYnZB35Hw== X-Received: by 2002:a5d:6286:: with SMTP id k6mr3587645wru.103.1630588344291; Thu, 02 Sep 2021 06:12:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o7sm1479635wmq.36.2021.09.02.06.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:12:23 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King , Taylor Blau , Felipe Contreras , Eric Sunshine , "brian m . carlson" , Josh Steadmon , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 36/36] hooks: fix a TOCTOU in "did we run a hook?" heuristic Date: Thu, 2 Sep 2021 15:11:36 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.816.g1ba32acadee In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a Time-of-check to time-of-use (TOCTOU) race in code added in 680ee550d72 (commit: skip discarding the index if there is no pre-commit hook, 2017-08-14). We can fix the race passing around information about whether or not we ran the hook in question, instead of running hook_exists() after the fact to check if the hook in question exists. This problem has been noted on-list when 680ee550d72 was discussed[1], but had not been fixed. In addition to fixing this for the pre-commit hook as suggested there I'm also fixing this for the pre-merge-commit hook. See 6098817fd7f (git-merge: honor pre-merge-commit hook, 2019-08-07) for the introduction of its previous behavior. Let's also change this for the push-to-checkout hook. Now instead of checking if the hook exists and either doing a push to checkout or a push to deploy we'll always attempt a push to checkout. If the hook doesn't exist we'll fall back on push to deploy. The same behavior as before, without the TOCTOU race. See 0855331941b (receive-pack: support push-to-checkout hook, 2014-12-01) for the introduction of the previous behavior. This leaves uses of hook_exists() in two places that matter. The "reference-transaction" check in refs.c, see 67541597670 (refs: implement reference transaction hook, 2020-06-19), and the prepare-commit-msg hook, see 66618a50f9c (sequencer: run 'prepare-commit-msg' hook, 2018-01-24). In both of those cases we're saving ourselves CPU time by not preparing data for the hook that we'll then do nothing with if we don't have the hook. So using this "invoked_hook" pattern doesn't make sense in those cases. More importantly, in those cases the worst we'll do is miss that we "should" run the hook because a new hook appeared, whereas in the pre-commit and pre-merge-commit cases we'll skip an important discard_cache() on the bases of our faulty guess. I do think none of these races really matter in practice. It would be some one-off issue as a hook was added or removed. I did think it was stupid that we didn't pass a "did this run?" flag instead of doing this guessing at a distance though, so now we're not guessing anymore. 1. https://lore.kernel.org/git/20170810191613.kpmhzg4seyxy3cpq@sigill.intra.peff.net/ Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit.c | 18 +++++++++++------- builtin/merge.c | 16 ++++++++++------ builtin/receive-pack.c | 8 +++++--- commit.c | 1 + commit.h | 3 ++- hook.c | 4 ++++ hook.h | 10 ++++++++++ sequencer.c | 4 ++-- 8 files changed, 45 insertions(+), 19 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index f6ca9d04c78..986146e3205 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -725,11 +725,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix, int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE); int old_display_comment_prefix; int merge_contains_scissors = 0; + int invoked_hook = 0; /* This checks and barfs if author is badly specified */ determine_author_info(author_ident); - if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL)) + if (!no_verify && run_commit_hook(use_editor, index_file, &invoked_hook, + "pre-commit", NULL)) return 0; if (squash_message) { @@ -1052,10 +1054,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 0; } - if (!no_verify && hook_exists("pre-commit")) { + if (!no_verify && invoked_hook) { /* - * Re-read the index as pre-commit hook could have updated it, - * and write it out as a tree. We must do this before we invoke + * Re-read the index as the pre-commit-commit hook was invoked + * and could have updated it. We must do this before we invoke * the editor and after we invoke run_status above. */ discard_cache(); @@ -1067,7 +1069,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 0; } - if (run_commit_hook(use_editor, index_file, "prepare-commit-msg", + if (run_commit_hook(use_editor, index_file, NULL, "prepare-commit-msg", git_path_commit_editmsg(), hook_arg1, hook_arg2, NULL)) return 0; @@ -1084,7 +1086,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, } if (!no_verify && - run_commit_hook(use_editor, index_file, "commit-msg", git_path_commit_editmsg(), NULL)) { + run_commit_hook(use_editor, index_file, NULL, "commit-msg", + git_path_commit_editmsg(), NULL)) { return 0; } @@ -1843,7 +1846,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) repo_rerere(the_repository, 0); run_auto_maintenance(quiet); - run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); + run_commit_hook(use_editor, get_index_file(), NULL, "post-commit", + NULL); if (amend && !no_post_rewrite) { commit_post_rewrite(the_repository, current_head, &oid); } diff --git a/builtin/merge.c b/builtin/merge.c index ca9b3ba4827..f215f264cc8 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -844,15 +844,18 @@ static void prepare_to_commit(struct commit_list *remoteheads) { struct strbuf msg = STRBUF_INIT; const char *index_file = get_index_file(); + int invoked_hook = 0; - if (!no_verify && run_commit_hook(0 < option_edit, index_file, "pre-merge-commit", NULL)) + if (!no_verify && run_commit_hook(0 < option_edit, index_file, + &invoked_hook, "pre-merge-commit", + NULL)) abort_commit(remoteheads, NULL); /* - * Re-read the index as pre-merge-commit hook could have updated it, - * and write it out as a tree. We must do this before we invoke + * Re-read the index as the pre-merge-commit hook was invoked + * and could have updated it. We must do this before we invoke * the editor and after we invoke run_status above. */ - if (hook_exists("pre-merge-commit")) + if (invoked_hook) discard_cache(); read_cache_from(index_file); strbuf_addbuf(&msg, &merge_msg); @@ -875,7 +878,8 @@ static void prepare_to_commit(struct commit_list *remoteheads) append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0); write_merge_heads(remoteheads); write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len); - if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg", + if (run_commit_hook(0 < option_edit, get_index_file(), NULL, + "prepare-commit-msg", git_path_merge_msg(the_repository), "merge", NULL)) abort_commit(remoteheads, NULL); if (0 < option_edit) { @@ -884,7 +888,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) } if (!no_verify && run_commit_hook(0 < option_edit, get_index_file(), - "commit-msg", + NULL, "commit-msg", git_path_merge_msg(the_repository), NULL)) abort_commit(remoteheads, NULL); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index c3984680d7f..ebec6f3bb10 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1428,10 +1428,12 @@ static const char *push_to_deploy(unsigned char *sha1, static const char *push_to_checkout_hook = "push-to-checkout"; static const char *push_to_checkout(unsigned char *hash, + int *invoked_hook, struct strvec *env, const char *work_tree) { struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + opt.invoked_hook = invoked_hook; strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); strvec_pushv(&opt.env, env->v); @@ -1446,6 +1448,7 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w { const char *retval, *work_tree, *git_dir = NULL; struct strvec env = STRVEC_INIT; + int invoked_hook = 0; if (worktree && worktree->path) work_tree = worktree->path; @@ -1463,10 +1466,9 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); - if (!hook_exists(push_to_checkout_hook)) + retval = push_to_checkout(sha1, &invoked_hook, &env, work_tree); + if (!invoked_hook) retval = push_to_deploy(sha1, &env, work_tree); - else - retval = push_to_checkout(sha1, &env, work_tree); strvec_clear(&env); return retval; diff --git a/commit.c b/commit.c index 63d7943a86d..842e47beae2 100644 --- a/commit.c +++ b/commit.c @@ -1697,6 +1697,7 @@ size_t ignore_non_trailer(const char *buf, size_t len) } int run_commit_hook(int editor_is_used, const char *index_file, + int *invoked_hook, const char *name, ...) { struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; diff --git a/commit.h b/commit.h index df42eb434f3..b5a542993c6 100644 --- a/commit.h +++ b/commit.h @@ -363,7 +363,8 @@ int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused) int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused); LAST_ARG_MUST_BE_NULL -int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...); +int run_commit_hook(int editor_is_used, const char *index_file, + int *invoked_hook, const char *name, ...); /* Sign a commit or tag buffer, storing the result in a header. */ int sign_with_header(struct strbuf *buf, const char *keyid); diff --git a/hook.c b/hook.c index 7f93fe40dba..d045379ade8 100644 --- a/hook.c +++ b/hook.c @@ -144,6 +144,9 @@ static int notify_hook_finished(int result, hook_cb->rc |= result; + if (hook_cb->invoked_hook) + *hook_cb->invoked_hook = 1; + return 0; } @@ -158,6 +161,7 @@ int run_hooks(const char *hook_name, const char *hook_path, .rc = 0, .hook_name = hook_name, .options = options, + .invoked_hook = options->invoked_hook, }; int jobs = 1; diff --git a/hook.h b/hook.h index a85e3e6981b..f6dac75f1cc 100644 --- a/hook.h +++ b/hook.h @@ -55,6 +55,15 @@ struct run_hooks_opt * for an example. */ consume_sideband_fn consume_sideband; + + /* + * A pointer which if provided will be set to 1 or 0 depending + * on if a hook was invoked (i.e. existed), regardless of + * whether or not that was successful. Used for avoiding + * TOCTOU races in code that would otherwise call hook_exist() + * after a "maybe hook run" to see if a hook was invoked. + */ + int *invoked_hook; }; #define RUN_HOOKS_OPT_INIT { \ @@ -68,6 +77,7 @@ struct hook_cb_data { const char *hook_name; struct hook *run_me; struct run_hooks_opt *options; + int *invoked_hook; }; /** diff --git a/sequencer.c b/sequencer.c index 549b583b277..db8044ab47d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1203,7 +1203,7 @@ static int run_prepare_commit_msg_hook(struct repository *r, } else { arg1 = "message"; } - if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name, + if (run_commit_hook(0, r->index_file, NULL, "prepare-commit-msg", name, arg1, arg2, NULL)) ret = error(_("'prepare-commit-msg' hook failed")); @@ -1533,7 +1533,7 @@ static int try_to_commit(struct repository *r, goto out; } - run_commit_hook(0, r->index_file, "post-commit", NULL); + run_commit_hook(0, r->index_file, NULL, "post-commit", NULL); if (flags & AMEND_MSG) commit_post_rewrite(r, current_head, oid);