From patchwork Mon Jan 23 17:15:05 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: 13112592 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 EA75CC54EAA for ; Mon, 23 Jan 2023 17:15:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233409AbjAWRPY (ORCPT ); Mon, 23 Jan 2023 12:15:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233102AbjAWRPW (ORCPT ); Mon, 23 Jan 2023 12:15:22 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F36A2CC5C for ; Mon, 23 Jan 2023 09:15:15 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id mp20so32312396ejc.7 for ; Mon, 23 Jan 2023 09:15:15 -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=Vxyi4RjxwTHoDnmCH1hoIfI/9xsPSTQv9k1R0cXtVKg=; b=ZrKfXd6QazJ46K4MXvJ9TC9cCYv+JWOuwW0cN6+UHrMv00g3R5dCvLwpicdcoYe2A1 pNmaxSw84k9BJnIuGSgVCkXYpOmWFLGQ4oSo4r8xrm5SHrEdtqpnBsTBUlibALlDdh7C 84R9AKb/wm5mwGP+TMBoKI2Yu3/pevGszRiHRTuJkiyGV8m6TFTknah+EVVRmKgX009I eggA1S9nMDJmV064CA1B/9JRa52MQiEB9n5bs/l1Z9rs+vq22vIqQNmd3KHF2hU6E9+9 JsOfTZqp3LoQUJcY61kk/HwBsLCC2KG+FxVDjzTi4lWxLi+z0ZfPLpCzwa5WLcOVRia+ HrmA== 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=Vxyi4RjxwTHoDnmCH1hoIfI/9xsPSTQv9k1R0cXtVKg=; b=bpyO5wWx6WRvslM2IlBIr5xWH8zFgk79Zf8in72TRm/321mg6xCBEQJgzESoXT1FBm 0YKh3yH2svxYIMCFrUO8Vv1iGu+Kzu6peZyXv1p2jGNf5zdyWFmOHNEp51f4A0ys1r6h KONvQ5TPGhhS8CRsxJc0bkpln1J727cq/Mc10MvCjBIOKY4rH4dWoKXe/kyNTr6kp2Fv y+JjJ5QEgnW8UlkM1qlnhpQ7eggR7YlVleJYwkuLDlQt07qda5COqniOWbYHrMNHUzYk 36D9WNtZgBS1ZGj2hNAqO+qfKa0z3E/Cg0j0LVClS+PSPZ0pCBdUViPbUPjGT6gqNZF9 1+fA== X-Gm-Message-State: AFqh2kpVDfc2viV8k1dm1YS9AkIuTLIiOU717ub9H9SybdzRClakYDJ/ 5weP1o1NN/wN5azKStJ1PKhaTx81chaQAw== X-Google-Smtp-Source: AMrXdXuKsQaoL3nswcjA0QywoULGIeQiSWOGX/MN9NIgSarMX7oLI10lbjH92QpAupemIIAG+/sY2w== X-Received: by 2002:a17:906:848e:b0:818:3ef8:f2fc with SMTP id m14-20020a170906848e00b008183ef8f2fcmr25020456ejx.5.1674494113534; Mon, 23 Jan 2023 09:15:13 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n4-20020a170906164400b007c11e5ac250sm22771754ejd.91.2023.01.23.09.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 09:15:12 -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 , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/5] run-command.c: remove dead assignment in while-loop Date: Mon, 23 Jan 2023 18:15:05 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1301.gffb37c08dee 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), the next use of "i" in this function is: for (i = 0; ... So we'll always clobber the "i" that's set here. Presumably the "i" assignment is an artifact of WIP code that made it into our tree. A subsequent commit will need to adjust the type of the "i" variable in the otherwise unrelated for-loop, which is why this is being removed now. 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 Mon Jan 23 17:15:06 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: 13112593 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 6193AC38142 for ; Mon, 23 Jan 2023 17:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233476AbjAWRP0 (ORCPT ); Mon, 23 Jan 2023 12:15:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233296AbjAWRPX (ORCPT ); Mon, 23 Jan 2023 12:15:23 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01C8C2887F for ; Mon, 23 Jan 2023 09:15:16 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id kt14so32402080ejc.3 for ; Mon, 23 Jan 2023 09:15:16 -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=ju+V7h+2LsytSHAkzvcd1pMbTPZ3YBeKNDl1iHJ4lnM=; b=gfcHOQq0BokKxz3dgex+kO+vrN2aMEP+PhnATLp81dboaFZ+S5FCp/r8oVNJseh6Fr EjM1slgDBoDlt+jWjtHM0qFWHfLM+SALsqMMvLIUwrbHpTbxk9mNT65QrMEL6TPWKtV7 SF74tkQh+1I3pcyPmbYfcgizL4Kqx8YGeTw46wpeow1TT+O6ijp2g6G6KSMJB3amUduP X4xsAhR8fMILW+LdpYIZsiRSkDvTl6CCVwFhqdItxDcZmUUCfAT+1+OWJ8hGMXjfL0lb S0r1TXe54tWD5VeqyiZI2siqslKGbywzn0DBtqayYK25pw7U2OyDUBtrTvltPElhtRih tF6Q== 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=ju+V7h+2LsytSHAkzvcd1pMbTPZ3YBeKNDl1iHJ4lnM=; b=0pHTd+UgfReEX54e2sthh8o0dTjjiZpJt7U7snX3H4kLVtZnI8yUnog5jX2aURYcVo vMaBptkEQeze8JAZdFzC4nE5dIaeg+xu5WFt06zwO494oW7G8eka4yBtovn18FrQcb7w EV9/VbWY5SZcDnWuc5LHmIpEqYy9J/qJMZUDozvyCqMsfdFWOv1SgsJ+kaBqlfg3ZJAL Dq1FzI9ngyz4QxM5a2sKCgmduOntSGBirfpIb36MR9pZJTBqcJdUHnF3r49sHMSY9cNN tphV4UMRORQn9TAWpQLCA8zwt2+cPhpenUghV+Ijf4DmcJm1Lv1vzjlNBpxWJD197nKc IEgQ== X-Gm-Message-State: AFqh2kpiqclrSY/qm+CRHrlzsIHEL95G51zDSvxFQsjm/jsIO0x74WHm Gt9r8U/mmP7xc9n5Nlukqu4tgkucshwV+A== X-Google-Smtp-Source: AMrXdXs5VW6PJqjsPmbiAAXYmDiEPYvvZZe2v6X62GdS/YO2JTDtpEvdTAhKj2Be+I6Tp0Tr8rLQEQ== X-Received: by 2002:a17:907:a056:b0:84d:28d9:ce6 with SMTP id gz22-20020a170907a05600b0084d28d90ce6mr25347721ejc.35.1674494114479; Mon, 23 Jan 2023 09:15:14 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n4-20020a170906164400b007c11e5ac250sm22771754ejd.91.2023.01.23.09.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 09:15:13 -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 , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/5] run-command: allow stdin for run_processes_parallel Date: Mon, 23 Jan 2023 18:15:06 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1301.gffb37c08dee 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 Mon Jan 23 17:15:07 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: 13112596 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 F3AE1C38142 for ; Mon, 23 Jan 2023 17:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233521AbjAWRPu (ORCPT ); Mon, 23 Jan 2023 12:15:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233471AbjAWRP0 (ORCPT ); Mon, 23 Jan 2023 12:15:26 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBC902BF1F for ; Mon, 23 Jan 2023 09:15:17 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id kt14so32402207ejc.3 for ; Mon, 23 Jan 2023 09:15:17 -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=G0EAP/+ht+MCm0hS+nzUQZhtsmL3FyKKtMK1D6L7A8w=; b=nTtacCaabKPItmmgObPGGZZpYUvGXlPfINZEG0xWCScJWZx+mK8ozFo+zgY3nW1OkL 2yZjSy7a6YoXgkGBRbRIdFJQ2GeyOU6Aa7vNuGywu/4Lq8kjy8cCQovasug6A5RZEoWA ld3FMk0JfhR5RLuu1USZ4rbwk24OYGXcHAu1BmokQORg2U4k+ql1jNHAlYtYWtnF6PxD 6HyiE+8wDOI6VjWQBdMoaVnbmOyq7UcgwYL5NEUrHEKoK4AoplNRyOsB+IckXgXRYT6U tVqbQ8Hv1sgxhls4K3w7m3+9zLiE5i0LMLi4JHGoyHBIegKfTvB2aTf+A117YOKZU4JM 7OUQ== 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=G0EAP/+ht+MCm0hS+nzUQZhtsmL3FyKKtMK1D6L7A8w=; b=l87dxs+VjVnUaCUW9TelpBHhx356x0qN3jWLg44w23nmyts8MUIRMt5BCHSCDdwPRg Hsrj2OVrd1JHWW39vmmlgg5fmceU5sqcX1zWpOwdWe1rcmWbgqBQPADsUf5+5oRNaaor 0YJn59QFuk5Zwjf4ob4/iJtfF+2t3eockg3s/B9AEbgABY6sRkrqFyZJpE/J0JCbaACx BckNWcIQNDoNbmK1xz5Qy4OYWEC8qzlpyhVhCH50iOvdfctfQQSBSztJYLjxOcJ/ZgY1 hFQ9HokKbVKoWvZPgLKyBD5pvxBsJZabP4YQDhh5KwjB07EaBWPYCKsl1U28q73tfBos y0BQ== X-Gm-Message-State: AFqh2koxLNiShd/pATqGaq+QsfIIq5UTBHVfYbxxjh2vllC1BBg4QGn8 8si32/F9IiwjQ2Zmx7HKNPdBVO/qy6geBg== X-Google-Smtp-Source: AMrXdXsoMhWNN4hJ5w5WlC+Us6SoSC7MKI9DVWkoLMvUy4egjB9peKUabcLexnY0D1i1hVZHUjPYGw== X-Received: by 2002:a17:907:c609:b0:862:c1d5:ea1b with SMTP id ud9-20020a170907c60900b00862c1d5ea1bmr29038928ejc.8.1674494115263; Mon, 23 Jan 2023 09:15:15 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n4-20020a170906164400b007c11e5ac250sm22771754ejd.91.2023.01.23.09.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 09:15:14 -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 , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/5] hook API: support passing stdin to hooks, convert am's 'post-rewrite' Date: Mon, 23 Jan 2023 18:15:07 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1301.gffb37c08dee 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 | 8 +++++++- hook.h | 5 +++++ 3 files changed, 16 insertions(+), 17 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..86c6dc1fe70 100644 --- a/hook.c +++ b/hook.c @@ -53,8 +53,14 @@ static int pick_next_hook(struct child_process *cp, if (!hook_path) return 0; - 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); + } else { + cp->no_stdin = 1; + } 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 Mon Jan 23 17:15:08 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: 13112595 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 DF8E8C05027 for ; Mon, 23 Jan 2023 17:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233516AbjAWRPe (ORCPT ); Mon, 23 Jan 2023 12:15:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233438AbjAWRP0 (ORCPT ); Mon, 23 Jan 2023 12:15:26 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC9462B60A for ; Mon, 23 Jan 2023 09:15:17 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id x10so15397139edd.10 for ; Mon, 23 Jan 2023 09:15:17 -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=bJffQ+wSx+zWVtvsPERwZgxa/0xg5ebkNBKJ8Ka/154=; b=UMCZ6+muaXeG4XnfVSXb04YwIIHZuR0s2hGGxYniJaKZJuuNfn2yaEXnLeFkdrEnQ2 gNkmJcwr2XTIAuVT4PE8xSdLJOafDF+TkrPTnKlTAlZ5MiXW2a4iv8VLKcmf8ltYEiE2 AOEG6b/DqUqb+cC987VwVd+hOqnARqbtgv4N5dTNZwm/vGOFsGhr2Eg1IUIFT5AFN/KG 0WhoGRQRYjuJLjpOWOhApSplQ2NWs6bmfd1Sxle6t0BTYf7XKwmRThWHeYTAOOqDWdPG d0Wz4msIPHGLtc0+CpP51LuhMosK/EUGjqegGS7FcJ6mvi6z0E2cJtAMy7DLHdVehuEq 2vCQ== 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=bJffQ+wSx+zWVtvsPERwZgxa/0xg5ebkNBKJ8Ka/154=; b=cRm90K/YdtsGcrG965JllrpIpKWTPS+7T/Mvj1uoEB6ftWF7cgf5R7dRUqb+uYGNw2 G6dQQNx937Sr3LJQwvgMkGIBemiqh2O3tWh/jMM/XNBNx1QltY4x6XRbGNo7K+/HxYSY cUtQo5e+cWggWV0CT80aRjvvLoT++UBBVy/vkv/4Ia0LPWisJGk7+n0sa5eDptiLu3cX 40vz6kys2D+tTcHOvgHBB9i5V3f5IMLOfF2KpgYYF4Hq2AQEfsNoDbybJ24DwG7hoRh/ ev81CeVaGimHsrsH41EXIEutPkZmvGCP2+5qRDEoGIG1N1T4VlOqWS4GY8MHEMLfYlr+ dskA== X-Gm-Message-State: AFqh2kqAKnhvn7IMYzu2zvoaUJXXk3dXKoPJtifatsL0hAMkPUOi2mz5 BTdInO0RswxzhnOMmU4+qj3qYwvcnfzM5g== X-Google-Smtp-Source: AMrXdXvD9qtnEYnTRYWjsrFjaXUADFVF0x68WQ+0hpVyGk7yhaY5R35Ie0IKG707ahjZsaMlG5K+Tg== X-Received: by 2002:a50:cc4c:0:b0:49e:1c17:904 with SMTP id n12-20020a50cc4c000000b0049e1c170904mr23223877edi.15.1674494116133; Mon, 23 Jan 2023 09:15:16 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n4-20020a170906164400b007c11e5ac250sm22771754ejd.91.2023.01.23.09.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 09:15:15 -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 , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 4/5] sequencer: use the new hook API for the simpler "post-rewrite" call Date: Mon, 23 Jan 2023 18:15:08 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1301.gffb37c08dee 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. That'll be done in a subsequent commit. 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 Mon Jan 23 17:15:09 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: 13112597 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 27CAAC38142 for ; Mon, 23 Jan 2023 17:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233537AbjAWRQF (ORCPT ); Mon, 23 Jan 2023 12:16:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233513AbjAWRPc (ORCPT ); Mon, 23 Jan 2023 12:15:32 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D01B830E5 for ; Mon, 23 Jan 2023 09:15:18 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id ss4so32273225ejb.11 for ; Mon, 23 Jan 2023 09:15:18 -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=CObrc47jsH1/VTaTtfLUTAmc+L7k4mYNPcUFl+dpBQ4=; b=h0v7vfG7IePzIHc/yyfenbI+3xEXLPMpRFaGtbbeacMuJMj8IOnax2cd5NF0t/w9px GMC8eBZq5xh+vUC3EEieON7eVjihQOW/wER24SEYbBbBaLaPrM6Lp1NEnvV+Y/lKOOlS c0E6KPEftN4Gu8Vtd5utpJ60OXPxrbUxVkGVGUlX021Ff4B3TBrBL3iNV4u8KDJDgV51 WIWNMw7/+mq9UEKSNKMaapR6CfByLEBrc++SIBadfaiuqquwNGow0IBR5RA1q4z/1Zvo 9zquLSPUHyGrUq9RZSrcDJDcGeZhJ6biVDr/ugBEwVppvA8/inYb48LtoVHL9Oyrrrf6 czKQ== 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=CObrc47jsH1/VTaTtfLUTAmc+L7k4mYNPcUFl+dpBQ4=; b=AfphbGNef1BuzcoEt3R9yYyOtaHVO7W2SrT/s+OPpXEJqC8yO0ZzvGISflPfUTMzXn Xyhm+VnrBl0gPsoipzw5lUYMjRZlFuYbSCs5hqRyOJGQskVTXX7ukSLN9ABo2PrOEiRJ K05tqUwj8ds8RtzKQI9AjKiTEvX6Vmgen674bDf78fFfnZ0C3EomCTqJspBePtSnSi2O HXWS65g0tLHC2X19sdN3dJj/8HAAChK3MiEX+z+2+g47Vr07T82c8AaZRpIgu3Vwqa3X I1yv33pRXmfxO3M4BvvLOc/DY6o6HWi5exymqQ3vaIr9TM8uMXKXucgR2PmyVkEV8OE8 e+Xw== X-Gm-Message-State: AFqh2kpIJavWCSff3D7TTWnG5WSKtGYCCdTlX1/LD9FrJ9qFEwfgJLi/ SQwoK+HQ5tobBABYO5U1z1w6WLcg75PFaQ== X-Google-Smtp-Source: AMrXdXsTBUrugCWN3TPbYS2PiVafqZ8wAGvg3RxY9xIS6Z/VjPaXFltimPoUJv6MiWzjfyKrwLZmqQ== X-Received: by 2002:a17:906:5283:b0:84d:4be4:aa2b with SMTP id c3-20020a170906528300b0084d4be4aa2bmr39037865ejm.68.1674494117084; Mon, 23 Jan 2023 09:15:17 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n4-20020a170906164400b007c11e5ac250sm22771754ejd.91.2023.01.23.09.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 09:15:16 -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 , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 5/5] hook: support a --to-stdin= option for testing Date: Mon, 23 Jan 2023 18:15:09 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1301.gffb37c08dee 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. 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