From patchwork Tue Aug 3 19:38: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: 12417187 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.8 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 7785FC4338F for ; Tue, 3 Aug 2021 19:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AD9D61037 for ; Tue, 3 Aug 2021 19:39:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240161AbhHCTjZ (ORCPT ); Tue, 3 Aug 2021 15:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240073AbhHCTjZ (ORCPT ); Tue, 3 Aug 2021 15:39:25 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048F7C06175F for ; Tue, 3 Aug 2021 12:39:13 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id b11so21163564wrx.6 for ; Tue, 03 Aug 2021 12:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nGhfhM2StsDZotV0FH96QboWHkMW3lg3Gbh/P4LPikg=; b=oXDjKUkq9Sc5OdRpLy8Zpm2aIJUNT0vsWSqy+jbieGBQQlwMGDaPkSfdLrhBpKj4n5 zrU5pu+ty44c1/IZgol8cUDpHDhFIiaLu4eF/abSP/R7Z3+q/F4767CVs3z/kO11BKUk KSvj7FbJlCDMnMsZJrdq0yneUTmbaSQETkGVPHTHpdo5JxtRQ+Nw8thpW9idxb2QehGZ VyX1S9p34MH1hr7MAhRWfZakuFweg2Xo77/CPEyjBPi5yXOarmFKRA/NLx8vcd8hHIrN sZ790HhjVanajlrNL1Fre2BDEEkMnkSseU2VgjsVkM3nAekVJUWyAWWeS6kFg2NMauL9 wX0g== 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=nGhfhM2StsDZotV0FH96QboWHkMW3lg3Gbh/P4LPikg=; b=IUIPu01RqxdMHwvpyqgAO4alQfJ9yZg/C9upPHocKSyxkFpNgw7xqyIOEpeUNw6zwV CZtzXzIVlqlZp6jThuDZUulF0nC5qI/38E8bPhgdS1jAftuF0rHINgRY0QX/ADPzfQri ui1AmNLxi/VwmpGCLBnoPwGSN/yBDmsZDOZQKfWzS1a76smpU9nBg2r31VwjSH9XvfaU LEIgukTbBs1jdd0EyavZu5L6BpcGgV/Egzu9Zch2Sj1O+6lywH4nD5NZafqkGO77LxKN zgPI918D6V0bVXUq6f+ArF1cK4uAsVKBKnGwaIje4uTCtPMM8F82XvNOmjg7qMWBLAPY j1mw== X-Gm-Message-State: AOAM5323AWImdd5Rk6XgMj+mGsBKYD4pcrHFJiHM98m5iAxcARuDwu0l nlt3/ZkFjgSdJco1JlaEkrhkfngg63aqVQ== X-Google-Smtp-Source: ABdhPJzuU2KWGtjpT1SR+Q/Zt8nSe1aBi5dcgTeQTPYNCoBg4gTs/yfFcc5muH0nGreNe32uGNujbg== X-Received: by 2002:a5d:526a:: with SMTP id l10mr25384792wrc.40.1628019551142; Tue, 03 Aug 2021 12:39:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:10 -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 v4 01/36] Makefile: mark "check" target as .PHONY Date: Tue, 3 Aug 2021 21:38:27 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Reviewed-by: Emily Shaffer --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index c6f6246bf63..2ff038069e8 100644 --- a/Makefile +++ b/Makefile @@ -2931,6 +2931,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 Tue Aug 3 19:38: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: 12417189 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.8 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 F01CFC4320E for ; Tue, 3 Aug 2021 19:39:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D941260EE8 for ; Tue, 3 Aug 2021 19:39:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240164AbhHCTj1 (ORCPT ); Tue, 3 Aug 2021 15:39:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240160AbhHCTjZ (ORCPT ); Tue, 3 Aug 2021 15:39:25 -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 19228C061764 for ; Tue, 3 Aug 2021 12:39:14 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id d8so26473919wrm.4 for ; Tue, 03 Aug 2021 12:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p6Egb8vZeS6l9iQjRvmtuI6xE6Lpzpw0QjroqTZSFJc=; b=sGHDojD6Jj/w+ETJksTmInALaJDdW8u6IHm2QJEDKCqpntX5uu4R8w5LUHfgIkSWFv +WKrinJaveAxok05UY+7yhn9Tol26C6t/tHePdlCsViZh+jZ52UH8sWqKD+UMlnhk6+L JsJ9dJaAHFzAPm2rAwYxkox4J3pqVaaF3lS3Le/zVLxnMkm9R+GZ7ECCjU1Mi3UTfYbA q4VOFgW6S4lpG2FN3HILfsiYYnKa628ArK1nAyolzF9Euvc+VAYio6qHX517Vyj+vqzQ jLBxeQIS1zTxIYaF1jNRtoSwq/IveQg7Cj354KE7LI1PF94vo9B0eh2/lYu9uFRaj2MW 8b8g== 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=p6Egb8vZeS6l9iQjRvmtuI6xE6Lpzpw0QjroqTZSFJc=; b=HQxY4cgJIU3wBORWUU54hAhnLxyc0qY11iCavSOqi7yuBNJ8xBUTJ6zlC2qihqieIt tJjSNVi3DNH+u49scCKmvL53kmFHyLjBGQlS1BGUCXd+X/+LCQJ9f/UkktuHP8qJEBcs ck38ugzdiaf4xOT0/JdYrqZxs24RMIaoMBIA481mANJs+yUI4vb3KswW6xHSYfoqR4sq 0LPLYpEP4jh+5pAeKJi1XQOi/vOIXkG0FHEgJL+Llf62V3VauywFdH5NfqiJTp6XOcZN YvsHSXmnVJz3WnRRMGlQdc2l1fcZZKJzd3Ra1HPfa0jQWIveFOEPgua1LI3UHu2ghIHD rx4w== X-Gm-Message-State: AOAM531A/rT6OEz7vmjPy+lTF7cx4nI7Z3V2ZZPmQXheHULnbNcbg+3c uXX0xXcB/lI/rKJ3UbhBLkp5diL+HfjLkg== X-Google-Smtp-Source: ABdhPJx+YWf8gC+8z61QHoD2byumHNoW6mgb5fD7a/FwZ+xmMiYUA8IsFw2xOhctNHgY7bCSdcjzXg== X-Received: by 2002:a5d:49c1:: with SMTP id t1mr22260648wrs.141.1628019552443; Tue, 03 Aug 2021 12:39:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 02/36] Makefile: stop hardcoding {command,config}-list.h Date: Tue, 3 Aug 2021 21:38:28 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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. I have not tested the Windows-specific change in config.mak.uname being made here, but we use other variables from the Makefile in the same block, and the GENERATED_H is fully defined before we include config.mak.uname. 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 Reviewed-by: Emily Shaffer --- Makefile | 6 ++++-- compat/vcbuild/README | 2 +- config.mak.uname | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 2ff038069e8..89bf0dd7332 100644 --- a/Makefile +++ b/Makefile @@ -823,6 +823,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) . \ @@ -2909,7 +2911,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 @@ -2932,7 +2934,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 69413fb3dc0..9988378160b 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -732,9 +732,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 Tue Aug 3 19:38: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: 12417193 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.8 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 0F311C4338F for ; Tue, 3 Aug 2021 19:39:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E237560EE8 for ; Tue, 3 Aug 2021 19:39:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240179AbhHCTjc (ORCPT ); Tue, 3 Aug 2021 15:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240162AbhHCTj1 (ORCPT ); Tue, 3 Aug 2021 15:39:27 -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 E5754C061757 for ; Tue, 3 Aug 2021 12:39:14 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id m12so21698688wru.12 for ; Tue, 03 Aug 2021 12:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tvoPSieD9ctzfcwINzAJ0zt1YDPrk7OA+CqjlRPDqZo=; b=eGpOSVafo7IuoTjTxzMWrs/evvBVhHKa2Qm/3QE2ZVEpMOs30VPuchzaugO6rvCHP1 oP72deD3LqGOiS68GrjtEic2p8SS19oxP1SKV09p1rukcEzBLLcoovOBMyUwwccumN8d jHXDJgUQDYrqCefTH0zwPOUwRqLlDOyfVie6NEvHTeqjxCDwBnQSFhAy3vZ/dBQOBa/5 jt6Rw48KukDmoSB5LJegzXA78oAzApbPMJrzTMNPpgPaL5/ZZoRvzWsJkeIc2jAxrUeL VtfHOCoXrgWclVk9Oy2rlNEwleukUlwLj7BhHZ3Nmfs8DFv+SMGTw0uMFVyYBDxnLSCf gjjg== 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=tvoPSieD9ctzfcwINzAJ0zt1YDPrk7OA+CqjlRPDqZo=; b=bjWl2r4bzrQnkxL3LgZbxDGB6SDtoBMj/9ZwyVF4Vg07sDEHPe1arKuOeU93hOHHok A0C7wY5wzAwxvIgh9q5pE6eywxQGiqWM06TqFI4KHeAbOSW1CgittPly/M9Rb02NXgOT VkJjyeiCWYvuK4yj1wcqJuCfm/GjdAdII59GoYdoO/sjJcXhX6+P8uRBvMNT9Z+uChAo CrgG0DU9nsHXmxrntcwakKu8xAJVQ7ZFe6B2Mpb32P8d1Ezehzb47avYG3ybBcGTfj0D CNoquM+YIuTldr3czIpu1XfFeGv2+loMoPddVYyezvJRhPoWCm3Ky69lqUgV59lrC1DT kAeQ== X-Gm-Message-State: AOAM530tSLA/9K+E7mlB/0iU+hudIXMh70lrtrbhL7U7lo4SuFZn0/mV XFC1TWFW3L+CzhF0KUTtL2VO6MzNLftPUw== X-Google-Smtp-Source: ABdhPJyDo2WEgBSUsZPonjANdIPtSRS+jU9grWEaWl3L80RlLc0PrRjTZo6aekQ4fM+U9YoeQbjtkg== X-Received: by 2002:a5d:5111:: with SMTP id s17mr24277625wrt.227.1628019553291; Tue, 03 Aug 2021 12:39:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 03/36] Makefile: remove an out-of-date comment Date: Tue, 3 Aug 2021 21:38:29 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Reviewed-by: Emily Shaffer --- Makefile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Makefile b/Makefile index 89bf0dd7332..0a540dcd34e 100644 --- a/Makefile +++ b/Makefile @@ -2519,13 +2519,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 Tue Aug 3 19:38: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: 12417195 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.8 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 A1F62C4320A for ; Tue, 3 Aug 2021 19:39:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FB9360EE8 for ; Tue, 3 Aug 2021 19:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240140AbhHCTjd (ORCPT ); Tue, 3 Aug 2021 15:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240160AbhHCTj2 (ORCPT ); Tue, 3 Aug 2021 15:39:28 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79BBC0613D5 for ; Tue, 3 Aug 2021 12:39:15 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id n12so26503474wrr.2 for ; Tue, 03 Aug 2021 12:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6n9vsKuIaIWpG08Ft3EMnUp12AWDVPMX5xaYdaeiPec=; b=QrtnBX+JbDqO4Pg02PBUcIXFKsvio8rawS9gP2EpAQDGzkzzSteqNzb+1zNI1iZerp tSwpHPtp7dAdXJGRrHFvre2ghe2o5GSTKF3Qkzak05Uz0n+3BKZxvbN54oAfzRxr3+Nh SECX2cZZtt0Nxv4gxuydbb2Jsl188RoVXUjf84oY+Q9JAD9rQZE3jWzJhT0oxG/l+DAK I57gmNuPVHwY0Iwp3oMmmV9lKos1er4lWefDEvrcnLrssbtjsSEkghqSc6qg9lqukrhN 2j9iyS5JpkeuIXbFpDJNyUXTYEgAZMhRP2SOp20qeE276CM3HDVHW7s3Xj3D+49IdbgC uc7g== 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=6n9vsKuIaIWpG08Ft3EMnUp12AWDVPMX5xaYdaeiPec=; b=aUOScueRg9u2RB9gX+1atqeic2ehTcIHDsuhGfZsXjFVxarBQdMdH6WuQiCIQEth8G qs0tcqNvzSsEN/zw9rhrwMvrF2ajkyFVArz86XXYCsON1CFnLv+xWxq0mc65WHtISq6J whtE8xfc8OkasJb3RmlWjOSGLUO89MZ6pgnccSyTdfPHnURfxuPqipcdhVodCRYAY0SN ejjvmXPpd8EiwR1K4IZadb2+Z13Rm8LJBS+qmD5A2k11RzShShyJQsbuwYr6sB2XUw0C q+Sw6SC3AeY1Y4OTFnRFE6Kz6ogPMbmnQZf/SxHHvW38Z2BIrCmymRypTZvN75LK+Bn2 wsqg== X-Gm-Message-State: AOAM533VeaS4zx2FYwXHEiM7k2VkQ3Jr2yXNeg6IfJNeNh9zEJcGDcBj U7U5CX8oQzbaiIvl3d8WXM8uHuENdAx95w== X-Google-Smtp-Source: ABdhPJxPuE7GDAUq78llBk2gRHmEJ4UujTeZ0tZlTTl4raNELYaaavfMiIZ0Hgrii6PBrH0LoAhMKw== X-Received: by 2002:a5d:504d:: with SMTP id h13mr22817344wrt.132.1628019554201; Tue, 03 Aug 2021 12:39:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:13 -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 v4 04/36] hook.[ch]: move find_hook() to this new library Date: Tue, 3 Aug 2021 21:38:30 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 0a540dcd34e..bc258886904 100644 --- a/Makefile +++ b/Makefile @@ -910,6 +910,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 7436262aae2..51b07ee02ea 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 a8a843b1f54..be98d66b0a8 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..68624f16059 --- /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 and run_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 7f07cd00f3f..ea4199d65a4 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 Tue Aug 3 19:38: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: 12417197 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.8 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 01994C4338F for ; Tue, 3 Aug 2021 19:39:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE68060BD3 for ; Tue, 3 Aug 2021 19:39:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240169AbhHCTjg (ORCPT ); Tue, 3 Aug 2021 15:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240170AbhHCTj3 (ORCPT ); Tue, 3 Aug 2021 15:39:29 -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 97EFCC061799 for ; Tue, 3 Aug 2021 12:39:16 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id j2so26426117wrx.9 for ; Tue, 03 Aug 2021 12:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WLtLR+JR4AprRu5HSIwBSpPnrCTD6gpOxNukHQY/1+A=; b=mso/6H4w8Vo536aErloaRy+KMsD54AOY5woo05cOhO2yGL+La3gJ1Ryx1uUHIvMaQE 82rgxHuNV+LiS5UhkzeyfxuYjub3HeqncsghB83pr9BRvMOAg3KgFkGjjr9w6FYO0KMO 2kTD1T1yJvJkIsjbJivLCN6Ptx+DrfJBm2Mr52KbuBEH3cbh5DKdyAXkAvzvdyhz9vpo aESdN+mYn575Sb6mukClfrOfEksNGXkj/xCYyqZlxVone0xAWjcJBCVp+Z9WL3Jt/l1V DX/q8P5ZImXT7BLz0tO2kX+xsaga5ahnBnln0zkuuzRX8p5Mt4vSQ4TYg8OL3/Ezz6iN rDYQ== 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=WLtLR+JR4AprRu5HSIwBSpPnrCTD6gpOxNukHQY/1+A=; b=j9OA1BDrwFWzfkqv3sq45yKejGDtubaJ9UHfESrfb2+gesN2oryNiwfA5K0YEDn8da 8lpqRyv4NuCbNxuixi+KUItVO4Ixall3GaocqVrZ+VOX5P4PshxsaIc6/suJVkjkr2+v g0YGNMOa8UzI7Vf4D2RZpybMJQjAHS5yhSZnoauaFfxSzX3LGqVz560HT6PQG9RJQV40 TbrBepai0bQV4rD4pnsmvqQ9H73pffmtipV1SxkbEDjhLpuE5ewe5lr21j8DwMOm+DLh et5outy2y0TnBV8YcPDeXjTgBkmvSIdZ/oPhpfGGCx7/Xus4pf5hv1DDa4zLgcypNq9N Nvzg== X-Gm-Message-State: AOAM532llgIe23LNAvR8kkbq6b+DQB7KdSM8BdmQ+Ldq/Yv7scBsPDRh PK7n9m94F/gIjtOxIPYv5in7GpqMy3a2Cw== X-Google-Smtp-Source: ABdhPJysfZLt3biaOEijL5i3rCACJNULMy7hL0M4QxNwiTfO7xUdroGhtURtX5m3xLUAXEO9NqJjNg== X-Received: by 2002:a5d:6b8f:: with SMTP id n15mr24418432wrx.103.1628019555002; Tue, 03 Aug 2021 12:39:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 05/36] hook.c: add a hook_exists() wrapper and use it in bugreport.c Date: Tue, 3 Aug 2021 21:38:31 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 68624f16059..4c547ac15e5 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 Tue Aug 3 19:38: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: 12417201 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.8 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 88C9FC4338F for ; Tue, 3 Aug 2021 19:39:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70FD460EE8 for ; Tue, 3 Aug 2021 19:39:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240186AbhHCTji (ORCPT ); Tue, 3 Aug 2021 15:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240162AbhHCTjc (ORCPT ); Tue, 3 Aug 2021 15:39:32 -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 7ECF7C061764 for ; Tue, 3 Aug 2021 12:39:17 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id l34-20020a05600c1d22b02902573c214807so2450337wms.2 for ; Tue, 03 Aug 2021 12:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j9lSSGf1sv0qQkCQL0QsZf8Dse1H0w03hbA91D+KFGw=; b=dU2p1UCDraw0V/AjLaYPoax4Cw+nQcDG2ILo3mSlbv0QLvUT58R8c78ePrqc/GsYGV uctkeAX/o8a/R/aGu4HJkwITySgocNbWxt3B55Xrkx9cEWSCCkYG/1zvZZVfUESCPO06 +J86d+WR5U8s13x+u528Uzcdv6nL+gvNw2Nz4Tfzc+5W9bPt0c44Hl7M7k5M92cfPhpp 9GPDJK9QOMG3m3huMDFzVqqJRVRVPDmbR+pfGx3yVrMlzzpspzFGxDNucVOlLVAWKjWG TYZuXOGSAqKp+bnn33NERFADmSOm+NXgAAGnEqob0bObJ58Q7jTOY1FfpKT+OZDWtO0w tV2g== 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=j9lSSGf1sv0qQkCQL0QsZf8Dse1H0w03hbA91D+KFGw=; b=BJYLwMz/CkQ1pYUV7AC5Oc/xIkdTbteRO/jsgty5e6JEN7zVTXv+HcwPhZzQdgPnlf leev8tqM9x2dsy42S15qJu4clw2xa2Oo2hoDTzTyKQaOV94iYlrTII90qiZs8UaXrfCS Wpheyz2e1fH9PoyzXW+MlHJrbB3SUtu/0au0H5MjkcmRjvcSbLBoyMg0bvSYTHpgxT0e vqyFlcw2ilmH/o5tcS7mp493BESRJwt+qVSvhGvpg7x6Cb39u53/hPqqmG2JdaLNw2gi uy5MvNA7WsD/vFHzp1EkiEYaRHRNkPneMpaBk1jRTcyoxtHXhDyTAS9tQI9kpzFI2bKW /dyw== X-Gm-Message-State: AOAM5319Y4hIMJH1zCykV5FyQubI3kPJ2xob8sNXS0L3mMacequg1gaN MM2KIqNirazbpgi0cgCvvBtmnrxNhHjdIA== X-Google-Smtp-Source: ABdhPJzD8u8MbFPpbQhc2TGdolG2dS2VfESvPCkC+MU80Rg4Yj5mMlNyoaAQGV/LOygp4Oor3e8aDw== X-Received: by 2002:a05:600c:4103:: with SMTP id j3mr24430582wmi.12.1628019555873; Tue, 03 Aug 2021 12:39:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:15 -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 v4 06/36] hook.c users: use "hook_exists()" insted of "find_hook()" Date: Tue, 3 Aug 2021 21:38:32 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Reviewed-by: Emily Shaffer --- 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 51b07ee02ea..aa3c741efa9 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 be98d66b0a8..03f244dd5a0 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -849,7 +849,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 ea4199d65a4..9aac08c1545 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 Tue Aug 3 19:38: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: 12417199 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.8 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 16D5FC4320A for ; Tue, 3 Aug 2021 19:39:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 023BE60BD3 for ; Tue, 3 Aug 2021 19:39:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240160AbhHCTjh (ORCPT ); Tue, 3 Aug 2021 15:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240180AbhHCTjc (ORCPT ); Tue, 3 Aug 2021 15:39:32 -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 998CCC06179F for ; Tue, 3 Aug 2021 12:39:18 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id n12-20020a05600c3b8cb029025a67bbd40aso2477282wms.0 for ; Tue, 03 Aug 2021 12:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lRk0MGLktbzJCc0V9oecVeu57BoPU490W6nuOv4B+Nk=; b=qNTw00H6HMDXQr+Q46eOkCkG1ffNV5Dx/kPlcHFln6AdUJoKHpWZjS8kAs+HhOIfXR mXmofZ4xdhVBJamPgfoDOMIQbuwEYKQdUcpbIiPc9JTbppiUPFYq3JAVDmOyjbV3yVX8 SOrk5ldm4J43tdesd72A1ixzGguC2y+IIdPc4ctdnjbOik2Ia4vZ6s08wW0bGVT3p+/8 ESBjxcVs93KSQSGW23NhRgjpEiQcJYs6Ljj48nTCBBrZgOb8YLKBf6jp0w4a28ofnI3t AwAppIvH8e0hJrZpioP++rGlmZLR/mMIYf0gqUAtJbe426xJL1me4Ybkskg+sXmdO6v4 YVpg== 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=lRk0MGLktbzJCc0V9oecVeu57BoPU490W6nuOv4B+Nk=; b=oxLbku6xrZMqmIjjNeVHarDUKRbWWHj4GwsjrihxYbepP3CEv2smb9xyqzzv3e/yzF AqcOEMTgW8WOkUeAnRMUEoSYe0MiNZ1I4rlQj9ywC0YKZnNRYhEu0w2z6XcUxdSo77Uz hIlMyGP5/jejZADXOTTRDJz4DTJaz9IAZlfwVD5t6PcwISACOVo9XHgEU8C1TnGHULv7 7lBsgwW8as5TBZYj+bAEx0UDs79xI20RQxvdlfMXbpJCHBJUekIOSFYWbZbyqUi/g9r4 S8gRB/HUrLGcl4JDcvUyfwH5W9DD3hidddLalc6Wq/kNhWxo3a0wa8fRiFaJsB+wrYDa 1xoQ== X-Gm-Message-State: AOAM5318c9JClTGGpaW4DskBOBI7+rlv1aLBcS4DCTNx+jNdBAOMB3cr dunvocqdcZS7sWQR9YclBsGzL55eLSmwCw== X-Google-Smtp-Source: ABdhPJz7qDIl6dGbG1qbAkcKetI8Hm6jnw7rWr4IBdlB3zPxzXq/ugqCW04EaDrJFThD5/w+rJxM1w== X-Received: by 2002:a05:600c:2dd0:: with SMTP id e16mr23894360wmh.113.1628019556816; Tue, 03 Aug 2021 12:39:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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=?= , =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH v4 07/36] hook-list.h: add a generated list of hooks, like config-list.h Date: Tue, 3 Aug 2021 21:38:33 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 die 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. 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 ++++++++++++ hook.c | 19 +++++++++++++ 6 files changed, 62 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 bc258886904..1740b99db00 100644 --- a/Makefile +++ b/Makefile @@ -823,6 +823,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) @@ -2226,7 +2228,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)"' \ @@ -2259,6 +2263,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: 12417203 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.8 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 14705C432BE for ; Tue, 3 Aug 2021 19:39:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7F6D60EE8 for ; Tue, 3 Aug 2021 19:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240202AbhHCTjj (ORCPT ); Tue, 3 Aug 2021 15:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240163AbhHCTjc (ORCPT ); Tue, 3 Aug 2021 15:39:32 -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 1B2EAC0617A3 for ; Tue, 3 Aug 2021 12:39:20 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id o7-20020a05600c5107b0290257f956e02dso2453833wms.1 for ; Tue, 03 Aug 2021 12:39:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lAAbXBYdpEO1cfxlL+YncxaM2ks2LM0GqRmmthC9rJ8=; b=cnyzXfNsv+cfexBMeC5b4E5rZQ7+2zJGtJv7IfT7Te154t2ooN02O+LllzeB51JYsi woXyP5aEaY8M0Dm9OB12rREW0ZEQfZHpUWITC474xaX/64BS8k8DdlTydwzEdHdOBXh0 +zXysZa/Gv/TV3znPV6wR4p4aqY0mbsg81nMPTj5zgqOZkEagnQC0kUmJENXthAMdEuf 0XehNi2xA+jBs1ra5m+Jx9+sbI0eDRJUtMgzMwLBwWw4KylccVMOhwcxn2FUpVC6rJKb f72irRBWuQ0BkQ+6zsApZR6P1mNkTc34vlLFBLizL269eJ8h7n16WtK5crTAz9ZwwOYY ZS4g== 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=lAAbXBYdpEO1cfxlL+YncxaM2ks2LM0GqRmmthC9rJ8=; b=pXw66hjMWLIXTmrTN5qsUVhPYtgCikUCNmBvQtjY0oDGo6XZ+u9l0mhSvDAKVwVnn1 764ZlsqwhU/gXj6hhtN5bCHEvPfC9041e/6HSkNvZOBS3XOtmXzSaHbL/IX502Ms6Tf9 iq8BxGRh7fR3eHfAOqT2LZLRZr1MIkwtcOBcZvL+C0iqWPzi05YJxpv549KXQfJuJY71 82xVVgH2smt7p85p6e7VkF+m5AoKY6jRrtT7fUOvSbnC74VsAnfD8+JWxwmFTekdfBFT pyAfPoxSMiBpkuH7eYkaGuBf5FBVOKd02CEUnGTY9flCimeAusUQB0Sr6NM5aUU20ZpH ZlgQ== X-Gm-Message-State: AOAM531gyTAj4mUASnZIjlirM8m41rERiuPyzBaCXYqhrCOLM2HrzGPS 2gvhooRCXVWZoYVdL7MDT4OhkPYAWMkHsQ== X-Google-Smtp-Source: ABdhPJylH9pjWEcN1nVl6mfriQxW4QgFaF5sGpdmwNLgSVDXO8GlotgaHuD8/EBqiRepAL/2UTUqeA== X-Received: by 2002:a1c:2784:: with SMTP id n126mr4293546wmn.32.1628019558124; Tue, 03 Aug 2021 12:39:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 08/36] hook: add 'run' subcommand Date: Tue, 3 Aug 2021 21:38:34 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 | 85 ++++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + hook.c | 111 +++++++++++++++++++++++++++++++ hook.h | 41 ++++++++++++ t/t1800-hook.sh | 133 +++++++++++++++++++++++++++++++++++++ 11 files changed, 417 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 1740b99db00..e68ca41507f 100644 --- a/Makefile +++ b/Makefile @@ -1114,6 +1114,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..41dd15550cf --- /dev/null +++ b/builtin/hook.c @@ -0,0 +1,85 @@ +#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); + + 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 1f1db1ec9bf..c8ff3975043 100644 --- a/hook.c +++ b/hook.c @@ -2,11 +2,14 @@ #include "hook.h" #include "run-command.h" #include "hook-list.h" +#include "config.h" static int known_hook(const char *name) { const char **p; size_t len = strlen(name); + static int test_hooks_ok = -1; + for (p = hook_name_list; *p; p++) { const char *hook = *p; @@ -14,6 +17,14 @@ static int known_hook(const char *name) return 1; } + if (test_hooks_ok == -1) + test_hooks_ok = git_env_bool("GIT_TEST_FAKE_HOOKS", 0); + + if (test_hooks_ok && + (!strcmp(name, "test-hook") || + !strcmp(name, "does-not-exist"))) + return 1; + return 0; } @@ -59,3 +70,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 4c547ac15e5..361984c69d4 100644 --- a/hook.h +++ b/hook.h @@ -1,5 +1,8 @@ #ifndef HOOK_H #define HOOK_H +#include "strbuf.h" +#include "strvec.h" +#include "run-command.h" /* * Returns the path to the hook file, or NULL if the hook is missing @@ -13,4 +16,42 @@ const char *find_hook(const char *name); */ int hook_exists(const char *hookname); +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, \ +} + +/* + * Callback provided to feed_pipe_fn and consume_sideband_fn. + */ +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; +}; + +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..644df0a583c --- /dev/null +++ b/t/t1800-hook.sh @@ -0,0 +1,133 @@ +#!/bin/bash + +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 'setup GIT_TEST_FAKE_HOOKS=true to permit "test-hook" and "does-not-exist" names"' ' + GIT_TEST_FAKE_HOOKS=true && + export GIT_TEST_FAKE_HOOKS +' + +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 Tue Aug 3 19:38: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: 12417207 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.8 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 011FBC432BE for ; Tue, 3 Aug 2021 19:39:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6B3B60BD3 for ; Tue, 3 Aug 2021 19:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240214AbhHCTjq (ORCPT ); Tue, 3 Aug 2021 15:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240188AbhHCTjg (ORCPT ); Tue, 3 Aug 2021 15:39:36 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A038C061757 for ; Tue, 3 Aug 2021 12:39:21 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id h13so13026384wrp.1 for ; Tue, 03 Aug 2021 12:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3M6Wi9+FeyUUGQHId/NJKBrc/edlEsrrPDNsfUYGmdU=; b=tPEqGF88lmGJyCkgWYZH5LBGqERk88VlPORxhpQTbih376Ya76QsyxgMQOt0WKPOuh 1VFTidnoyS4pG16kdgZ31uKVpr+5dli1iZUStGL5OcCywW/MD0TiIY18kJ0VAlp8kc/n kkPPEOlW5uSEf7EeY5dDs+/0Kf1MzEuVlg4GzEmqDhLK+f1CqsKyvxqCPwM6YZP8QL34 EFew0rPB37PwpOlGZCJl7SlDVN4+tkoG1X6fjSUVDo8jHELNrwybJKH/Ezm14BLNgGWP KvTMiD8TXj0FTVYJaNgEHWVCEocUyJSBH8lIEHsRfZK/DC9ZQELghqi7mx/NvPGtBuQg Y+fA== 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=3M6Wi9+FeyUUGQHId/NJKBrc/edlEsrrPDNsfUYGmdU=; b=GliQy+xoHzgitAq/xAvZXO1ujMx+jpAqhfYsiKYvPRr45x+ARW2GZjSnYKVyrtj3L+ wCiDoomMyD0WJmxdZ+r+aIQjruv/xg7DvU5jCKUBxdN0gZPrZWJDMre+CteZf5yLHCXY yP/8iPJ9I/c+rrM4rmSuYOICPn0LV6K1rpZ2gmLkpsarNTYTQcb/XEIyjx3eyM5HXVlQ mhHv6jTmVZk4nKZELx7YkVLf5gZCIVwSPY1V8gAboIPslpMcSIAMT/E7M2Zmnev5CT0p fJCgm/S3m7/DVVzXWZPEnjbI3TIm1097E3g2xLrwfvLuVDxFyuyKkX/bPYL5EHwuURls aGGg== X-Gm-Message-State: AOAM533+XnUPL1Mu8aOlGHIL2YYu4jKvKyfd9vxH1qzXu03acczvdbQU RiOe1E+GALq+JySZsTVbgWtBt45N1n8TPA== X-Google-Smtp-Source: ABdhPJzbjLvxauLIHBENoWEStV4qqc7QAYshKAP+iD/8DIQIYAz24GgQpBEkU+M7Wjo856MHgJoOZw== X-Received: by 2002:adf:f74f:: with SMTP id z15mr24980878wrp.54.1628019559367; Tue, 03 Aug 2021 12:39:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 09/36] gc: use hook library for pre-auto-gc hook Date: Tue, 3 Aug 2021 21:38:35 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 | 21 +++++++++++++++++++++ hook.h | 13 +++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index f05d2f0a1ac..2f74cf394d3 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 c8ff3975043..981a9bf46e6 100644 --- a/hook.c +++ b/hook.c @@ -170,3 +170,24 @@ 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 361984c69d4..2201ab9d568 100644 --- a/hook.h +++ b/hook.h @@ -51,7 +51,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 a scratch one will be provided for you + * before calling run_hooks(). + */ +int run_hooks_oneshot(const char *hook_name, struct run_hooks_opt *options); + #endif From patchwork Tue Aug 3 19:38: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: 12417209 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.8 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 EAF99C4338F for ; Tue, 3 Aug 2021 19:39:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D115160BD3 for ; Tue, 3 Aug 2021 19:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240220AbhHCTjr (ORCPT ); Tue, 3 Aug 2021 15:39:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240190AbhHCTjg (ORCPT ); Tue, 3 Aug 2021 15:39:36 -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 32628C061798 for ; Tue, 3 Aug 2021 12:39:22 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id l11-20020a7bcf0b0000b0290253545c2997so81552wmg.4 for ; Tue, 03 Aug 2021 12:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BkBFiW6mSuq3FMAcykrlw52LcUdZ2+9qWA8uQ4ChYP4=; b=eNUfh42pzi1vXDX2wWB2yCuo2kSBtK99hADtZDM84GgUky4+CIe65ciWX+P8tiCdOz kIK1sRdVF2mRqSBA3WGC0lkiumYv2lTsDLevpYSBLduhJLAdNZkRRZlbgg7A4m81xgZS YoiYjw9lI0dWPmRw2g+/DTjKDWDdhuIDk6T9i92pD6hs6gRkOkwS+ckbASkRce6EQXnl jkP3xe3YoNl1KBVfhAvygvQ/yBBO8WIOZ3fC8uND0zGxJiiQt0Dr8pWkzuhwUpK9fbno wiTic8cbYCLnSaFVOVrq2vTo7oH6QATgTy2QdYfMc+MSyHrluiO7pzLOJSVRhrWEVj/d JHag== 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=BkBFiW6mSuq3FMAcykrlw52LcUdZ2+9qWA8uQ4ChYP4=; b=Ce4P5smokaBnKu44o4W29TYMVWCSaINF9BfyvbXIrJFmfYFhmbm9arTgQ9WNufthlV RTa4ukSma4OHGCZ96OmCykpxGDHF0ZFnoTEtq2sMLUCfyRH2RLDxaY8lL18E6D8M//CH XzUeEfBSmmE0oUh14e+gYhLYGxPXlyooBZ+ILY9fWaX5RPyP7OllABMTGg84Pc9KXfDf 9zZRWwgLKWst6yV3iw6BTo+5CVKL7ylRtOBrEyk4ewxmdS7/BFuXfJH34TBYiVuRR2gy DLxS8xy+4APycaPbkU9vGhurn8mMLtvh3AQ47qFVtzHOpJzg4/HP1zRrqlmeZDdZdtNi HXdA== X-Gm-Message-State: AOAM532qclaoTXVgKSpGuZkfKmyq8RLki+Us8AlZdDEeV29wOjbENnI0 uGWo8rzOfwBK0/h2OU0E/fgYstYZNYn9lQ== X-Google-Smtp-Source: ABdhPJwMAxSgxMdb15EXrquxELLr+5zDNW7e3ihrpjJOkPfWCyRN0cBJjmcUJcMOEpj9VTQWFDpfpA== X-Received: by 2002:a05:600c:4f49:: with SMTP id m9mr3440385wmq.82.1628019560512; Tue, 03 Aug 2021 12:39:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 10/36] rebase: convert pre-rebase to use hook.h Date: Tue, 3 Aug 2021 21:38:36 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 12f093121d9..e7c668c99b1 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 Tue Aug 3 19:38:37 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: 12417211 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.8 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 62CBCC4338F for ; Tue, 3 Aug 2021 19:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48E2561037 for ; Tue, 3 Aug 2021 19:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240223AbhHCTjs (ORCPT ); Tue, 3 Aug 2021 15:39:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240191AbhHCTjg (ORCPT ); Tue, 3 Aug 2021 15:39:36 -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 3DAEEC0617A4 for ; Tue, 3 Aug 2021 12:39:23 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id a192-20020a1c7fc90000b0290253b32e8796so2494724wmd.0 for ; Tue, 03 Aug 2021 12:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/vYekOHyvzpEpbHiytPrbkA/C6k4PdJ2YoVyCuon4lQ=; b=IKq1TviR1Ndw9CEheOTk2l2wO1WHKbcqnK8clzhnY3M8iVpqBw1NrS+J8v6g7BpxLa iRlsqUPPv8ItR7334dvE66xnqoU98YcW4uw2JLdhbLnnp8hGu41+wY8SRxlB+4cyyUVc JfCFMukwbhu4IhWYli2QAuOPKUOjWHkwLWVjl3/IU4wkB7ImFH3yy8wvx1vwpKgJfU1r masitl5qTrfpBoOofDwKPy61UsWlgSavlqUDVh2wLATQ1LJ6NzNg+17KV34qsoFLJ5qd 6NNQdDrjz0ra77eh6zydlylcrXMfKtEOy5rxRHFmWYcmVgIvhtQaB+Bm5pkJW4K+RNFZ Xz6Q== 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=/vYekOHyvzpEpbHiytPrbkA/C6k4PdJ2YoVyCuon4lQ=; b=ZqIKCheImrbazKfwW+wrMuGIN9l4lD5SA6nve4PNpY+u/svetDnxiMQEA1x8olpVL1 i9XWROmuHrbFdrOkhV6bBQZkMBXP4pkC/yY71q9FiE4LRAubMT0RjyIdVhA58jQFfSND s9pz+rG9+gu8QdPUvG5yJOFUhjpc1FpGbTruAcYj2puG+OKDB/LT9++OPisHOCFaMoju P3JNLmaEFoGGLG4mWracs+bBny4chJI+39QyUWx9nu1QVnMwqTXPH+mzBfWbL7Da4xRj x/YzHNk/IlcbYXRdjb0DXsJ17d3LsNZUYd0XpDGI7/spkXDuW5IwdyzoN8aNJAS5GG8G ASjw== X-Gm-Message-State: AOAM530xvA9dzQJc2F6y8pdly/OxzjgNd4Mj3eMBoH+nRac9TEYX+vKe jqu5n4WVTRLxkohOrJZKbfTQt4494K2pHQ== X-Google-Smtp-Source: ABdhPJyduDXDDlctDZm5VZugou6ylIDa2Tqhi51idiVSUvH0xB6j2b13O3WY7eHCdRSbbYi4J7xtcw== X-Received: by 2002:a1c:188:: with SMTP id 130mr23996369wmb.184.1628019561536; Tue, 03 Aug 2021 12:39:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:21 -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 v4 11/36] am: convert applypatch to use hook.h Date: Tue, 3 Aug 2021 21:38:37 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:38 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: 12417205 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.8 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 7CD70C4338F for ; Tue, 3 Aug 2021 19:39:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62B0461037 for ; Tue, 3 Aug 2021 19:39:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240168AbhHCTjl (ORCPT ); Tue, 3 Aug 2021 15:39:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240166AbhHCTjf (ORCPT ); Tue, 3 Aug 2021 15:39:35 -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 57E1DC06175F for ; Tue, 3 Aug 2021 12:39:24 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id k4so13117477wms.3 for ; Tue, 03 Aug 2021 12:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wxcYyH3X1IBtvpSgbAsZeL/2zSSIb+lJzM4MNiz9lK4=; b=R+hg4Rbg6wCzJa8RbUCdb+PXsVN/9dC1bXGnhdDUqkef5fr7JO7UjhBzzzQf55Le7/ +WmvXIxTiG1Jb//L2EGrK7yLxAJeFXPUUrV1YB9lTHa2IUAI4zPhkx/vsHy/ZfZpahzo DRO+7Mzbq0gPZAitt0v/2Qx3BUJVVLvIFPpvwOReB2x3rSY49up47GQdTyvA/OXe8U+w RawD3iZBVxa/yANOvRpajxTUy8cUitQgzWCVnyjQuaH86hCX18EfZsCzCc62o8qoNzKA SNxANXX82fgM1MF9oHrN7IUpIkrrAISJPfUueCzVjg18nBgi35ObELes8OJLyVapwKLG ClyQ== 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=wxcYyH3X1IBtvpSgbAsZeL/2zSSIb+lJzM4MNiz9lK4=; b=j+sh5UGsb/g8hI7yPNBnqSoQls5VKweaB6l+CSbk5oCYSQPBibcz+D9QxhghBQdybF z4eCl3hUeO5rA6VTY7PLB/Ok+98EJUnMilP/yCH2+dChSTHz35RIaORh57cv2IJVjtem l4mN2BJli5Nub+exwuxMSdpy8KA1OD6pXHbN+aYDPQ3J0VY8S7Ch0SpJTpxkhfWaIxFe 1hufJq4u/jO4HFkQJaj+3pXgcbnPasv2yT0/zydWBQ1hghp+Ygeo4dmCbJWeKvs2NBng qNzSTUbbLmXC1LKN75F8wUOjvLMi8h9eCprsxEkj7XidkinzKAfuoevYvzTX+Dh19Zwn kJ4A== X-Gm-Message-State: AOAM530et+kZkhfPTzsanfZGUPHV9IrnYHZ9hwwFm5LNQuHJOQwyDLjd +7lqHXxb29SL22DY6Y5oFiPWER3aunrTdQ== X-Google-Smtp-Source: ABdhPJymQ9NCP59XXo34+iYVIVRMAc+PIKmesoQeCCd/UytwN8yIRB5Iqtci0P+Y/f84ADmVYArqYw== X-Received: by 2002:a1c:f314:: with SMTP id q20mr5990242wmq.154.1628019562648; Tue, 03 Aug 2021 12:39:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 12/36] hooks: convert 'post-checkout' hook to hook library Date: Tue, 3 Aug 2021 21:38:38 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 | 8 ++++++++ read-cache.c | 1 + reset.c | 14 ++++++++++---- 7 files changed, 53 insertions(+), 27 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index f4cd7747d35..6d69b4c0113 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 981a9bf46e6..5ecf79c8397 100644 --- a/hook.c +++ b/hook.c @@ -92,6 +92,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); @@ -145,6 +146,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, }; @@ -158,6 +160,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, @@ -168,6 +174,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 2201ab9d568..53ea3a9649e 100644 --- a/hook.h +++ b/hook.h @@ -28,6 +28,14 @@ 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 99a174b91e6..c9e2b013972 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 4bea758053b..6499bc5127d 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, @@ -126,10 +127,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 Tue Aug 3 19:38:39 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: 12417213 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.8 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 AAF6AC432BE for ; Tue, 3 Aug 2021 19:39:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 917816103C for ; Tue, 3 Aug 2021 19:39:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240226AbhHCTju (ORCPT ); Tue, 3 Aug 2021 15:39:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240180AbhHCTjh (ORCPT ); Tue, 3 Aug 2021 15:39:37 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67B92C06179E for ; Tue, 3 Aug 2021 12:39:25 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id d8so26474302wrm.4 for ; Tue, 03 Aug 2021 12:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J2qZX9ADydzDCwCeYMmoGobk6vdlg8qx8oCXrBvhH2c=; b=gy3HVAKopL2v2YEV7kl+HeNbTMos58Jz4dd6W5ScLbUX/jEWet7WxJ38LVt7hmEyWu 21nbm8juVJEBIPMSVChK3ppDAenuRuYS7PYnkOb38uZQuC5df8UTtz5Yrg2nTf347YNd bAcSP4gmhdN/ArCiI8/Whhslvuzd/IL/6iF+re9Yxaex+UcDrzSMm0Lw/PIUbV3sfHyf IEuFV9v4S0EBw7ck+ZOG5vAVevmIm82t9XCxfgD6Hk/vSVJxlXE+oeRnpt3dyH73N086 T+xv/GwSF9rFDhfaKgTw5naeiUc2znp2k9EhuFuYMV0kqCsiASbJmZbVCVEWM+ubD7ci Qz2A== 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=J2qZX9ADydzDCwCeYMmoGobk6vdlg8qx8oCXrBvhH2c=; b=B4gG7rT+ZocTjAL4lQJ9E1CLCon81Kp7tmd2L9HRzXzbIdoRUv8k1iiOTid1xRxxzZ GBofaq9ZW5KIPM6LNI5C3uwSRt8VLYH2jg0CEOZ4CMShQhgA2VnHEui0OSU4nbtbrVkE H8wQELoc5V+47SUWfvSMfZAPkR8E3WSGdSmpGQwItSLW1OUJ/xkv/hzkL2Ho9S9iF/QJ /VmDBI0hgIsWl9GzKAtuPJ0ZrQ5G3upuw8APARumy6uXcNjgs4gMLwGMua3V8itSTbSJ oFxTjigMgzLEd9pvoZ1P4meWWAedRx++BHVqIJn5DIBBuE4suq3CnyuG7Qu5pqpilH6W Z7MA== X-Gm-Message-State: AOAM533VM1n+wdopmWw1aiZEQJDAtmz3v4hrJN4bOHNfLFjhBK+PgMoT B5sV/XOPbrN3VuyrtLzjZeSDcl1C2F0SMw== X-Google-Smtp-Source: ABdhPJyaG0ptEs+vtFpDsParytTvJvxaM1Hw5OtDDkBGd7RK8xSxcGeXV9aBsySXFvZNit0ZjKrejw== X-Received: by 2002:adf:f852:: with SMTP id d18mr24613748wrq.201.1628019563679; Tue, 03 Aug 2021 12:39:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 13/36] merge: convert post-merge to use hook.h Date: Tue, 3 Aug 2021 21:38:39 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 03f244dd5a0..4965df2ac29 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 Tue Aug 3 19:38:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417215 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.8 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 B4B25C4338F for ; Tue, 3 Aug 2021 19:39:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 978BA61040 for ; Tue, 3 Aug 2021 19:39:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240230AbhHCTjw (ORCPT ); Tue, 3 Aug 2021 15:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240183AbhHCTjh (ORCPT ); Tue, 3 Aug 2021 15:39:37 -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 63E5DC061764 for ; Tue, 3 Aug 2021 12:39:26 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id p5so26514332wro.7 for ; Tue, 03 Aug 2021 12:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5WheNg16LOu9InUSvAJw7ZkDJjrGCqhlbjJkBY7xOGU=; b=OZb+dB8kJCfKnXQzEHRwKUmPGpuPDTxcsIzBam62mufY0CB7ky4MrS9y5kHKxuyRzj 5h0f3ONRg5ysKY62qRYolG5edl47da6ROoZLZJEOngjgMLSqiNSnbLtM6sLMeGVlSZTp U3z9i9BRa1B1LZaxf9SQXzf76PJuw3ZZvnv9YosdsnrnU9RbB04kwwm/uxDAakG/tIxW 3eXBZ3kpG1ry4W37cv6BUlqx7Y0orypsfK1pkfDd6AirUbYyp2Qn9f/olwm4TXaucu3m hxNmFdf1I/z+GKBNCQV2cBsSz4kuGQj8KxqbGdcGxpIPu+FTTGsh4aYlL1Fi9J+NDooB inOg== 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=5WheNg16LOu9InUSvAJw7ZkDJjrGCqhlbjJkBY7xOGU=; b=cQ26C5qQGSBETreQTSmyjYN/VMtesQkHYeJjArOpVttKFnWCJU6/+NgX60m1PzRIrE IOuZZl8BODetaZNcCR+wljmt7m6NmEn7JknecIuJgH2tSDSivj+0/zXfDXqtv0yeq+f3 3Q7xvz/5Kdcec7iGl6kU3QL8SMgL2PI88bESjhlGn33OX0s/zFcFktnbiBMgFnvNHUBG 9/bWrZPVxL3QeBD45V3wIBsn6dH16kiHR7iIsa/Y9BqwFCNakisVHWhWeQY8Q9ssQ3Oz ovMpU0qSm7pRi8P9PDmdMwGYifDDT6nLwLXJ74T+f9ZLp26/pqij6QTHLgeXIPuUjHb5 pfww== X-Gm-Message-State: AOAM530vQwZrPD7u463AXKuFGk1Pt6pcY7fidAJ/lVhcK01aJBI56jST oRKktUlQMRx6395PYrLP2GRTyBVn7dk9VQ== X-Google-Smtp-Source: ABdhPJz36Z5FY2KjnaHMyZdI4Dux5pNkJ7TZOJazoaug5gJ76YaAIFEh4MmM1a8AOpJv0nIAYhsq2A== X-Received: by 2002:a5d:4a4f:: with SMTP id v15mr23998368wrs.178.1628019564724; Tue, 03 Aug 2021 12:39:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:24 -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 v4 14/36] git hook run: add an --ignore-missing flag Date: Tue, 3 Aug 2021 21:38:40 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 | 7 ++++++- t/t1800-hook.sh | 5 +++++ 3 files changed, 20 insertions(+), 2 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 41dd15550cf..f33db9953c7 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; @@ -53,6 +56,8 @@ static int run(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); hook_name = argv[0]; + if (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 644df0a583c..49df5a2cdfb 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -25,6 +25,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 Tue Aug 3 19:38:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417217 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.8 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 B3B7FC4338F for ; Tue, 3 Aug 2021 19:39:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B2EB60EE8 for ; Tue, 3 Aug 2021 19:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240197AbhHCTj4 (ORCPT ); Tue, 3 Aug 2021 15:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240196AbhHCTjj (ORCPT ); Tue, 3 Aug 2021 15:39:39 -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 4FB1FC0613D5 for ; Tue, 3 Aug 2021 12:39:27 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id f9-20020a05600c1549b029025b0f5d8c6cso2441520wmg.4 for ; Tue, 03 Aug 2021 12:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lA/GciJUmH/qCBPPiz7AGNvVtgWXz38AQgNSnm6L2+I=; b=QsSCoWF6a0awAzCksV5SiuknckAgvIOGeKqIAA1ZBxev6ECBL4Fxbz4Xlhur4gnrS3 uD+N3rC0ak/XNbbcvr+rBlV6pxrUkfQNi3ZluAC7iNWUpofJ9dsZK831YUDQZWHcFlar wwYTmoR2Stw79GUVK9YDx4yBNLUAc3cmuybi4Rp1R+TP9kjdmTv9byntMlk9/L495ca1 mV/XzFIjYRoUlpHvNp+1EJi9gYjGWm98nxXsdqLzbK7xKmaPQLeVHl3UyjJ1C6Z6YX6J Pl7/ABpXcMyS2AceOgI3NLodWrLHcLWDI9ERXwUfta+MY0akOa/3LC9BGTpLQOSjT50z T52A== 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=lA/GciJUmH/qCBPPiz7AGNvVtgWXz38AQgNSnm6L2+I=; b=kpVvQxoEgouaZAz/A/sDLFHouJOGfuLe756O+m35Yhz35d51mueyVDSNJq5JaHcY9P 4k+Jt9sGbq+4F7CiKLAN91qM/+oWw6DHwWSHQu9Erklx0Hw1GEJ+oc2EI8crXGWgbBI+ ZF3H1B34ZpaIEWQ6Hov2rUvNwcLmMbl0z3vjU+5T3p3pX300XrJhQAJs9L9vp7Beacet banXIsuItEJt8wU/PITzrsMVWbLy66cRMBe+Ftrv33HdoVJG3up/P0zBHBehAkoXRns6 dUh+pjL3iER49Z3QPyA6kiPI/2pAOMqIaViRNr2ACt0I0+OFbjCCqYU81my1ZMK/kCC5 W9aw== X-Gm-Message-State: AOAM5330RtYznrWbxpDjIVHjCtjVxllRn1CjbeeBcMv1VECVbgIa/z/5 iEp03uGYMjyHb+JO58fiw2Pww25N3UpEUA== X-Google-Smtp-Source: ABdhPJwzFIW5tVh+BVcznYkjmSYNCBarpP1eH3RSzmwGj7XBSQZ9HXmaak71JeNxJna3RIB70bMApQ== X-Received: by 2002:a7b:cb13:: with SMTP id u19mr23483818wmj.122.1628019565672; Tue, 03 Aug 2021 12:39:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:25 -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 v4 15/36] send-email: use 'git hook run' for 'sendemail-validate' Date: Tue, 3 Aug 2021 21:38:41 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417219 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.8 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 98AB2C432BE for ; Tue, 3 Aug 2021 19:39:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FDE26103C for ; Tue, 3 Aug 2021 19:39:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240176AbhHCTj4 (ORCPT ); Tue, 3 Aug 2021 15:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240204AbhHCTjk (ORCPT ); Tue, 3 Aug 2021 15:39:40 -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 53672C0617A3 for ; Tue, 3 Aug 2021 12:39:28 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id n12-20020a05600c3b8cb029025a67bbd40aso2477493wms.0 for ; Tue, 03 Aug 2021 12:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wmNu7doJyXF6QA5Q08QNCB4BkAkAVAWjoaO4hJ5rNdE=; b=ZAlRPEMqxKTZGiT+JAq8gUlaTV6CpphZoJszRWAjPuC2MQQg/b9OI8+H3ufDXPAoLS sRdYkxt9+XIcxy4cWitRPJ30MpDAkvDzKEeNkAVgu59VvM6INAvIBKdjusN40ZFMEQ1B mhgjLZLz3xetjw/sVSX22DmAGm0lmJhio8Adp8Wed1tNbtIVU1R8GDurcdOoyBt9Gddh rrraQp6sScav3j1aJQp+RikwdveV8+RgJUFeufUvJrS03XSpCY0DfMT3d8bW7R31OOWG 6nn6jkXdjyx61xTpwqAZyxd8tCzYpiW8GOaTnFA1dp8ykTe0fiO+lI/Huc+DKfIzY7EJ ns2Q== 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=wmNu7doJyXF6QA5Q08QNCB4BkAkAVAWjoaO4hJ5rNdE=; b=jM3Hz0vwzubL71G8ZTrcHuZdv6cTwKhk43M23y0S6Xj0ajkUFg4tu9UUVVLoie4YWh t5k314p4ahdOWV099WUg1QD4JK6h29uHIXg15sCdhT9qFqwRBNs2STPHZQjofG9rI9NV sXlyw47LIm37e+sSvnpAJ2kj8TIXIjkszG/MSxuGwY6w5jkScyoR6X2OMBoI8Ao0B3us 4i+O+V/M5nNPW1mQABpw6KAeg0GhP2T4SagYNpZGfOo4FiUx5fdA0cQKI9CqFTecXxNI ovzJD/MAtYyb6f4CjVoAzBgNLW1VNtG/dlMeXNKl65yR2kc091nAbsModBCpwdBP2IuU P0Aw== X-Gm-Message-State: AOAM532mlKGMbXgAzghRZsiAMK/yQSJuhN+qHdyvhC2DKnDKi/xLkfY3 8PYggcseopOzF2r9k71OlOaONLR3QQ8I5g== X-Google-Smtp-Source: ABdhPJyD/C0jLdmMZvcqBGJtvB4YQNU5Em1GfzpgBrZYar06/pDhp2/mcQlrp9veHFoCwjhnQlHVKw== X-Received: by 2002:a1c:1d81:: with SMTP id d123mr23535728wmd.72.1628019566578; Tue, 03 Aug 2021 12:39:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:26 -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 v4 16/36] git-p4: use 'git hook' to run hooks Date: Tue, 3 Aug 2021 21:38:42 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417221 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.8 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 CBDD7C4338F for ; Tue, 3 Aug 2021 19:39:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B583361037 for ; Tue, 3 Aug 2021 19:39:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240211AbhHCTj6 (ORCPT ); Tue, 3 Aug 2021 15:39:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240184AbhHCTjk (ORCPT ); Tue, 3 Aug 2021 15:39:40 -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 19E5FC061757 for ; Tue, 3 Aug 2021 12:39:29 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id b11so21164204wrx.6 for ; Tue, 03 Aug 2021 12:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lMB46S1NimLSkKJUhrBbN1mXbK87ERJkBZi02PZv9/E=; b=W76UJ6zU3RL7V97yQMRF9J2HHIKUEhycTYVbSKjLfEuT/sSlPl16NKGDXvqEYQsJV8 dQJ18YSQHN2+zdbv4TwG36qPjWx1sCDyFpEeLlTyQHd8mMHnFp1HGJEtrSZ3qWfzFmaQ T/CIf7Ws9wyDXTVplqgWsRhWrYxp9VkznSbc2eB/sHjH5m9FV28BJcXrkyvMARscEHro S8aaqP0RTmLqlulrmAHca9REgPHzkDJ5HLenkUd0yZU5W/g9yPS/BjJXJiGPsfQWqz3n 9EiAD0PA8movDAL5elaAmjslMQhEj56og5aN+NgMMa1sJL/a3hGj9X1VHlakXjfFYcbR /rbA== 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=lMB46S1NimLSkKJUhrBbN1mXbK87ERJkBZi02PZv9/E=; b=TduzqZ+nJQlM1wkQksVL+muLqL6FmZofMKeqZDe3a7LmvNYMlG2L0NlNNFxZG9zf1t o7deEAozvatkXGdjpOIVJs/k0wxNMAM8z/ZkgzuyoHPeDBaKCjy9tYWbjILH9QGfkf+3 yYsx6gRwJ+nnKMQW5Iz/DMT0U+jin1fLHKG3G+mqVIgbQ3Qn54EMQk02U8LvskEFw8Vy KsST2PcgQfVSaFoDN5/m63LU3bPYitqKOa9+HktoU+Z+RSABvxnFaFe3K8o2vauLtBVI rBOhC0x+YU19zXLYy13YBFYXS9K8fsdrypAxtMWYWdzYZOAeUFl5vyJEDunPprEGv7wI BV/A== X-Gm-Message-State: AOAM532iXtCzp9Cq4JHiesf3rxRI6HTyjazCRXwOHI5yLwk5Xt+n6+Tr moQUY8reC3d8Fdi/3ziNvETKsa2tIK8C+A== X-Google-Smtp-Source: ABdhPJxwgpZBQQ40IHtaVvSYTVGzl+GYDhqtcKH+yOeMKrnepxTRjNACe8Qx+9YSTl5m9SRNP7Rsqw== X-Received: by 2002:a05:6000:248:: with SMTP id m8mr25230075wrz.145.1628019567427; Tue, 03 Aug 2021 12:39:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:26 -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 v4 17/36] commit: convert {pre-commit,prepare-commit-msg} hook to hook.h Date: Tue, 3 Aug 2021 21:38:43 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417223 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.8 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 17ADEC432BE for ; Tue, 3 Aug 2021 19:39:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 045F260EE8 for ; Tue, 3 Aug 2021 19:39:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240180AbhHCTj7 (ORCPT ); Tue, 3 Aug 2021 15:39:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240209AbhHCTjm (ORCPT ); Tue, 3 Aug 2021 15:39:42 -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 22187C06179C for ; Tue, 3 Aug 2021 12:39:30 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id b13so15628119wrs.3 for ; Tue, 03 Aug 2021 12:39:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kw9QymIyq3vNdbRanlCbxxy13lTRBwg6cTFmzSwMEzE=; b=IYoBULyYQXe0Ast9oHQt9CWea6B/2VMC8ibLP+DnLQeLvMu3zq2fjNAuapdh7s4EKm azNN5jbirvbEo1CsrQDGnV6S2qaXDEU8BDJyVI+vNvGwdVaVziBRVbb3am1DKpWJMIyD CFIXq5wL/1Tu46I8596pDGdH2kiQlwlmpxETRDflYGW1ulm5y9AQyrJ5oOMX5LcLFbed 2BLSLqfzAn4r8ZJC38xTkpYTYkyJcnvfzChcYMnz6C7FqoGiaVpGfSviktArqsCyi7C5 eQJNb5HmX3BxryXwyVJbQa7jLTrFG8CfHZ3ToeHH4EgVQq1/Llc+Eh5OyPu3wwpul6gY UnhQ== 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=Kw9QymIyq3vNdbRanlCbxxy13lTRBwg6cTFmzSwMEzE=; b=EocDLWIMWaC5/c8fPRjf1TrFSZuARlka9WRKH34ACnfTOceu7me0Dxx0VIfK3Tjffw oxSKLuPHFrNIgemes+03dQDrABRmGCdPEDk3ZvWyfngGBHYvq+Bz7R4ZiMLMoywH6Mt4 FEe3GgM4jFCjce9MgWjPydj84RiQWyXAMj7ihxkVfvN869PpwH9bIi44KggRzr0vhune rN4qtpqwGKR0Yr3DRoaNDVF8isb35XliqPn5GHujDuVPLeBhZGHEl8vRjlBwvcQiQizh aGt2sSfu18l0iU+5+kB5Ymt9mH9G3nC40ofQmUVzmITbnZO6O/jlcMzPQtrA/Ex4rNjz 3QYA== X-Gm-Message-State: AOAM530q75qLAqDcDtgcQ4cXBrtqW3EizvZs1mKqO0Nlkc0yt5pO5LPB zzbB+J++3/OeOn6ZzORSQ9Bp/E+nA1FR8Q== X-Google-Smtp-Source: ABdhPJwS1kGwsCMjZ4yNycSe2YG7wlVACtQQMrI/Wvl5rgfNWTpEWiJt8thM9RO7+j83Nnzx0E/elg== X-Received: by 2002:adf:eb0f:: with SMTP id s15mr14136273wrn.308.1628019568473; Tue, 03 Aug 2021 12:39:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:28 -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 v4 18/36] read-cache: convert post-index-change to use hook.h Date: Tue, 3 Aug 2021 21:38:44 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 c9e2b013972..90099ca14df 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3068,6 +3068,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); @@ -3096,9 +3097,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 Tue Aug 3 19:38:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417225 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.8 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 0318EC4338F for ; Tue, 3 Aug 2021 19:39:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0FBF61037 for ; Tue, 3 Aug 2021 19:39:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240233AbhHCTkA (ORCPT ); Tue, 3 Aug 2021 15:40:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240213AbhHCTjn (ORCPT ); Tue, 3 Aug 2021 15:39:43 -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 22CDBC0617B0 for ; Tue, 3 Aug 2021 12:39:31 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id l18so26471762wrv.5 for ; Tue, 03 Aug 2021 12:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HHCqX0VaO37vKmhX8jZUiyguk1+2q+4YuX+EjBgC2hY=; b=eYMclEGT7UZ6zhKUup7ZK72PeFMbqwus1iTu0kbRL3fMqXsU+dN1/ylk3wqI+0hrc6 YbFjPSzuIctFSXG3TWJhGVzYv/Dal42J3r33O67rvVUQTLWN+j+npmahvNpA2FjaaNyS CoVjAi2ZMjGqgITOe8aGTfNeo031xKg3Md/dKDYy73iDMA0f3WxS/3knZuPWLRYCBeLW tH86rb/sSNzcdVHKZXXyi3sRd9vnZoK6LPQhjzmaa53x3J62H4HgK3imfdgG5ptP6TH4 1n1fvEVXpKpILr/WviSwImsEVDK7mxNQRMlRH2q90R39jUmcKfIfge1wXAcY3TmhPb42 AQaw== 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=HHCqX0VaO37vKmhX8jZUiyguk1+2q+4YuX+EjBgC2hY=; b=JP8WzhhW12y8rDTT6c3zhsbLzC3cQoLQAi2tprFvos11kXrg1mz4AV15lXCpH5I6aJ UHrZPVxvHyq6j6GocLVoibsc+BaApVPTVI+cvkib6vOYpC9xJYFDG8nfA/k+HoxErr4n SmIG1d5+i+q8d9LWwwgyNa4Uw9FqwHgjhg9s0pcRn29U6hvTmROOA2kRLgdaFiNuWpAK wfe+Tb7pu+BtDDhbpKJEWTedWdFvV4Fnpj9ct/Zlv0sXVwsfD7CbjoxqJiy4GuwY3TP/ nsk5Bi2+LC5XS22/7Pquv6j+Rfzx/4kyMP/04F5ichSJgQat757ZTeXPmwP9mdAgiLft gVfw== X-Gm-Message-State: AOAM532wM94/Y9C7e/NRWc7vJYxVyjDy9d839aScElvvrkpoVObAu47O gJceb2G7jUuPXs6Hr1PkwFo9ec8oQMZxlA== X-Google-Smtp-Source: ABdhPJy92i5zIqGmT9BkTLDzY3yVUQaCkH3/6SA/mg8lF+JdnoyJHdf3DyJdpKKZaecXn+LPt0fX4w== X-Received: by 2002:a5d:526a:: with SMTP id l10mr25385758wrc.40.1628019569452; Tue, 03 Aug 2021 12:39:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:28 -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 v4 19/36] receive-pack: convert push-to-checkout hook to hook.h Date: Tue, 3 Aug 2021 21:38:45 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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. 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 Tue Aug 3 19:38:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417227 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.8 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 273E2C432BE for ; Tue, 3 Aug 2021 19:39:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 108E460BD3 for ; Tue, 3 Aug 2021 19:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240212AbhHCTkB (ORCPT ); Tue, 3 Aug 2021 15:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240216AbhHCTjq (ORCPT ); Tue, 3 Aug 2021 15:39:46 -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 028C0C0617B9 for ; Tue, 3 Aug 2021 12:39:32 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id x17so6860837wmc.5 for ; Tue, 03 Aug 2021 12:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pTUqsOmWrxDA46ORPGY23DfKfx3BNCou62QzFUhxel4=; b=OUly5AMcEe1FRsI3US8AsFionTGBuV6vIWPTzybOv3NSfyqKKOxSPdPUJrXNbsKwa+ pMx+J1kQVVgFUrFAV53BEY1xdAUxG9U/xnbSHMD8/4VtVJZ0JyLlNY6mxXqwYueWTj1S uPDlcZObbDuglWDKCFJGiNVLVxoYwJybylSnijNowj/W3Jpk16aSl6FKtQzV62wZfEUM jnqWA1n/suiYGJV7x1nCPq4xHXdyoqIOxqf7+72qnXIb+FDAe28qZHtogIyBHgwu1P+q WwQH2C57HKFsH5IAQovhyrE8n+CSsbIrVcud+t6PIjD/ewAAHl3UrDdhBUBNF0aB33nW pGTw== 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=pTUqsOmWrxDA46ORPGY23DfKfx3BNCou62QzFUhxel4=; b=BG1TiUgZFCt+oCFPi/nM3NTDKLyjqEnRzoVn4x4uqgZU7A3rnYfyd/oarbpvhi8quA BmuMNpbU/hvqq8RkxW8xwAw40a8u7W0yI6PT8NTb3TqkSy8Z8OKXJguOlP+qBXuh2bTl H2EcowRMm2IoiP+ouUPsgEp5osM17d3UznKGfT19QtKbD6+ehcGp8iODMLQ3zxbafBEn Y4D9NFwUhLiYG9aKF84AFCIK1bASwZfF/Lo6vM2jLNBsJH/8QFoKd/Qo2eOzwCEtt7dT LxxKMKJPYso2KDGjeKh2icVOY1HXKMitS9sittPOCya6MOPVEbFhN3JK2TCPFA0hU0H8 rZBw== X-Gm-Message-State: AOAM532dRpQf2M+7tOBQO3emEyjfNFDmw9CN3piZYXlSX4S8axNyO1Y5 oWmBjZLmMTabmT9x+wpUSU25eiTLdQaVHQ== X-Google-Smtp-Source: ABdhPJyLigKCgbxjiNav6U29HEIqIqK1DZV2ds2bj1lWNCIUTl1HX3HA+UEPb0cxGZOx6tS6/CPiJg== X-Received: by 2002:a05:600c:4fc4:: with SMTP id o4mr5075730wmq.109.1628019570381; Tue, 03 Aug 2021 12:39:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:29 -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 v4 20/36] run-command: remove old run_hook_{le,ve}() hook API Date: Tue, 3 Aug 2021 21:38:46 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417229 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.8 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 080C2C4338F for ; Tue, 3 Aug 2021 19:39:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E935760BD3 for ; Tue, 3 Aug 2021 19:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240216AbhHCTkC (ORCPT ); Tue, 3 Aug 2021 15:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240227AbhHCTjv (ORCPT ); Tue, 3 Aug 2021 15:39:51 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0086C0617BB for ; Tue, 3 Aug 2021 12:39:32 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id n12so26504189wrr.2 for ; Tue, 03 Aug 2021 12:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GbWqkuv0PyqhDLloi7TIGIcoxvgpIrHZqEfmBs1BDF8=; b=tfSu5b3TOpGpl5L8M6xhoyNBL5gETUiG9JO/PkW29CnBEr5Oo+V0xm+8AzboIUhM1t D7X8spqiF9eYlsen76Ethgq+olquM4TKOTAjSv7VpA3IEd1/Wzfbi8U7Rr3iqt5bRsQJ gtQMeeQv0zKPEdu5Tw7PRqZ+BWspPe93avm5zWEFhNhzQZ9HYNiR5AaScdW9qeb4ZUhJ x2eKJyPC4ayiX3w336j8kRsCWiP686OXD4d2V0TFjNZdplKNOvyXpF5CvmSzZ2DIsDwA gqrgQS2RUE7oB53x+SYseljIjmi0QOHG7xOvdk62NSXN74mZEhB75u4rJrzE2GvyRmaa R+eQ== 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=GbWqkuv0PyqhDLloi7TIGIcoxvgpIrHZqEfmBs1BDF8=; b=Ks0SLxoyBF4xkhnBeN9MV7EjRhZtmTCDzOeo0scroytFQdnd9s2DHWyx4cZfhoZOjG yzWd/XMJWSdjosSagSG8nzGOrqWUUmHIgVV2uYEgaU6ds0/ORElL8qnXgx5HDdk/z+hK YGl8ofUoS8/ISXweKBmsaXXAb7lXgOGH8SL8+lnOajzyviA75U7jTrY616wM/2mE9pDy Lape8dQ13Lpm0PddWC/86pNlWK/zi+DV/BtwRqtXbrja6lwqWm+xfR69QN8xvEAKtlfB uSRu7pxfvIOgKqggJrXkFKTKfkzyVZE/LbET9CKoAfw8uIm0xrrtzhh67G2nbligqcHe uv9g== X-Gm-Message-State: AOAM530Unp1zS2rcSeXYpyL/qfcSZLJuwEFj+coN+1o+jpuNZFBWQdY2 TMjUzhoY9rQIsDI9eHzlqn9YoSFEAkWlbQ== X-Google-Smtp-Source: ABdhPJw5CRdzX6T/ugmkuw41fGv4qYG5mJqyci5SOKTrTUXD6zz5WzOAfIYXgC5zs6hSOcza3oNBXA== X-Received: by 2002:a5d:488f:: with SMTP id g15mr25624692wrq.98.1628019571229; Tue, 03 Aug 2021 12:39:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:30 -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 v4 21/36] run-command: allow stdin for run_processes_parallel Date: Tue, 3 Aug 2021 21:38:47 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:48 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: 12417231 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.8 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 997E1C4320E for ; Tue, 3 Aug 2021 19:39:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82C0E60BD3 for ; Tue, 3 Aug 2021 19:39:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240231AbhHCTkD (ORCPT ); Tue, 3 Aug 2021 15:40:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240228AbhHCTjw (ORCPT ); Tue, 3 Aug 2021 15:39:52 -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 CF06DC0617BC for ; Tue, 3 Aug 2021 12:39:33 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id h13so13026859wrp.1 for ; Tue, 03 Aug 2021 12:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1u8+Szhb8RDp/4I1F53C70kQTLq03qQLbPQPfcada8o=; b=JdlMB+9P87pApXzJ4kMoXTKXLKUJQFSOel26YJLQDOYl05l3/DGcH/T0bc5tagyDY/ Vsn6NNouGNYp9vmo1IOc6MYvCUpPQoXEIWbEwxyYxHM2bJ/MNGAsPEwcTxs7d8niz9g9 UX6dQSDbzQRV9+IGgZOafXTFetcXm3Z5pizRP357eAJk+qah+8cUEQ7oLiVc6fcSBlGu HBUi03SIFpQlOv7x9GXYyNEGcWZAsOL7AvDrMCic8RVB2MJ/IAwxdnqg1Kij4l4UpDuY wVTxTzhkCN+11AebU6Z+sjbDsW8Gh5R34H42DA5Oey6Awz8CnalG6Gao58tGgiQshjne OgZA== 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=1u8+Szhb8RDp/4I1F53C70kQTLq03qQLbPQPfcada8o=; b=QLeTc7puIHzBYPLkhX0WXiJN2tr/F8nFpvTLOwIhTNeeLEOwId+8dQSTye+5TuqACj 9S6GBVRVfyfDwrknI/XfOtafajxGFUsQZnhwumxeiSmtaag0B5s4xes6KhsOhAfd/sCs RbyufPIJcaYn70I5a30kxjLDFIT4OhM6FgT/wAN0NpYVowDnF/IIbwDfEHbOx4alnvLM mTGk36HAbFk2QUqD1V19W3682A1QM1AEkeKQCsqWSeGboxRwopSf8Ds287f+m8iGVXcb imC+8aUjuRoymr9UMSOSK+5UQVqFXK+M3Abl8Mnhq85aCiG5LqUXEjiFMMaOhiLdtsF5 AE4g== X-Gm-Message-State: AOAM530NxM704q93/bEmqIxVjpwT6ZZFHQ04n8vjLkzx7Uk4RLbdzyZa +z+4/ANjMmqfVMTV1VchmE1y98wf7LL5zQ== X-Google-Smtp-Source: ABdhPJzZlsdtEt+2nVMjEs4c0uJ1eMvJzmIQAGoJnSCj0qgmjETU6Mbn581aeC8wHktt+YIsT11Fqw== X-Received: by 2002:a5d:58c1:: with SMTP id o1mr25025468wrf.6.1628019572151; Tue, 03 Aug 2021 12:39:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:31 -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 v4 22/36] hook: support passing stdin to hooks Date: Tue, 3 Aug 2021 21:38:48 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 f33db9953c7..27dce6a2f0e 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 5ecf79c8397..63c9a60921f 100644 --- a/hook.c +++ b/hook.c @@ -88,7 +88,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 53ea3a9649e..cd6a68a3b50 100644 --- a/hook.h +++ b/hook.h @@ -36,6 +36,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 49df5a2cdfb..217db848b3f 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -135,4 +135,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 Tue Aug 3 19:38:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417235 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.8 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 E46F0C4338F for ; Tue, 3 Aug 2021 19:39:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF68861037 for ; Tue, 3 Aug 2021 19:39:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240253AbhHCTkG (ORCPT ); Tue, 3 Aug 2021 15:40:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240199AbhHCTj4 (ORCPT ); Tue, 3 Aug 2021 15:39:56 -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 A7DA2C0617BE for ; Tue, 3 Aug 2021 12:39:34 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id b13so15628296wrs.3 for ; Tue, 03 Aug 2021 12:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M1F5FeHgKcOYOv+fSyUIj7dfbmV5mI1nL97uF2SfCIs=; b=hMmaEyTEHGVJIjkCNxhY5DmjZtO/pEusU5xbYD+/M7Wrlkaj2U3Gfp3TR9HZChB/fC N58JCRahxgJ3PqUW6HNTiib2LhttOnPlFC+p+l66CDXWZJTrvqAD9+rABFnU4qA+2e8a eRkvrbV9JaiFcme43yoHowz4FU/FIs4xWE5txzYNBWG0m3rzssl5MGoqZt7d+Nb6cjXe ow0Lc13ZYsfEHMMj2cMKbnA/I1J2pbKys95Wv/BqYzs0ZDi6dHtjJQpIojnNXq1VB+0x 6m+3CzIFmd+ghGFnESqDBdw4h201AEEH6RxT0Ngahh0VGFYzWNRX9TzphCTig5KklHEF Xgjw== 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=M1F5FeHgKcOYOv+fSyUIj7dfbmV5mI1nL97uF2SfCIs=; b=rI1vUbALs1l+P9X1PWU7Gir3/jDW5GYyGR9xoAjHio/dQ5rAh/IVCELVZHqDEFNNcn EGIor4uSvsA9icNYtMHcxLwntMYLKyPzyZMAiiuAZqonH64bOiYb9NFotr5WmNdqyQjy lbaeYdSB9GT4K5ySq1fy56BHph1tEIcyx07j4VKQL39o6VVump6vzmRpQ6j7YPVrMavo Oijvlq5gNnjZ9+hDrnod88MRjmc/ZRj6kNvbTvZAq8ne+4M2h2v1nd4rqmWSdy370LFD bE+CYEdDQ8q8F5fBVDXlcwwgyUBx+Xy6zEB2RUHs61nssHt8GV495DMzfoH+CoRxIq+/ E1iA== X-Gm-Message-State: AOAM532TqR4KdoMdf4Nar8DLFXWQX9vhRD8tuVldWuOa/6t0bGjjtqNV XgD3KHVvW98jk4T3pcBbClWvrSFv0KvL5Q== X-Google-Smtp-Source: ABdhPJxDhXKbERfzVhw9x6SDf8z4Pkw3GwRiRsL3Z71srJZLboos3Wq2UpoPKjByRpbweh/b1td5HQ== X-Received: by 2002:a5d:49c1:: with SMTP id t1mr22261791wrs.141.1628019573034; Tue, 03 Aug 2021 12:39:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:32 -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 v4 23/36] am: convert 'post-rewrite' hook to hook.h Date: Tue, 3 Aug 2021 21:38:49 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417233 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.8 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 31B08C432BE for ; Tue, 3 Aug 2021 19:39:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1996D60BD3 for ; Tue, 3 Aug 2021 19:39:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240184AbhHCTkE (ORCPT ); Tue, 3 Aug 2021 15:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240238AbhHCTj4 (ORCPT ); Tue, 3 Aug 2021 15:39:56 -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 9E91BC061383 for ; Tue, 3 Aug 2021 12:39:35 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id a192-20020a1c7fc90000b0290253b32e8796so2494947wmd.0 for ; Tue, 03 Aug 2021 12:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q3XRO2JHGoG03/g3gEaz2PJltoYcpBW/dzqMzPu1hMY=; b=EhecSSXyObNRQ/OPwF+/V5HJEQsagytgr55gGF+IFM+dR/P8rGhvr5/+vwfXU10qkp e2E8wnhdqnfr24DWze848QYb7sqPYP1YzLni011ZmHKqCqcUeTkiZI1pXxlvfez0QwM4 m7UYK66V5GG1zZM+Ogdc+iPZSxUHErAhrw63fqHhVR1HnxlVXElv+3Hx83eCg0t86Cl5 mDTYu5mzlT+PuXFxfgweaxoPD0kb2Y5f1fIrp+VZ9rbTFitkbrCVChWvKntLuVvFK2XK tZK7kW1KIarP6dbe+P3z+xzVQ0O0NW+fUM1AVVQ5tiUTdHZt/dA+u7DxogCWd5KRmR92 yCLA== 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=q3XRO2JHGoG03/g3gEaz2PJltoYcpBW/dzqMzPu1hMY=; b=oYIdSXncXeay/MIm414Fi47YSIGM29be2EYvaBRMnrp/YuXSivWJw5emfu4ivKW2Pm k5MdjoOlhXc1bQNfxXFgoFDQpDzRgLEi1BelvetIobVPc9FrC46+0Ug7R/vTV1mCKoYJ gu5jvOQBf5mMAC1jN2LdQBcenTJN+KJ1qTmvZlKfKSLlM46GmrTrm1H7IcoCA1brPXCv 0Mmkyd/IY1phvfQYtWCq2s7gWCzo+Ipzd6EAwsm6TAdpE1AkLkfiBD/zGnJX+8b1ZKz8 6K2KpK1mlNH+TiRD8caBG8od/3Q9SHsxQ/SD7hgKxfPJ5JSLV58of+jy+UxQaYRusRpU hrkQ== X-Gm-Message-State: AOAM530y1oGPazsyiqEZ2VkKIhWj3jB7cZWYSmcHn3b/+NPEB5Y2qM2Z 3Pj7JPb7mk88CBZYKQWuXVxpRqv0gM4QsA== X-Google-Smtp-Source: ABdhPJyzHDO0EfjbwcRPWw0j6flD5+e+Tvrs/m0CPheDNSqiz/zc58E5bT/75RohdVokdIcKvYrapg== X-Received: by 2002:a1c:46c4:: with SMTP id t187mr6081317wma.64.1628019573934; Tue, 03 Aug 2021 12:39:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:33 -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 v4 24/36] run-command: add stdin callback for parallelization Date: Tue, 3 Aug 2021 21:38:50 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 25740c13df1..fef6e85d003 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1817,6 +1817,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 f73963ad67d..f42ded548bf 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2294,7 +2294,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 63c9a60921f..a7462639d97 100644 --- a/hook.c +++ b/hook.c @@ -175,6 +175,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 Tue Aug 3 19:38:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417239 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.8 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 DAF42C4338F for ; Tue, 3 Aug 2021 19:39:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C684260BD3 for ; Tue, 3 Aug 2021 19:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240261AbhHCTkI (ORCPT ); Tue, 3 Aug 2021 15:40:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240171AbhHCTj5 (ORCPT ); Tue, 3 Aug 2021 15:39:57 -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 656C1C061386 for ; Tue, 3 Aug 2021 12:39:36 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id k38-20020a05600c1ca6b029025af5e0f38bso2429106wms.5 for ; Tue, 03 Aug 2021 12:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RZJAedodHOCyKHn5EqcPNmDKaEqty1UOdjR3RcX4RA8=; b=aXSRiyCyBLjouLGUXLkePWXQxlarD4LQDqj4BWcCXiXg5ImYcoJr1a6n1F2cV4Zxmx D8qS/sBRSZ8+uCj5H+xScbgMNumbdk6SX/EXodRaW57cshCJOoLQapoxFKFQstTaVIzt Kd0GLwO28DsYd/BsRdX9KQ+wv6Pu+BuKpSkC5RWIWHvvgF4+X0gn/IKTBLtP3PtaX2YH lpFHM9RsMgHCOsj7iSQJM/7sY4heKVBZOEhmD2RMnEIGqPPoAOs+rioLtWkB35PaVpu9 K9d6dfrn5d08T6Bo6O9m6lGyecDOQnKQrQ7irAmUd6VtBoTD7VlZy79BuA2tvUVgHQuF EElA== 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=RZJAedodHOCyKHn5EqcPNmDKaEqty1UOdjR3RcX4RA8=; b=VRimNfVYoQQkXii5GRxtfKCzpe5BjmBZTXmgj3vUO+VeTOs+uskPwVIkBR5XFKn1Po SCdMrxmO6SYN5VJR3NHRW3si4zhl4dS9h53wHbty6rVifr116OrzpohQeThs1aHLumhT 1oNFc81POnOBJRIVw9X0a3+FR09RjuhaK2uolVA2FbU0hu0PX3u72AqHPogU/HLBZ/wy 0HwYQ5nyYA0Jqi7RL1NGDFk9C2cYcvNVT+M8y0P7zb1wIRZO/IT+3wp5lNcgSHS+iUat mxmQw3LdG5Mqo04364Fu3dnUyRS8JR1kRNpnK5V8ch9jfHq42gQUBuIFq1tkwKEZR3Lg j9rQ== X-Gm-Message-State: AOAM531tifuLbmwCpN39B8BzIgylGsM1IXKoLWPZgsolj2l1szES40K2 VazHwggKgqGclIBIqffgaW/TSA86yjZ3Hg== X-Google-Smtp-Source: ABdhPJwEWSqQ+feGUm+bj2zyro2qphmuULLCXcgHeb+m6vEKReAZl9I6bWD8GS2wHFuydHvuUVhyfw== X-Received: by 2002:a1c:cc12:: with SMTP id h18mr6189209wmb.12.1628019574763; Tue, 03 Aug 2021 12:39:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:34 -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 v4 25/36] hook: provide stdin by string_list or callback Date: Tue, 3 Aug 2021 21:38:51 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 | 27 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/hook.c b/hook.c index a7462639d97..44e73827800 100644 --- a/hook.c +++ b/hook.c @@ -77,6 +77,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, @@ -92,6 +115,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; } @@ -175,7 +202,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", @@ -183,6 +210,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; } @@ -196,6 +224,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 cd6a68a3b50..b55f283f90b 100644 --- a/hook.h +++ b/hook.h @@ -19,6 +19,12 @@ int hook_exists(const char *hookname); 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 @@ -39,6 +45,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 { \ @@ -46,6 +65,14 @@ struct run_hooks_opt .args = STRVEC_INIT, \ } +/* + * 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); + /* * Callback provided to feed_pipe_fn and consume_sideband_fn. */ From patchwork Tue Aug 3 19:38:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12417237 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.8 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 1C87AC432BE for ; Tue, 3 Aug 2021 19:39:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 098DE61037 for ; Tue, 3 Aug 2021 19:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240257AbhHCTkH (ORCPT ); Tue, 3 Aug 2021 15:40:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240240AbhHCTj5 (ORCPT ); Tue, 3 Aug 2021 15:39:57 -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 50EFBC061388 for ; Tue, 3 Aug 2021 12:39:37 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id h24-20020a1ccc180000b029022e0571d1a0so78865wmb.5 for ; Tue, 03 Aug 2021 12:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7qDVL0vjk9KM58b6qtKgTV0vGAGubdw1h6Sfe9qD4zw=; b=IH6YiLhR1H2OE0hmRAR8HfMBiBRKDiKAmIZCrAcx6rHCkPKnjQ7V2UmLsElZWL/nXf ATzVjQajeAz6h56J/OZ7DsxanVfxQJaew3iAQ6V3Fr++kxE/lyO0da8KnLkpinj4nnSI nNtenkkcZWN2C9plgid2N8E9XpnSSOgtaj9c4SaHQtIUFrdLoFMjx77aZfjQuCX+MIGc zun8bZaRAdqEJdMcNzLke3fjGaZ56HYlnfNhe6tDdzwC2xdkwz9mgqIx2enLKKtkRLfb 9kA/uvDhTeCA6jQvkqtY+pKTIqDJ+cgS+Oj9i6jN3RVbCIriSzMTnQrAvubIV3/guB6v Nm1w== 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=7qDVL0vjk9KM58b6qtKgTV0vGAGubdw1h6Sfe9qD4zw=; b=p13fGVs+mL23A5yHsEIMQ6QXzaiyFTABjisCzEEpwYzvlG3/uIh07YEeFrirLWl7rN MsoKeOyIH35dC+UnoGmk/2Y+975mHQfcmkq2p6+EhnV6FnqY+zAQ77ozILrBO6D+k2IS h4g9Smm4Td56bK5DwPrLYJdtmZl9FrmFlaM9JUtV4veXJMPD11BaVeYcrOHNVpVuCYTa vJfUAwSxSvKHIpev16BojvzjajTZD8whlTY13nqHUuiYaoyYH71cJ6JJBcH5KQqzYYBe M3G1Ht/mePJ3Quzk8WZ7PDRoe5KqJsn3B38vRa8iKzQMsVuzveQ9scoTWtTEi1msEUNI af1g== X-Gm-Message-State: AOAM533F6HApmvNw0cUcKMWuvvLJinz+W8a5qnVfBMMpUaWni7RJZtSH hXoyFzv2f1Mf5l4StnUrFnZllgdCxYiQAQ== X-Google-Smtp-Source: ABdhPJy7TJHQ9CNpncdz3VxCpNIF+nqOAjqXObHDAuJAnByGVfLJ7I5CewiTDBuU4HKvt4my7CsqgA== X-Received: by 2002:a05:600c:1906:: with SMTP id j6mr5749063wmq.108.1628019575654; Tue, 03 Aug 2021 12:39:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:35 -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 v4 26/36] hook: convert 'post-rewrite' hook in sequencer.c to hook.h Date: Tue, 3 Aug 2021 21:38:52 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 9aac08c1545..77f809c00e4 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 Tue Aug 3 19:38:53 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: 12417241 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.8 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 61AFAC4338F for ; Tue, 3 Aug 2021 19:40:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A4FA60EE8 for ; Tue, 3 Aug 2021 19:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240237AbhHCTkJ (ORCPT ); Tue, 3 Aug 2021 15:40:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240192AbhHCTj5 (ORCPT ); Tue, 3 Aug 2021 15:39:57 -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 58637C06139E for ; Tue, 3 Aug 2021 12:39:38 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id n28-20020a05600c3b9cb02902552e60df56so114542wms.0 for ; Tue, 03 Aug 2021 12:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+XIgSkEUfrDm87A9P0WKS1uqytWn8OXDyB3PoFjrnvU=; b=H/Wb44wK6CGItFPLdtkAs1TrlYXSilb2dlHUqLfUfVkWtp2QsqsW56c76EohXAk7wZ Vp5ZhYYrKMUu8c+7p6xJ1Ei0JkXQI/XSbc3W1nRwTZb5c4LR8znV3TtFiCuTt0B1f/P5 JdR30uap6KnLSVLd3ZJ3gsfOOLF+6YhFqEbxrTTt++osgCeq/SMjPdqOgdxttCv1SZHc uCiT6ONSOUkHZrjEdV+KZEn73o4/uzaWOkG3Jztylp9qQ3chew5TDpxaiZUMWbI2JMN6 HAyCLTl5RlTVn/RRHTIxvDRD7MSEOkHWn4k5mn2/El61Oyt0ZP2KTfYRg8r75RDiVA6c 5Zvg== 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=+XIgSkEUfrDm87A9P0WKS1uqytWn8OXDyB3PoFjrnvU=; b=sPxyaUIqmhRmjRSN2dWdtVurWjTAMmfEj/GAbtkegIAGDAy4ll/hyqHiGU++RTgZ5I xnsdTP4+dxGRHQnNI4R9CX7DPBz+hiUGm5mFQTHS6lEkHgOfRl3YdT7qZQivKxAvnYgu mKbCutnDP3tGNux4UqH0rAUwolRlwd0HV+KAu7tlcD49DGWtUIsmWAf6T/AGdPfD12MN u1ybp/ArDT84Q1a1BRvgkcJKTUNu8Jp/vbi0aa+mhCTKaYdfvGeHPEHNNQU9IsumoVGO StxgRagmiphNwadenQ7txqaqzHEJ3ud55/jd/6PInOtOFpRJUn3CTg4eqit4xocfVTsA F4Ww== X-Gm-Message-State: AOAM533TUDlZLdE7e+VVr3RON1DuyiYYlOAyJW8FkU07n4cI4HR+soyf jqT227fMYQI+mzxV8pIXJuhEuRGUwpK9ZA== X-Google-Smtp-Source: ABdhPJwLJNwCqIO7nreWq1L3+yN0KUaZwk6+pDacESE2sZ9/M/4fN3GFUOsQl2k4QOEjGUJ7Nq0clw== X-Received: by 2002:a1c:f203:: with SMTP id s3mr5771692wmc.138.1628019576384; Tue, 03 Aug 2021 12:39:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:35 -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 v4 27/36] transport: convert pre-push hook to hook.h Date: Tue, 3 Aug 2021 21:38:53 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:54 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: 12417243 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.8 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 3002BC432BE for ; Tue, 3 Aug 2021 19:40:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A55960EE8 for ; Tue, 3 Aug 2021 19:40:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240274AbhHCTkL (ORCPT ); Tue, 3 Aug 2021 15:40:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240204AbhHCTj5 (ORCPT ); Tue, 3 Aug 2021 15:39:57 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19FD8C061367 for ; Tue, 3 Aug 2021 12:39:39 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id h24-20020a1ccc180000b029022e0571d1a0so78915wmb.5 for ; Tue, 03 Aug 2021 12:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yem/csLCBuEtm+wciJ/HlPvXcvotFk/21uT1YnzVB1k=; b=rkw7awwH+JO9pn8umbLzMEV/CJAxWybtwvMuAzatqdLjxCuMlTtfEVZW1rbkPjFDLD lqYhH9wY9aHrmuK0nMUijOU2VNnzsMCpr8i8oGy5CE3VK/9SS0c0wMWKrJKdwemmcBZS bigGoar/P0K7xE+DFSo9FLi4bV7EVJgHKIhj31TDJjX51JUIGWiL3eRupOes2vtB9/oc 8QJbN1UJMtwAISFiGG+j1K/2M3NO0xvd+jdB97dsWfd1x49WKk0sh8RmN4gFNtL61ryl R7ZTOqiOZYAZHyPl1DDNsqIhVUXGw/gDprnHT5i6SSx2dhWW06M+32oE98kmKRcehgjD Yxog== 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=yem/csLCBuEtm+wciJ/HlPvXcvotFk/21uT1YnzVB1k=; b=g53P/sSgSIAuxhKlZeDyMHOY8bCFHaGF9GCmyeLEVrwCpAA6HxiUak/7/HFR379L9Q INO7JAwP0GraXcthaFSujVE01pW+v4pAmZhRwBjMruXYhmaudyleXNmCtJp1ENmYqj8r f/VR1iD2bt1fBQ9ixMvHpcfxeWoEVFY4rAgF1F5Z8CehKLs8oGj/ZBgxnsTIpQPugvEj WDrKCm8Td0Y/cJDBQ5BWy85I2rvjONI2DpYQs0muR0XuKZXIZectgJYK8LvMefp8JL+V jXBhTEDmSPmXdkvj1oKci5O3WRGBsuCpcglDi5b3bZ0h57LZoI+k6xy17sF3boqk+Kq9 Zp+A== X-Gm-Message-State: AOAM533miGqrkkTLkOcLBCHtxJx+9tj3TfGpJN0roMtIokvaq8auMQTO XsUvpXHiscpT4u7eX0H0Zli/a5FOaF1efw== X-Google-Smtp-Source: ABdhPJyXDoTL33ysvb0D3Tiurq4gcq86zDdwcw4r1E8f0cTdTFeT1cBlAK3F1e5sql3fyb/L5pIc/A== X-Received: by 2002:a7b:c255:: with SMTP id b21mr24102361wmj.100.1628019577415; Tue, 03 Aug 2021 12:39:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:36 -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 v4 28/36] hook tests: test for exact "pre-push" hook input Date: Tue, 3 Aug 2021 21:38:54 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 helps a parallel series that's refactoring how the hook is called, to e.g. make sure that we don't miss a trailing newline. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Emily Shaffer --- 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 Tue Aug 3 19:38:55 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: 12417245 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.8 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 4DB42C4338F for ; Tue, 3 Aug 2021 19:40:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34E4C61037 for ; Tue, 3 Aug 2021 19:40:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240251AbhHCTkM (ORCPT ); Tue, 3 Aug 2021 15:40:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240190AbhHCTj6 (ORCPT ); Tue, 3 Aug 2021 15:39:58 -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 E44BDC061764 for ; Tue, 3 Aug 2021 12:39:39 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id h24-20020a1ccc180000b029022e0571d1a0so78931wmb.5 for ; Tue, 03 Aug 2021 12:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PiqLEIHOkfureZWRUdx3XIkLM531MzLFlVZ4HciqwD4=; b=QdsoDq78URXWs6+ooGEAhKg6i5T0i23CAtvDsOEzYaqfwvAnqFxzMRreZ6ZWArDPje wj5EXOXJhkwjXQfZIzCd0AGbg31ALXgoul0FdkP7m0E7BJYeK7urWcK0g18upBywgEZ0 RGpdEwoOm8wo51Y7mhcreeRvYDccUG5N835AMelZdnZzvBTxVNLTC7xm7iSCGVKnDbaW h7VeI63FYjB5/PeFIlQCnp/Lzw9V8xLSw+R8tBec3jNEzBAhe2Moox9LyWO6AqAc+PT+ JjVApES2QtZy40BEIPNDIDIxds8vp3CcS1unj6xvHbz4MqVdLfZ5/LX5jsqVgEx3vYib KEOQ== 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=PiqLEIHOkfureZWRUdx3XIkLM531MzLFlVZ4HciqwD4=; b=m5Bu+NsNfjlO3bm4iHlCOwfvPQ7Ar8qAtGlAl0w073O7iq3xgbDs+PsNJAiy5G0t8U Qs4mJXE4dSVLrV5tgoLOpsmEG2qsqmvpAeqhut+8hP0gQrfT4WWMvfPFfl7UDrpCYZh0 RQ/hZ2RTi11Fa3ie8kv7KZ7OKWsBelHDYjHFE5S1Wma3ruP04suhApeX6iLLiojRI9hn XQEtZcKv9ZRdq07LpgdviPeyr8ZdEC4F37as1Ntw4SoJDhOrcokGWCKv6w2ZM8RbtdpU aEVatAIzZBc0n/+66iWiWX4wm0m7ykq9q7IKaeRXGRd5i7rlKNjt5vosMGLaDsZhFwb+ ZhVQ== X-Gm-Message-State: AOAM532qgpTHu6P1HZghjHjg5WJtnn2g1yZPZ910EwiJegNtFHr6Ny4h HsDK+JvwEXd1nf2kqm2m+FWVdJgK8dQ8dQ== X-Google-Smtp-Source: ABdhPJz1pOzoFNm954vbWeiyoo3vSZ36WlHMMHsnKMMGLiXrVZOiSGemBFDh2eerG6dq0+fHvCk16w== X-Received: by 2002:a05:600c:4103:: with SMTP id j3mr24431896wmi.12.1628019578296; Tue, 03 Aug 2021 12:39:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:37 -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 v4 29/36] hook tests: use a modern style for "pre-push" tests Date: Tue, 3 Aug 2021 21:38:55 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Reviewed-by: Emily Shaffer --- 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..6d0d5b854ea 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 <expected <<-EOF && + parent1 + repo1 + refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1 + EOF + git push parent1 main:foreign && - diff expected actual + test_cmp expected 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 Tue Aug 3 19:38:56 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: 12417247 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.8 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 B071EC432BE for ; Tue, 3 Aug 2021 19:40:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BCBA61037 for ; Tue, 3 Aug 2021 19:40:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240276AbhHCTkO (ORCPT ); Tue, 3 Aug 2021 15:40:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240218AbhHCTj6 (ORCPT ); Tue, 3 Aug 2021 15:39:58 -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 BC20DC06179E for ; Tue, 3 Aug 2021 12:39:40 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b13so15628482wrs.3 for ; Tue, 03 Aug 2021 12:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p9lxZ1nFhaiOgv1gjNp59SSY+ODJl8LIdh58BMvHMS4=; b=cEpzuNtX8FedseCbnw+xeExNIkSeiwDoE+F6SMsr69Uf9awgdNNFSWGEqbADc80O1H Ypx0xEdpZHFbB/z/SwcTLCjeWcnbp6w5bQGfQjqUL/xjFlj0qXvqD0V9EYj5pX6sq1xo Cd02pbRRSm6faq4m38VflMwWG7fdjmoS+21KMhyzUmb6p2IWOXYCBKdgPAGeZxvbEGPl gYZu3i7AgIo2PRaILThJoYs1h9nP0fkGhTuY3CkjP3Emgd31quX7gNIagErirvwFhLtu KCmBzkECcro5Ial3fWl/nkfpyana7gkLhILYOtFG7Flo0HsTNc4YVDJs3RPlYiz12c38 bamg== 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=p9lxZ1nFhaiOgv1gjNp59SSY+ODJl8LIdh58BMvHMS4=; b=s6UFVOe0nFTfK6c00ZIKg8TH37dMm2SMNkLDi/pJyncuz9tjqYCFXaBXVIDFEgnr4e 8rcT9VtGcGP12jJaewDcQ6WRJ05uExVV/q8cwWXpaMO7q6VM+URfqcQjXVzbhkTnPbho fnmGDV2EIpWpwlDTL5UY8Ncod1aDxiAF/1TbfyZCw6JHCtTUE+pvHCBIp2BDZ+3BB5jk 0RDPpjlJlqhkmBHeBFScMd0n5jbjyqnu4KmCE3+3Kfx91AFsH5J/5LsRQY+9Ysdd3gjE dFKdLrIWiwr2UJuKgAnQZtw99cWEcAHGpWq6s6knU5NHvxYJuDGMMAu0z2yS/4fvWkSs pDqw== X-Gm-Message-State: AOAM532nfhUxlx/ulwxAgLUakw3jhciPsGPML3wvAUQii1GXpucCtx8S GHYXrVvStUQ+AfxTXOHuYeG6YLFVQMrHbA== X-Google-Smtp-Source: ABdhPJyAEUPRH7tGMmdDj0SIaGOPmezoBgGb9UIypG0ldlAcau4EpJhrLMaFZkM7QwplejeZdWH/bA== X-Received: by 2002:adf:ebd2:: with SMTP id v18mr25516876wrn.248.1628019579177; Tue, 03 Aug 2021 12:39:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:38 -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 v4 30/36] reference-transaction: use hook.h to run hooks Date: Tue, 3 Aug 2021 21:38:56 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:38:57 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: 12417251 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.8 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 4795DC4338F for ; Tue, 3 Aug 2021 19:40:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3361260BD3 for ; Tue, 3 Aug 2021 19:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240268AbhHCTkP (ORCPT ); Tue, 3 Aug 2021 15:40:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240241AbhHCTkA (ORCPT ); Tue, 3 Aug 2021 15:40:00 -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 B36CEC06136A for ; Tue, 3 Aug 2021 12:39:41 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id n28-20020a05600c3b9cb02902552e60df56so114617wms.0 for ; Tue, 03 Aug 2021 12:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4zI/gMqONxIBLvn66riKCQkB3G6GvrSo7Cj/k69aKlU=; b=YJKU40MNT7Sh9YU+Lgob7ndRq2LTSH3z14FHY9TLNnqsjeXm+Apo2GCiJBHvTbA3Ya X4RNSlVGuvOK51+KuPgvPZTeQhfpZEbDRR2ZIuL5nBkFxdDz+pQbd1QSrk6IkoTHakkt dWBKh8BoVHbOpjzl34eDKuYGOY0cEXbHb9AqCNaj1ftIFK+ypU4/A2cNN4YWCXJaj7GG Xlkp3VKL6yyilQt1C7L/4WYbU6/hP4lk0HcUaBNy2vMg50sZmMRexZ97bxE1sZoAYekf ncDTAcCF9agvpsB8LOYfA/kK27FXKlAMevkbflDPDGXp5Aa3qIIXUr4JPGkooesgZVN2 ZABg== 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=4zI/gMqONxIBLvn66riKCQkB3G6GvrSo7Cj/k69aKlU=; b=By3bL5JPy9cNIyg3Jl30bFv+qpGa11ilYxp3cmw53Zh6SpjG/C7y2HPu2p16vJmfzo ZFb3ad3fp60W/1mMpkKcMGovErTmGrEQOp7pqQOsA9Qj0yl3rOxFe34dgxCbK6GpUyBx sevM2Hc5JtRc7Hj/d31a7VTTspO5eQutra4W7xFlfbeX54GhGmLzc8t5xZnTvjnSislO N8Z9uxhmqCoK9L5TBI3Oh8lTKY5PWn8L6wb/yuhjQPscRX1jXExY9BN31o1n9Mw8Mn2I +Gk9YJUll5ri+f0Mpb2PGacGnXlRpStC0HEsMyrI2UGiHZl/yFpo2zcwA7m2kRzbWKgh veKg== X-Gm-Message-State: AOAM531Aiq0dnm+syTQOxDo14F+yZROuDiUnkGyF+I39BEgoXAme1kJT w5X+kgW8867UaQ+Thf7qhdkCu31RE6I9wg== X-Google-Smtp-Source: ABdhPJzPcduXawfysn9VKFiVCp+Rt1BHSy0G8gT7DygjGUSSQJUDvwN7f1IfPFT0c+AOtKznroXqiw== X-Received: by 2002:a1c:2784:: with SMTP id n126mr4294771wmn.32.1628019580026; Tue, 03 Aug 2021 12:39:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:39 -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 v4 31/36] run-command: allow capturing of collated output Date: Tue, 3 Aug 2021 21:38:57 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 fef6e85d003..de14df5085c 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1817,7 +1817,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 f42ded548bf..e5e5a8bcfb5 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2294,7 +2294,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 44e73827800..9ae3007cdd3 100644 --- a/hook.c +++ b/hook.c @@ -203,6 +203,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 Tue Aug 3 19:38:58 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: 12417249 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.8 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 83B54C4320E for ; Tue, 3 Aug 2021 19:40:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C95560EE8 for ; Tue, 3 Aug 2021 19:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240218AbhHCTkO (ORCPT ); Tue, 3 Aug 2021 15:40:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240222AbhHCTj7 (ORCPT ); Tue, 3 Aug 2021 15:39:59 -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 798DFC06136C for ; Tue, 3 Aug 2021 12:39:42 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id c16so26472221wrp.13 for ; Tue, 03 Aug 2021 12:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mvW3V7M+OI+BgkcwtyCLIYcAP2tVMxhrTUAAeJ6vL9I=; b=ftavWhffpyUguFy++suVR7o1V2MxBRu0cGBpMPXf5O6VvFMxbzrSVkpcN+WB76BaBh NTccn9Sh/NEHCD4Qr/k0JgfldXeoj9eW/cS0GmNISk6gorDoX6+DL53S6PVaqoinru69 KGGwHuYGHtOL2RaLzilROsRlTt0mztG/5oBhqBHjFiFXEPrhDEbrkSi3tguJI5FlS33Y udOlhjOxA/q1SMnLrRppHHuDg+CzV/C04eXJtzOnB4vrRBXjZjNQK5fshTYd1AX/w9lc O+krdCTti3c+NPkQ9fGJmhosBU4l6gCEpfDDvi0TpjsqZq4ILVpokgtA3NzLxar1+dPb A8UA== 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=mvW3V7M+OI+BgkcwtyCLIYcAP2tVMxhrTUAAeJ6vL9I=; b=pQAOemBR91LPnzTJF2lFZM3x2Yi/whammxOELaUU6go1fCdZeZGMZk8/ozaKM6dAqJ +i8EPTS1plKEVuoYKczHn5SbNqQjl25sDZ5xdr2d7GvC7Xv5fGS3ol6mXa28rgUrntL6 kmH5/wqKqTptfaiL62huq82QQ45yzCZsvuq++w2WMxNFXpxQhjC3cU3UJbe0j1vNSdc7 /QtrJ4A2QWW7wx/O09jsXQ6hY8kLJ+Y8MCnwSknxpLFVvfIkRrNEEQTyj9+H6m1T2MQb w+nrbqjz2b1uz5N0bDXCNAFfTeM8dQlT2Aqt6hRnDlkpSIrRv+TW8s6RHilUoKtAK+PS LQDg== X-Gm-Message-State: AOAM532hEy0woHOZa54CGli6CkqlwEbM5U2yG/MUBJm6Iu6SPHfK4IDZ 2aYhprHITC2BM8dQYIOWIaFn7uiIIn1R1w== X-Google-Smtp-Source: ABdhPJx/zwJoEjd6ZG2Jlc7Cm/nZj10AF9QFdFCGfhvvbys2RXb1AGpwAeBoXyykC03LD7cYTuhy3w== X-Received: by 2002:a5d:4b41:: with SMTP id w1mr24035994wrs.367.1628019580809; Tue, 03 Aug 2021 12:39:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39:40 -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 v4 32/36] hooks: allow callers to capture output Date: Tue, 3 Aug 2021 21:38:58 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 9ae3007cdd3..efed5f73b4d 100644 --- a/hook.c +++ b/hook.c @@ -203,12 +203,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 b55f283f90b..37a9690c2ca 100644 --- a/hook.h +++ b/hook.h @@ -58,6 +58,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 Tue Aug 3 19:38:59 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: 12417253 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.8 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 3D3E4C432BE for ; Tue, 3 Aug 2021 19:40:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28C8B60BD3 for ; Tue, 3 Aug 2021 19:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240267AbhHCTkQ (ORCPT ); Tue, 3 Aug 2021 15:40:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240246AbhHCTkB (ORCPT ); Tue, 3 Aug 2021 15:40:01 -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 89B77C061372 for ; Tue, 3 Aug 2021 12:39:43 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id k4so15680785wrc.0 for ; Tue, 03 Aug 2021 12:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ta169ZOJ+RmhDlceEmLLsVIdLxFZcY00Al6FLOVtWD0=; b=rRremnwAVKpgfy0OYnGMNQ46sjY/KRjRcGOsjMkJMBspc+Ii4cXssHepTPQkwGMRJ+ MgVjRY7Y0SBlq2mbnBr5OWDeX+0gZU9BH+SGrjIPpfU/cMBUXI59Sl8Y4u81ssjskoWb MNSFF47B6oFSy1tnSv6qaMLf+ypOBbHWmSpC6vJHXzsIoAG7y6qfsxK1Ylze6GoLp79j u+yoj3aOSCZJjcHgdm0pNpgt7j9Hti98dskb0v14Ocn98qqcdOXCFHRuqeiwMnFqWz0o A3J+RT4VZ4AdAAuG5jGs25Xm1ncWX9fxTd7s5sur7fHi5X8c2fMu+dUvxPjRLE1A2zWO kJIA== 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=Ta169ZOJ+RmhDlceEmLLsVIdLxFZcY00Al6FLOVtWD0=; b=MtlB8abKWp2sn+iG3PvO0MKlpJdhvRKaIpWWs8czvz8v+7MVgYIy9bhiEnFOf527FN L3DqEtBlEnyZmpVd7VKiz49FmVIr1Xv6QZyVPJ6lx+cpyyXLXbVUf+3vHgMMTx3bnafA R/n32OscfXoWXqdbRjO/M6fkat8gENsQ1GBK6CcRIQcnIWupZVeH7VSRz5SXEORhLpNt Y/1Eyd9MAj8WsSITEboM45o2QaYLpNpCoxGlpbBfOXYWXVEpCRFAMk+aLHRwZiN2TKEz RQmjL8B08O3Ah+AkDB2NB0oGolMoIQJ19S+kyUuQFL76LSYRVTu/EJQ6Auj4AoKm//zz zmqw== X-Gm-Message-State: AOAM533u9l+0P5XUJmYTeBWxHo0VW7bUstPQLCp5ceklKCR2AVRINg4F nvT6Vslk7Stz2BV6Bqx0PivwVLsjkES1zw== X-Google-Smtp-Source: ABdhPJy6lp/u2JLCWjF9pYKIfiHlAT86vK6u1DchRqikFTLcoKnUgdo2v53ukRCCU1Yqx+F2vJO4Zg== X-Received: by 2002:adf:f845:: with SMTP id d5mr15447531wrq.267.1628019581848; Tue, 03 Aug 2021 12:39:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 33/36] receive-pack: convert 'update' hook to hook.h Date: Tue, 3 Aug 2021 21:38:59 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:39:00 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: 12417257 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.8 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 E6CD7C432BE for ; Tue, 3 Aug 2021 19:40:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB92660EE8 for ; Tue, 3 Aug 2021 19:40:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240281AbhHCTkT (ORCPT ); Tue, 3 Aug 2021 15:40:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240248AbhHCTkB (ORCPT ); Tue, 3 Aug 2021 15:40:01 -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 7DD08C0613D5 for ; Tue, 3 Aug 2021 12:39:44 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id b13so15628614wrs.3 for ; Tue, 03 Aug 2021 12:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t4H3xaN0d4Gpz07+4ueidJHFlNnY5PP6O7RkIfFF49Q=; b=XhUnoKzw61+SQWBLGVE/VgSb4l6M8iMSC/r9HU/O/jKDB6kHdQOLA+CxwGj5tb/wQ8 htKFzWY3Ksgrfhsvlp2lHijk153N8co11pc+HZoZc1J/ORr20JFg37hKBjYQHKP1Cc7a Y+CIc0GA5/MOYNcFQaRyqCxljbqvuKDHhO7rLVoKGfz50j6PaKqAcriThYtAolG9LC3P BtFQm29OhyL4l5GCcm3MlcwYzMdYv3kdkCfPh5NC9+H7m9nFkOZAmiw5CEFTBOrJoZaf dSlzzwwB5MosrlSxulhawZHOYjqu8tD+JD+39jWozU7cd1m8WL2yH6M7fgAnju60nX0F NVwg== 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=t4H3xaN0d4Gpz07+4ueidJHFlNnY5PP6O7RkIfFF49Q=; b=sm0VYuGxN8MjDQSn6YjvM51Hdhuv/CIjtL926gyyqN9mk0MA0UtbN0OG/1TJJTtYwS sGDDONJnU7p978VQ+sL/kXlTQmfIUBfXrZv5b21MLKD0WQpnLYXfeipMJcgRji1azpdj ma7f9M7vzRH1sQffMB/Ns9GrsyitoePE+5MXVkc0yCJSh/Yl/FpxE0AWg5f5k8k7nKFn nDDlvVaPSC/bF/bp3TQjUxcHaxhvtP27yJ70zMlyD8e+WgmCAd5iC+X37TwO8U1xUfaj 5v5F0ujJWC6tAoVBMWs/iJgSb2iWbvpf+khF7S0zpq9QbOUlaseW4KvzTC9RoE5oHFxV o1tg== X-Gm-Message-State: AOAM532+sTW5Alr/PVUP/czCn/62s0g//m0ODzKm5IRrL4eR7iCVE9Ak Ew8EexdfS+OsLzpY9OcVxlGify9BEYcolQ== X-Google-Smtp-Source: ABdhPJySi+895Gmm5Gl1ApK0lcfGZ9Pzy65wydHaX/zwEMv325VxIR8rolN+EeRAc2zcZB3Ifr80NA== X-Received: by 2002:adf:d225:: with SMTP id k5mr24529431wrh.10.1628019582894; Tue, 03 Aug 2021 12:39:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 34/36] post-update: use hook.h library Date: Tue, 3 Aug 2021 21:39:00 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:39: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: 12417259 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.8 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 D2E32C4338F for ; Tue, 3 Aug 2021 19:40:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B83BA61037 for ; Tue, 3 Aug 2021 19:40:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240264AbhHCTkV (ORCPT ); Tue, 3 Aug 2021 15:40:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240252AbhHCTkB (ORCPT ); Tue, 3 Aug 2021 15:40:01 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67696C061757 for ; Tue, 3 Aug 2021 12:39:45 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id h14so26470173wrx.10 for ; Tue, 03 Aug 2021 12:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AK5kx12g+auXj6+2QwqqEtxeKo9cA5xEdlPXGaf/TQw=; b=emtpXKcQcf3wLxTjtOqm+MDwpulLf032uIb24nrviGsMDYTqcDM9iyW5K62H0Twz/q 8Cf79cz6OtaEj+F7n4iriGodCpCK1ppyk3Y/neeVbVNp0mpVHNRBuY/4qPKgjRKx3eE7 NQe/FeGa71F9ZznOipyozd+jvfOjTeenaWGGtKvgyplL8aDS/bYeaVFszkCrU5RkCmVK GNsHr4NbA2xFJBQ3nwAjq2kJBhD9QKMnwF9feOVR1+nlhCPTqmMG91f49ar8wMfmQGXs 9tcxitMq++GB3xlHeKHxm00pp2vGKC0O6rpKeHBt5IIhb9WRbBFwpX29HJaBl/DSj14V l4oA== 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=AK5kx12g+auXj6+2QwqqEtxeKo9cA5xEdlPXGaf/TQw=; b=Rqdu5ZqCoWwyzXPC0CFn4jSkHjWOTsfp/JoDL4hyhV1Hr17d0BltQkN6wNYh9GfoyW XnSqEoX9XEo4YewF5n0fTs7ydYORbmHH0S8K3Ihkezd2d/iWKeS8ZSX8UgEb7VyB1S4f m+HGqFPCD75GRzB1huj2AppIMstXepVDK3IM0Ouvq8m7JHBOpAS1mZJ32wZIc/lHeBgv k1goxvgM4PTf9/kr4+xlMsEH0BnMFRnQxWadXK6Aes6s4K4cwteg+TVmYhFn4v6PCTfY KHL93ZIfviYmzT7AR9jrykQiOAnLwnXtuydDp3mr4ed9Td5tNFg1AWxvuhFsE11W4EyJ JlnQ== X-Gm-Message-State: AOAM532K37YlghHd1bKoLbk65A1eFpSh4UihbMEto6AivuUW0smpIbFd fyiWH89L2M7jlvX1mLgCqK7ixRPuBrS6AQ== X-Google-Smtp-Source: ABdhPJx6D4QyOYl0rK0gNb3jArNU3TnNNlLp2IIkVR6+oznAUhwIoNJf7gFcKihaIHgcSA3tlF1fFA== X-Received: by 2002:adf:fc8b:: with SMTP id g11mr24693187wrr.224.1628019583715; Tue, 03 Aug 2021 12:39:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 35/36] receive-pack: convert receive hooks to hook.h Date: Tue, 3 Aug 2021 21:39:01 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 Tue Aug 3 19:39: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: 12417255 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.8 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 D3456C4338F for ; Tue, 3 Aug 2021 19:40:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC4DB60EE8 for ; Tue, 3 Aug 2021 19:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240270AbhHCTkR (ORCPT ); Tue, 3 Aug 2021 15:40:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240247AbhHCTkB (ORCPT ); Tue, 3 Aug 2021 15:40:01 -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 65F5EC06175F for ; Tue, 3 Aug 2021 12:39:46 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id b11so21164841wrx.6 for ; Tue, 03 Aug 2021 12:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+4Wfm2lUXpamhTYzmEv/waXn4JJ/ex7sYpGBriLWUzo=; b=mGYvmp5iPlSCZ1uFCG7fMU01ss1FLaXN5Qd8LcWJFCrdSVoSn2EmePyXf5ZIiwLwgT JPwB4JHSCk7IdhkSIcDiIzlCFYEFec8k8IK6aa/NF32FbX9XQ02cPTTYkHi1lt9kTUt7 MkcaNvuHWOD28RCA7lV2NbxOtW3GkynKi2nOjh0oBYCEz0VkJSynvFcYJrJL/U+vx+Hx 5znHpnyLNxDnqlw++ZT86DycB6FqLH2bt2QxeiHeF61gRnT6ivj42PY/wtpyYSPQqGkR 36imilP7nOo+/J4dF86bkRTp3njQR05/koewrgVtSYmYLXp8iocZT9BnVyDaGbx//DHR KXlQ== 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=+4Wfm2lUXpamhTYzmEv/waXn4JJ/ex7sYpGBriLWUzo=; b=AGsxyTzeeMCdKgaU64SkFxC/4UL9D64EpvPBf6zfs9i5PM3B+I41nh/G7NZf1jZbKo VviCmfeu/5TkaZEw2BOig86xaUXV9o/re+XbDSN6Usy8SBiCi8lZXcmMo+aGP54ljegh TGETjT3zw5EdP0b/QDlYU0ktsAcfsY+Xz1W5D4lDFKWngfH9hpqKvrLZkC6DzTjWSdxC RHSgXS26Kkjy7WZ6Ep4PEHiMqBgH7A1kbplmRe6qjwe1f8rVvgpeWZE7appEbrg0VFFy Nj9ex9sEcAHi3NSGndL6fgoXYJdrierPsnfVj07ArMTpBoN5G9/gTpZgICga9C4sdBha HkwA== X-Gm-Message-State: AOAM533BEVh439WJGDYNSjwVf/lWTvb0krLW48Siky+kfFONWNeoBqU+ SEHlM7RBpLGN/9ECmhfcO3kHXiSBebZLJw== X-Google-Smtp-Source: ABdhPJwdEo5+3zqXc7Xw1okWPBLkTJyJQ2P8rL7r1NWKyX2XP3BCvFtydyOs/mjgCyxJTNRtDOLdGw== X-Received: by 2002:a05:6000:248:: with SMTP id m8mr25230922wrz.145.1628019584523; Tue, 03 Aug 2021 12:39:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n8sm15333562wrx.46.2021.08.03.12.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 12:39: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 v4 36/36] hooks: fix a TOCTOU in "did we run a hook?" heuristic Date: Tue, 3 Aug 2021 21:39:02 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.593.g54be4d223c3 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 aa3c741efa9..0b7642e8324 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; } @@ -1840,7 +1843,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 4965df2ac29..9bd4a2532c3 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -843,15 +843,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); @@ -872,7 +875,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) { @@ -881,7 +885,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 efed5f73b4d..ee20b2e3658 100644 --- a/hook.c +++ b/hook.c @@ -173,6 +173,9 @@ static int notify_hook_finished(int result, hook_cb->rc |= result; + if (hook_cb->invoked_hook) + *hook_cb->invoked_hook = 1; + return 0; } @@ -187,6 +190,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 37a9690c2ca..58dfbf474c9 100644 --- a/hook.h +++ b/hook.h @@ -66,6 +66,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 { \ @@ -90,6 +99,7 @@ struct hook_cb_data { const char *hook_name; struct hook *run_me; struct run_hooks_opt *options; + int *invoked_hook; }; void run_hooks_opt_clear(struct run_hooks_opt *o); diff --git a/sequencer.c b/sequencer.c index 77f809c00e4..f451e23d0c1 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);