From patchwork Wed Feb 8 19:21:11 2023 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: 13133626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E1F2C636D6 for ; Wed, 8 Feb 2023 19:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbjBHTVl (ORCPT ); Wed, 8 Feb 2023 14:21:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbjBHTVi (ORCPT ); Wed, 8 Feb 2023 14:21:38 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08FC756498 for ; Wed, 8 Feb 2023 11:21:36 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id p9so7717928ejj.1 for ; Wed, 08 Feb 2023 11:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nD/udz68tVw54g+vFm4Vjo0YIwfa9GkUBWib6qtPmWM=; b=CZDAw/JlObEnvek94VsmcKGNcixIbnQOxiV/5QSIAkEY/1bl/xUAgjTzL3pfIS67Ah No0y2xXqHLWlsx2YPV1ryjfUB33G8MpbmTP6xvooYOK34Mu57ySQtmRF04PuTHidgmre ANAiaI49jWWxELiz4lMoD8/I8hsaJN1WGqBZ/XmnMw9ygKG9/6U3er630F9rt7mMhiKo FIeHRP0+bJMKgTR3p1aemUgI7VbHavl4h/pwXaE8gv8Yi8o6AHFZJ7I5sWfrG2E53KN5 HNhkvhgkOnz/pEDfVmeMEngrSBuiXmIhKpmnlUTck3Z7R7j/lujFIS0JqfdEHyRHDIRd /V8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nD/udz68tVw54g+vFm4Vjo0YIwfa9GkUBWib6qtPmWM=; b=7Hs8CCiSVWfmNRwtFr8QzyLmlaHJjNnmVFAaIATeFajpKOIv/yvqwt971ggKNfPM9w 8Y9htdr6wW03D3FOkiS5FAT+CikwYFa7RwmZ+4u89VHPaYfekuandFRQ026XhFgNzPaW mVzqLFDTttVGj+S5vDuwABzACQ23754ZF2ldluAQzp7hcllVntqhPZElzsMy33fszxJW 56lE8cVPxciH1hvp0bWVIOaecWqnXCFiRubJLZRh08++5xoAllrPn4dhD67IqZEvEJz5 QcEDkuNJ9UfHjJSFhlg/8oimckeghb4APZZCTL/t2VoGrgpF96wtoN2Pgp6Xx+VSYFXt nBbQ== X-Gm-Message-State: AO0yUKUWVG/Siex1azr0utUicjKwIy0WuX9gIzgKZnUBKg7Oe89GVQi3 TmPTRSceYsl161zLbLcza3EA1MW+9TqKx8jC X-Google-Smtp-Source: AK7set8o8Uj9G6xSeoJIk9h+RvS1Z2FlTDbIe+AHIEdPaqIpLJJrX3fjvVABDo5jA2ejxYrOQhH7lQ== X-Received: by 2002:a17:906:db0d:b0:878:61d8:d7c2 with SMTP id xj13-20020a170906db0d00b0087861d8d7c2mr12424162ejb.39.1675884094165; Wed, 08 Feb 2023 11:21:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e15-20020a1709062c0f00b008964fdd5bbfsm6244227ejh.155.2023.02.08.11.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 11:21:33 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Emily Shaffer , Junio C Hamano , Eric Sunshine , Felipe Contreras , Taylor Blau , Michael Strawbridge , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 1/5] run-command.c: remove dead assignment in while-loop Date: Wed, 8 Feb 2023 20:21:11 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove code that's been unused since it was added in c553c72eed6 (run-command: add an asynchronous parallel child processor, 2015-12-15). Signed-off-by: Ævar Arnfjörð Bjarmason --- run-command.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/run-command.c b/run-command.c index 50cc011654e..b439c7974ca 100644 --- a/run-command.c +++ b/run-command.c @@ -1632,9 +1632,7 @@ static void pp_buffer_stderr(struct parallel_processes *pp, const struct run_process_parallel_opts *opts, int output_timeout) { - int i; - - while ((i = poll(pp->pfd, opts->processes, output_timeout) < 0)) { + while (poll(pp->pfd, opts->processes, output_timeout) < 0) { if (errno == EINTR) continue; pp_cleanup(pp, opts); From patchwork Wed Feb 8 19:21:12 2023 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: 13133627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C26BC05027 for ; Wed, 8 Feb 2023 19:21:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231810AbjBHTVo (ORCPT ); Wed, 8 Feb 2023 14:21:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231573AbjBHTVk (ORCPT ); Wed, 8 Feb 2023 14:21:40 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C387564B2 for ; Wed, 8 Feb 2023 11:21:37 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id hx15so53566884ejc.11 for ; Wed, 08 Feb 2023 11:21:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=96BbuNrsta3M++1CyknaUQDLObubEczaFZyb1SKal0M=; b=N9Pb7kDgSwHfOo45jn/dyW5IILvg144NGUqY1oU7nm7foe77/aBqD142yWKwVJJNc0 YznNhnbN/jRy8etpyZdIJhtjmLJ4KJ6Dh3iS5nP8GicK+MtjKhgtcyl3EitCHdXEvBoo Pg9Wz06KyVM8sforInadVMJeAmdyHnBf5YH65fsWvd7Ig2zzfka4Cedp6EYzsB7g2j+A zlH6m9YEyoIfdr43TNJGcvaCGz+t98Iv1RPTZYlsp5QAr+vM2e4bcoU7++RRHexAW1z2 EVGIKeg2JcP6o1T8ZtxAR3cCRYajYPCHFpvYO48PKHL1mR/4LyeAVBXy9hrII2xqSJAp V1uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=96BbuNrsta3M++1CyknaUQDLObubEczaFZyb1SKal0M=; b=TxVVc4zf+bNPzITaXaaP15LwJGHxU3MP2x29Yb07DGdpU3/wydsvM+xHgQRIrfHAzg 4YTVw19+EQ7zF1tAv/OPACx+P6LntV3rjS6DmzoqruQFwZf1eciz5RT4UcXIMz0nUtqG FmPosoJzTDBeWMGeia10Hfj1YX/6D+m8sTSt1MS6I4GYms1Qmd0CvQPCslAHfOEnLgPJ yyPrzNEMtFRuW94XTB2egX0/DfSNRIHIcIHRhOVCwMhHMf3NUJDZVgNW9xUBizuP4BGv 8hF4SwWe+uEj89iHv5OLR7iEeCEx5Ncv/hkJMKCdCzHwRUr8zPd4XUPGfcR0YGMw/wUy q6VQ== X-Gm-Message-State: AO0yUKV8rnXKTGcECi5sBm1geNuFtlnoBsTfopeW7hXsIwxOE9w4zvO+ PaFyeRKFlRObTsV4q5oJXN0lz1WyVWvUoIOo X-Google-Smtp-Source: AK7set86xj3X+gFu3WiseABumzfYuf6Y+Q+EHS/UYJBAMRaLLRh6lwCuSQsjtmi3rmBsm+1KFxS7CA== X-Received: by 2002:a17:907:6d03:b0:8af:22b4:9952 with SMTP id sa3-20020a1709076d0300b008af22b49952mr2019552ejc.38.1675884095240; Wed, 08 Feb 2023 11:21:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e15-20020a1709062c0f00b008964fdd5bbfsm6244227ejh.155.2023.02.08.11.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 11:21:34 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Emily Shaffer , Junio C Hamano , Eric Sunshine , Felipe Contreras , Taylor Blau , Michael Strawbridge , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 2/5] run-command: allow stdin for run_processes_parallel Date: Wed, 8 Feb 2023 20:21:12 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef 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 b439c7974ca..6bd16acb060 100644 --- a/run-command.c +++ b/run-command.c @@ -1586,6 +1586,14 @@ static int pp_start_one(struct parallel_processes *pp, if (i == opts->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 = opts->get_next_task(&pp->children[i].process, opts->ungroup ? NULL : &pp->children[i].err, opts->data, @@ -1601,7 +1609,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)) { if (opts->start_failure) From patchwork Wed Feb 8 19:21:13 2023 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: 13133628 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E394C636D7 for ; Wed, 8 Feb 2023 19:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231823AbjBHTVx (ORCPT ); Wed, 8 Feb 2023 14:21:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231201AbjBHTVm (ORCPT ); Wed, 8 Feb 2023 14:21:42 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1673351C73 for ; Wed, 8 Feb 2023 11:21:38 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id u22so9073900ejj.10 for ; Wed, 08 Feb 2023 11:21:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AVSJaj0QMhRtZU5yv6Ks2zyXX5fJPkcIZf+m8Mauzv0=; b=j4+1++UpxUZozetS9pnjJkai/H1QADohs8o+JscCFx+PBnBD2OCZGF1dHfrjQZhAn4 SEkpoYVCA3QJE+z/aBQgq4my1ca7PDvHwxHpHA8OCjK3AK7QQcrIrKFPoyX19T732WGA /X0cIVgVg6vcSyzGESta6N4WIOxdpsFW/+cMqScqgrnaseIfbH/If7Yoig+GUBvH49Me bTWsEYJJzE63WOGJ6i2JjA3KGTcTK41khzCYrWC6CGFicGABfiuZ7gF5/8HBew95tyre o4XYnRHaoyeC/b5qmN/dWRlEIEIfG7X6vLUy2gtTIvRAK2Q60NgmktRFFRGd9q3t/qX+ EH/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AVSJaj0QMhRtZU5yv6Ks2zyXX5fJPkcIZf+m8Mauzv0=; b=2sk2Xp90DMpO1Bh2Ha+IwpGRPPmliq6bjvWWzr2EX0PxwcJ8tGAdQKPQoANfq2gr0c 3NyeU9buZEHyl7UUf+2QrXgz+TdTsaAFQ8mpvhNkrLoyQNpJrmlv0YIMl1N8pw+9rS4R 72FsMm/tsjThx6b279Oqm9PSNjGU7KyR+Wy4us9FaSi+3hJbn+JYDyj8wA93fPp2lQqn JMDf1aLb7OUiR2E230v2xHOjDtmwduPyhTYu4+mLA6DDdlF7cX6fffFWnvJC3Hx2k8uV /A/g425XngN9atMdpYF1IIPgc3iBTBoxYyNfyhl7udN2tD15EXqSkdH0417/Jr8PFwwv 8Fzg== X-Gm-Message-State: AO0yUKXYjZn5Wi6hdWGHI4DVUWhEcEffFisAzBpTj9MHia4v5eyJI8Dq 6l/Monty65R6Nl/aetOBwQ/nem0raZpbmhjl X-Google-Smtp-Source: AK7set+pYXY+/lWcgOvIbl/VAe74IsMQsg1BK1eF7/8ABEb5NM/ZYD7kFc2uAKdBJdzj54cahXaKhg== X-Received: by 2002:a17:906:fd8e:b0:8aa:f74:3252 with SMTP id xa14-20020a170906fd8e00b008aa0f743252mr10083604ejb.2.1675884096269; Wed, 08 Feb 2023 11:21:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e15-20020a1709062c0f00b008964fdd5bbfsm6244227ejh.155.2023.02.08.11.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 11:21:35 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Emily Shaffer , Junio C Hamano , Eric Sunshine , Felipe Contreras , Taylor Blau , Michael Strawbridge , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 3/5] hook API: support passing stdin to hooks, convert am's 'post-rewrite' Date: Wed, 8 Feb 2023 20:21:13 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Convert the invocation of the 'post-rewrite' hook run by 'git am' to use the hook.h library. To do this we need to add a "path_to_stdin" member to "struct run_hooks_opt". In our API 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) once the hook API is made to support "jobs" larger than 1, along with support for executing N hooks at a time (i.e. the upcoming config-based hooks). Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 20 ++++---------------- hook.c | 5 +++++ hook.h | 5 +++++ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 82a41cbfc4e..8be91617fef 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -495,24 +495,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; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; - strvec_push(&cp.args, hook); - strvec_push(&cp.args, "rebase"); + strvec_push(&opt.args, "rebase"); + opt.path_to_stdin = am_path(state, "rewritten"); - cp.in = xopen(am_path(state, "rewritten"), O_RDONLY); - cp.stdout_to_stderr = 1; - cp.trace2_hook_name = "post-rewrite"; - - ret = run_command(&cp); - - close(cp.in); - return ret; + return run_hooks_opt("post-rewrite", &opt); } /** diff --git a/hook.c b/hook.c index a4fa1031f28..1a848318634 100644 --- a/hook.c +++ b/hook.c @@ -55,6 +55,11 @@ static int pick_next_hook(struct child_process *cp, cp->no_stdin = 1; strvec_pushv(&cp->env, hook_cb->options->env.v); + /* 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); + } cp->stdout_to_stderr = 1; cp->trace2_hook_name = hook_cb->hook_name; cp->dir = hook_cb->options->dir; diff --git a/hook.h b/hook.h index 4258b13da0d..19ab9a5806e 100644 --- a/hook.h +++ b/hook.h @@ -30,6 +30,11 @@ struct run_hooks_opt * was invoked. */ int *invoked_hook; + + /** + * Path to file which should be piped to stdin for each hook. + */ + const char *path_to_stdin; }; #define RUN_HOOKS_OPT_INIT { \ From patchwork Wed Feb 8 19:21:14 2023 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: 13133629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 588E2C64EC6 for ; Wed, 8 Feb 2023 19:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231387AbjBHTV7 (ORCPT ); Wed, 8 Feb 2023 14:21:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231804AbjBHTVm (ORCPT ); Wed, 8 Feb 2023 14:21:42 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D25251C60 for ; Wed, 8 Feb 2023 11:21:39 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id rp23so2583033ejb.7 for ; Wed, 08 Feb 2023 11:21:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v4IqOqJFnNv43KcGny+BezwjI5ZJOkPyfhzT7Mevgag=; b=pQJSeb6zRZMFhKBCDcC6vpDvlptxSmL/BFGZ+WNqyGtFTjiEnPhMmjvpUKZkowaw/i coDaNTsm1k21Z2PU26AZxyFBHFEOuoXbStx7jVImCwOsco7hV/v6k6fRNOrbomoU6I1e I2Ed5VvmX2XS2BpVeIAqZ+LDd0qu9C5IIoD+/BgcTcGrIA9zkVKU4RMpc4VaKCi69g9+ 5ofECuJVYKkn/Xjzrv2XUVpIdgApf8AYHAYJOXRtXeZ7msQMLa72DpZCoJkfrsUqU/kQ lGeazzNLx9Ee8Sm3DxrsvtYW/XB8KbhUrV5whNhUSN3mduIsgEjifYv7PT9VmKdKk46D lOvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v4IqOqJFnNv43KcGny+BezwjI5ZJOkPyfhzT7Mevgag=; b=78mAJZjaz+Kbxgvi8NjaMGFmFamH8ZxvG7Wlq/DD1y7JoBEyHOnDq/UmBXzz0vves3 pYMcw4gkiA/4O6W9AiLEMcvbyevUdaBnbDmFi3/gv6bwGgDIhbIgOfxmQWqxyzMtgcS2 AMDKtbHzxOkf1LpHyfr0MnEdNSRnoYwbZNT0P/cSo5cusq151P3HS8pJ4gyaF8O52gnw U7cxLQE3+anS9+XPDGdOgfCQolaAkjqbHkx+NJn/1RUN1rfNrDLdwUlQWrgHC2oMaY6h fnq74V3dpsd442IFK1fJ1U96z/ofCpm4MNBosw/1p9Xi5xqiuZRC4Crkc5PMYPPPivm/ PA/g== X-Gm-Message-State: AO0yUKVvmmgx1OwJm3fsFC2HqyP3tFTr/pFH+wLq90a5QBbkSomQQtB2 mqyDwxvsabZi3or1GCl3T1rnSqfZbqEjXbB+ X-Google-Smtp-Source: AK7set/1P3RO4291sjEy8XLQiHHIxuZ1ti0SeV9TaVrpJbf3GbspSj/kTXmxCvUfde4JjB7QAriuGg== X-Received: by 2002:a17:906:71c3:b0:888:4f0e:bb72 with SMTP id i3-20020a17090671c300b008884f0ebb72mr8005536ejk.40.1675884097487; Wed, 08 Feb 2023 11:21:37 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e15-20020a1709062c0f00b008964fdd5bbfsm6244227ejh.155.2023.02.08.11.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 11:21:36 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Emily Shaffer , Junio C Hamano , Eric Sunshine , Felipe Contreras , Taylor Blau , Michael Strawbridge , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 4/5] sequencer: use the new hook API for the simpler "post-rewrite" call Date: Wed, 8 Feb 2023 20:21:14 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Change the invocation of the "post-rewrite" hook added in 795160457db (sequencer (rebase -i): run the post-rewrite hook, if needed, 2017-01-02) to use the new hook API. This leaves the more complex "post-rewrite" invocation added in a87a6f3c98e (commit: move post-rewrite code to libgit, 2017-11-17) here in sequencer.c unconverted. Here we can pass in a file's via the "in" file descriptor, in that case we don't have a file, but will need to write_in_full() to an "in" provide by the API. Support for that will be added to the hook API in the future, but we're not there yet. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/sequencer.c b/sequencer.c index 3e4a1972897..d8d59d05dd4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4834,8 +4834,7 @@ static int pick_commits(struct repository *r, 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"); + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; child.in = open(rebase_path_rewritten_list(), O_RDONLY); child.git_cmd = 1; @@ -4845,18 +4844,9 @@ static int pick_commits(struct repository *r, /* 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); - } + hook_opt.path_to_stdin = rebase_path_rewritten_list(); + strvec_push(&hook_opt.args, "rebase"); + run_hooks_opt("post-rewrite", &hook_opt); } apply_autostash(rebase_path_autostash()); From patchwork Wed Feb 8 19:21:15 2023 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: 13133630 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D9E1C64EC5 for ; Wed, 8 Feb 2023 19:21:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbjBHTVz (ORCPT ); Wed, 8 Feb 2023 14:21:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbjBHTVm (ORCPT ); Wed, 8 Feb 2023 14:21:42 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A5A8530C2 for ; Wed, 8 Feb 2023 11:21:40 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id hx15so53567274ejc.11 for ; Wed, 08 Feb 2023 11:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0kySIHZO26mFqMGbpAbUgN0QT4l0xqyf910mX7ROvzc=; b=l9latO6iEmcGAFRJC/1hE1iKPvRIBjzpQiDug6Frb/NinzV5fR83TSMP7rRqwUoO3M Zb0ejR4IZ+CMRo5MTgYmZR1rMyTSgffKJIQVh6bql8jvvxhE0o37V6vjpl+6MlgfFlLb EAGvRsUgAw+XxQMwUrdjAZGR1zV0pQiTzVtDrPb6uff/xs6gTduAz2qsYyqDvf25+cy1 /8kF+45KZAZX4I9wDyk3WHqY9PEoA1Ld2c3nvwLkqagIZAwRVeTmQn81pvpUTx8H6aPH GAIsm2Rbx2YOtd6tWyNzFAztreuhUoCGcxzEQq5bWqC0vQzBB4xbZDqvQJlRmyJWAIur sS4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0kySIHZO26mFqMGbpAbUgN0QT4l0xqyf910mX7ROvzc=; b=qom0n0aYY62XwY3Y5awBBtdaqLBYKxtSkzcOQBUCxVBJjiWau7ebfdANmx70MuX2eB 8IgUAnRNptJy/44/3GJ0Y1uNdqCBmWGfszFD+/QiDAHUY+1BcMTMegOTWW9qIDX0+PeR KseS7rKq8OCDobehrHmP5jObKVhbt25f5Y9y7KFmGHR9hoEcvWgnb+FLepfSYwyWfQ92 D7DuwRZBljFSU7oAumTzNTGCwNXcdaYsBB3ioSx6pmP5NTuMObjo01+3ssKC90Uye6K9 Y2LqGp0clJCJU7d/zQ26kR899hN109EvlNzt4I9TxtiTmyL1tYrbsByRAK3l7rEh+Uvf XsMw== X-Gm-Message-State: AO0yUKV2614cpQNz5bbY/oJrKL8YgGT0RReBmzG+rHitHmw4in6UAOCm 1SuFn5XJnaK5GiBu2s0u8dQpbw1qvRr0gRd1 X-Google-Smtp-Source: AK7set8JKjpff+nhkhLG7DQf+wzOqUGOV53Y1+Q3iTsSaCMlB/3gn/55CNomXaI0Hi6AMXw7M3yzBw== X-Received: by 2002:a17:906:6951:b0:8a6:1020:8799 with SMTP id c17-20020a170906695100b008a610208799mr9075636ejs.56.1675884098508; Wed, 08 Feb 2023 11:21:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e15-20020a1709062c0f00b008964fdd5bbfsm6244227ejh.155.2023.02.08.11.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 11:21:38 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Emily Shaffer , Junio C Hamano , Eric Sunshine , Felipe Contreras , Taylor Blau , Michael Strawbridge , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 5/5] hook: support a --to-stdin= option Date: Wed, 8 Feb 2023 20:21:15 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Expose the "path_to_stdin" API added in the preceding commit in the "git hook run" command. For now we won't be using this command interface outside of the tests, but exposing this functionality makes it easier to test the hook API. The plan is to use this to extend the "sendemail-validate" hook[1][2]. 1. https://lore.kernel.org/git/ad152e25-4061-9955-d3e6-a2c8b1bd24e7@amd.com 2. https://lore.kernel.org/git/20230120012459.920932-1-michael.strawbridge@amd.com Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-hook.txt | 7 ++++++- builtin/hook.c | 4 +++- t/t1800-hook.sh | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt index 77c3a8ad909..3407f3c2c07 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 [--ignore-missing] [--to-stdin=] [-- ] DESCRIPTION ----------- @@ -31,6 +31,11 @@ linkgit:githooks[5] for arguments hooks might expect (if any). 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 b6530d189ad..f95b7965c58 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, @@ -28,6 +28,8 @@ static int run(int argc, const char **argv, const char *prefix) struct option run_options[] = { OPT_BOOL(0, "ignore-missing", &ignore_missing, N_("silently ignore missing requested ")), + 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/t/t1800-hook.sh b/t/t1800-hook.sh index 2ef3579fa7c..3506f627b6c 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -177,4 +177,22 @@ test_expect_success 'git hook run a hook with a bad shebang' ' 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