From patchwork Fri Feb 3 12:15:31 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: 13127414 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 2D4FAC61DA4 for ; Fri, 3 Feb 2023 12:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232799AbjBCMQg (ORCPT ); Fri, 3 Feb 2023 07:16:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbjBCMQZ (ORCPT ); Fri, 3 Feb 2023 07:16:25 -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 19E1F9DCB6 for ; Fri, 3 Feb 2023 04:16:22 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id mf7so14802819ejc.6 for ; Fri, 03 Feb 2023 04:16:22 -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=Hu3vo5KFEPY8C96Ix8vUUWNfKabwfcfA4rWSBTVVUFI=; b=CxmZRR+saBvy83yUOcDGABZkzR2k5OOmOjnFn9GuQVtO5YSK61vK5ArDXdzdjZ9pEc bmacR5mWjZPuxMTBmKRyPtzPitji3LBi/m+/Yxt6MyzJwrLo0o/xqnw4QMCeyDutTZTm ZAMyjDdq//7pcheig1zDPLl5pxMfbe+eA32h05/8tmuNZU4xtefolGwnxUAx3iL1fcDL sfO6AxcAAS+LaAJzZsX5TvRxbJFwa3Lo+9HusXAYniWqdpwDb180+z5D75lFlJcMplu8 lG8ZU6PpU6ppnwn0jv+a7DMLjDhpo6pJ4dY8YowBlq1l6AT+zj6k91f//+7bsKruYg8C QOFw== 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=Hu3vo5KFEPY8C96Ix8vUUWNfKabwfcfA4rWSBTVVUFI=; b=hJNtoE1pA6eDVVbds+cZbyRJTMUYCUZwh9L3uJkONS52ulKrfw2mCADP7mh4tIlGGR PZg8K8uKvrB6kX5bjIehTUz6mUcmnM885kjEJRNHye+Bt1KS7U0GEzSjSotxdLhlwog4 YyYzPLY6Sb2MbkQbJvt9/3NJIOi0Ibl7VU3ncZZO7ICPgDJI2tpJkmwXcpsNMg26ovXV iH2z4JhyDb210XZA2vVPuzSytQJTiBC0eaJotTSGrq92Q+MmviVsvJ12sRfauO5/5m+/ VvIef4zjFYAlGZoSZvwfMSsArlVEPy73PCGj7FU1yZbIK3RWM8IpSjqiA3GbAyo7NN+g azsA== X-Gm-Message-State: AO0yUKWJ9aCmAlhDmU82F/xbnhBZvv0k84ySWQfJ7dWhGbhgaZUbqRLx 5j23qynhe1gaEnWh7P5+1zBTDu/iX4f2UDNF X-Google-Smtp-Source: AK7set/pG3DeDCcRCvKZ6YXXkGfHpZEtGM4n/qsCt7emEahUjvImYR9w+xfSusRWnZ8UCYOiGBqTJA== X-Received: by 2002:a17:906:948c:b0:84d:4325:7f7a with SMTP id t12-20020a170906948c00b0084d43257f7amr8843045ejx.65.1675426580172; Fri, 03 Feb 2023 04:16:20 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m24-20020a170906849800b0088b24b3aff8sm1286313ejx.183.2023.02.03.04.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 04:16:19 -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: Fri, 3 Feb 2023 13:15:31 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1397.gbe42486b8a4 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 Fri Feb 3 12:15:32 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: 13127415 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 10F33C05027 for ; Fri, 3 Feb 2023 12:16:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232776AbjBCMQi (ORCPT ); Fri, 3 Feb 2023 07:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbjBCMQ0 (ORCPT ); Fri, 3 Feb 2023 07:16:26 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F3265F1C for ; Fri, 3 Feb 2023 04:16:23 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id m2so14778215ejb.8 for ; Fri, 03 Feb 2023 04:16:23 -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=om9xyFyMT6HrZ68IqVJAxK9ea/CxcSJCskNYUIGrZYo=; b=VuMGhjm0UozK8t/H5TNWBBYq50L+qw93Obr8kMOyW2VsLQHK03d/2br6VTyz7kapRH 7kqa24oNBZ4izfFxcyeXGWYeRkmDPRJTGbOvcDb/5pMJR6F0qsGBajMIveo0LKHfKe9b NYgYEFiJAc9j6pcHOFcUtEocEIeNcPLTgSjeeAR4igJ1L2UMk90LNwEIuCaNf8Tyb7T7 xbHH3w8/fj56U+eQYpj9PSLONbcmZlXxx4w90ti98w4f51njGhz28sifIN9teRwOLV4z wl/YnEdOubSHG23raRrktfyP/IKuTVqcZj6ixBmhM2hBaSl3ZwG07MgvhVkVjRcHj79S uHng== 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=om9xyFyMT6HrZ68IqVJAxK9ea/CxcSJCskNYUIGrZYo=; b=hz5+sEUi1nBo/iRDCXQTH2lyK3/dp89VOeQqFLTcU6q0W6zlxkk6y3IFF3HMfzE2Ds wuCR5hYjoI82ePa1+KkOw+L9CLG79TmTVAX8Yu6IrGvbp2dBaqemLJrYBuXjjQ+bGw8a HcsCJc577WVgB8LXFvF+2FHOUPkW4oYyoP/SVtnqc9bGb9fdizuVKumnGI9VaFcjw6Tl hjmYuu5uMk5oIgoPgdguWMYvPAKf+sNINXqdkNBCMSiZH9KMinScEB+dVPWnwEOjGJy4 XG8x1xCndQG0yeB4xURhTetrJ0FLBau3zbFUwxIVEhdOX2Y+E6Fzx5bPED2NEJpnoN9r qvDw== X-Gm-Message-State: AO0yUKV5ZxK0ttuHAKpwMk8bdyGlEAquG+vH7tOkjw9QybLJOIQN4OxJ oPN0yaJ+yi/mf7kXhrhZ9yk0qF/8Q8hg+92B X-Google-Smtp-Source: AK7set92clsuGwGjQatVOfuek6mlYRYvzbizo9k7N6dwtWVg2XHZtfzuFjJq+dwOSSZKSsZP+ETUSA== X-Received: by 2002:a17:907:7293:b0:886:ccbb:a610 with SMTP id dt19-20020a170907729300b00886ccbba610mr2052244ejc.12.1675426581267; Fri, 03 Feb 2023 04:16:21 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m24-20020a170906849800b0088b24b3aff8sm1286313ejx.183.2023.02.03.04.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 04:16:20 -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: Fri, 3 Feb 2023 13:15:32 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1397.gbe42486b8a4 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 Fri Feb 3 12:15:33 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: 13127417 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 51568C61DA4 for ; Fri, 3 Feb 2023 12:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232805AbjBCMQm (ORCPT ); Fri, 3 Feb 2023 07:16:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232775AbjBCMQe (ORCPT ); Fri, 3 Feb 2023 07:16:34 -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 20CB36D06C for ; Fri, 3 Feb 2023 04:16:24 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id p26so14701599ejx.13 for ; Fri, 03 Feb 2023 04:16:24 -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=ukuROd+WVlg4bjI0njxyh1k/SrOshfl6sA9dO8JzAzk=; b=iwn5xy+QPlPP4Rqx7Qz5deUpPu9Qud5ESMn2vdQ/oBGfrHZNWCRsFc9XrKQtmj5BKP IoW3sKbw48QR191UxFZeQukMi3f5iZDUl/Flr4RYijQKZsWQMqmLeLEbW71MgjqvEMv1 CpaWFIKEqH0Li/2Z97GvJ28s+7S5BTYDhhTokpqwybTHBpyFV5OePJTl3DlL9GuIt0fX RjMKD2050HiuYW8gMNo/1MqTZKp+EI2CYzjsdxAjgubGlUGoSiKIlLOKtnCw7kYwCgKQ j0vsCtW4dpiLvyzSuvBBAUNxkKkygownn/49HgPP2b+uDQUfW20wfxb0+hb3UPGo/lro 9O8w== 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=ukuROd+WVlg4bjI0njxyh1k/SrOshfl6sA9dO8JzAzk=; b=LMCKKKwWs2syH5EO2m587i03JYLPQfAVy+EiajypT9joowUqY2anmM3f/q6OtdnJ7a wmOSIfNwlqUUwVxtUgIM089XWPtexAb1wulhq1MH14VD+HDrx7gqn7QANvinEd0/c5fj zNcOtTOhgNJRX2TAM1KKLQtOBdLMSUg6qEly0Y4o8TxPI4VueYCGj7G7Q6dUGY74dYod geTgXM2/fv/h/8Gg+jgIew03dRKCH7JBGeDjRUzPoGMdWTZiQyxrgiVthQM7TjR90Ffj lesbfNDap64rAe1TZXWOq7Twar0a6/mmHwwOvECHn8dR3EEQpiI55QLsk7KjqHr6Rnpy coRw== X-Gm-Message-State: AO0yUKUY6Zz2nFYByAcB2ojjWTVodx/cg11CDqsAVHVIxLILyRTB5gc4 CAKk+76cBzkvvunUbCwBhB5Y/imr9vEvB0Kq X-Google-Smtp-Source: AK7set8KRNj24M4B00K03fKTpx2eeG5WzhoJwddyHJi4yuHxKa8V58Fxrj4Kwkt8RNEHqITHZBjocg== X-Received: by 2002:a17:907:a07c:b0:884:d15e:10f8 with SMTP id ia28-20020a170907a07c00b00884d15e10f8mr10869610ejc.51.1675426582308; Fri, 03 Feb 2023 04:16:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m24-20020a170906849800b0088b24b3aff8sm1286313ejx.183.2023.02.03.04.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 04:16:21 -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: Fri, 3 Feb 2023 13:15:33 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1397.gbe42486b8a4 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 Fri Feb 3 12:15:34 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: 13127416 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 B3AB7C61DA4 for ; Fri, 3 Feb 2023 12:16:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232784AbjBCMQj (ORCPT ); Fri, 3 Feb 2023 07:16:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232774AbjBCMQd (ORCPT ); Fri, 3 Feb 2023 07:16:33 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A99099DCAF for ; Fri, 3 Feb 2023 04:16:25 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id k4so14858559eje.1 for ; Fri, 03 Feb 2023 04:16:25 -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=LOxed2EOTlliBjFIR9X/w2ZZBkPbquWBQ1Fm3+vKPLk=; b=fbRpbGd8/7JXbZhUi3ya2hLW/wruuxZ12oVcNzoY+hYX0eOekuLRO51Af0XnZjdINB EX6SH7pQWAK3UvhGO0iRy7ZYrBsGy+nwCJxksxX5zgiTeV30vDAr8qV6UrYvhIxxvF4M 8OeRndgvdOcx4X6t3MdcWTUJ4v1ABhjJ+58nLcBpVCyiiw3vkiU3xvQfTriHQx+7u6MD IaeaGIFHXvPf722RX4vmSIFS+kNuZ7LpKgURzxKl++u3RjUkoA++oqUqXQYz2DgBmFWL 7BmHJvCv5E8BjmSprPPqAwO+6BqGv9D5SoFiQSA6y6XewTJMaNuMJxt9j5xID1AXzmJe C1UQ== 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=LOxed2EOTlliBjFIR9X/w2ZZBkPbquWBQ1Fm3+vKPLk=; b=6igFIAUZI80Pt5fmN3++ha0J/2NFNqj4bZ0+FQJXC9E/eQXBiOj4U5ZFNEmbUrOa/2 wt01+jQIbZJb2bDvUkLySMcUYx73ZdETXmdmtkTHSJEp4ZykNzuujAdkUS+OKIV40RHc pUonPCHmK8jm9q6QvTpNYQDOYCYD82fY6xdvs4tYk6s4a26oZNXfX+CqzJ/2xYevhiKI rTluzy7GVcAVzO6GD1hUHbiza7ezsPyZaOSRS2TC+eTOPcDYkTNrFgs6IrxcJcWk3W6k Md3OKSsPGJdIP1NmrpBB6unJclO2usTMA3IolJH+DsrpShOLQDBdMLMdIFlO7tE9bymS 2zaQ== X-Gm-Message-State: AO0yUKW2dsxysVMq+cgo3DchqdGANszZII38NUn6NYGsP+UwKo8Ieq0u 3Ld583vpeVxdwN8yZqYVWtWN5lrebqfUuUwK X-Google-Smtp-Source: AK7set+OKIkgTDpJJKrqZCFYEZqFRow4T6HIvaigOenVlrTh6qZ9Hkf0BK1UyVSQLN+VwGG9oHAXkw== X-Received: by 2002:a17:907:9916:b0:887:915d:7502 with SMTP id ka22-20020a170907991600b00887915d7502mr11159995ejc.31.1675426583448; Fri, 03 Feb 2023 04:16:23 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m24-20020a170906849800b0088b24b3aff8sm1286313ejx.183.2023.02.03.04.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 04:16:22 -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: Fri, 3 Feb 2023 13:15:34 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1397.gbe42486b8a4 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 Fri Feb 3 12:15:35 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: 13127418 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 7D4E3C05027 for ; Fri, 3 Feb 2023 12:16:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232815AbjBCMQo (ORCPT ); Fri, 3 Feb 2023 07:16:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232777AbjBCMQe (ORCPT ); Fri, 3 Feb 2023 07:16:34 -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 C712095D1D for ; Fri, 3 Feb 2023 04:16:26 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id gr7so14809159ejb.5 for ; Fri, 03 Feb 2023 04:16:26 -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=tQ3OfThxAa3aEdV1n9p+/L7BjJm1v1y5Uq3UaqGckfM=; b=O8P1oguLbcur4uLYZ4Mxlz7TgBmvdzPtcbnJ4KAZ89YaRY9SmDLUFLKvIFy2dwnm3V kvsEMfj8nKNyHtYStFLh+ObHgD0PIkqp3CRfb6anQMEJ5oUT71rMz0zFjgkptCKlI+Sw Hzv8RRfacpIljQpcMHNrxwdLy+e9R5MKwIR7c+1Yqg5vfsLKii9ujruagraP4TaOP2JA 4wGtVbOv/y0x8ov8PqAH2Qw7UVPPrGZ6nCbIWZhIXsTK/aBPQ48GDW8+K+vtkEeetwGT AqYj1IsonbcJy3oyT9QkUh7B/SSGI+DrBuRsFdpV/XS1ngn7vyEr7ufaRV8yqlB8Woe8 X/Tw== 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=tQ3OfThxAa3aEdV1n9p+/L7BjJm1v1y5Uq3UaqGckfM=; b=aeKUVrxvN4FY76On65kNGICdBH5CUgA/NJp5W2Q9mF05I8IuTrFQ07IF1fPWE2rhfL iEH10DJAvn/rTr+fne98PXQlX+q7YB0TMGnesrOYcl2kLdBuJj04OUePftTF+/vNROaj GKyW2lptcF8DsuKFDMrV/HNigSRsdcEEobpnBB6bC9UTCGy86Ta25c/OVioVTaGfujL2 tDdwouIt9frg5iW03/BET0/x4AGFLCRkj1Wl+koRrIs6ObbVgXPTyj0Pk+dpbrqKTlya tbnI2ET6byfmJgUw2srpQcOMcCXKI7qseqfvgLPI9400oqbaEUEkse5TO+eB9j5iI2kN Va1Q== X-Gm-Message-State: AO0yUKVKC5gkWSrwiE6zUqAalmD89TljDU91Q0FBjicy6o7KMMfPyoLP E31Y5O8qfC/3XTXRXtBcuh1MgsfnWurQrYe4 X-Google-Smtp-Source: AK7set+eeUsE+8rJESqxjr0lOTutEnro3VjgbVoRvfwBHehNrDGV8wLqBOoDWceQXZCgiGKdF4NsoA== X-Received: by 2002:a17:906:4713:b0:87b:d597:1fd5 with SMTP id y19-20020a170906471300b0087bd5971fd5mr10830021ejq.75.1675426584967; Fri, 03 Feb 2023 04:16:24 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m24-20020a170906849800b0088b24b3aff8sm1286313ejx.183.2023.02.03.04.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 04:16:24 -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: Fri, 3 Feb 2023 13:15:35 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1397.gbe42486b8a4 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