From patchwork Thu Feb 10 09:28:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12741600 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 AAC75C433F5 for ; Thu, 10 Feb 2022 09:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238516AbiBJJ25 (ORCPT ); Thu, 10 Feb 2022 04:28:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238531AbiBJJ2z (ORCPT ); Thu, 10 Feb 2022 04:28:55 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1801F10B2 for ; Thu, 10 Feb 2022 01:28:57 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id z144-20020a627e96000000b004e057a71cf5so2971088pfc.21 for ; Thu, 10 Feb 2022 01:28:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=1q5oLNtDReJ7p0+YX28Bu8psSH2hz+Z8tqtHbnD/3Rs=; b=i7X3v+eWhFCq70yj5diBqXk8uluc04X8836ruTfmGQL1ME8caGV3xsEKx5vyznEQG5 P3RQttYun4soRMYCeSDLWeWcdXUedQRnNK0Yla3g77rtikbfeSVdWL45a/Kus69ETOJ6 dOt7UunOQLFDgKvkxF+4Fl175usplW/hDpZFa7iByojY0bPoD+RbcukGCqOKXH3FsXE/ M6vU098j9UVSqoXlYHvpOV2A2qfOAuFAxntvKidXalse6GRcZ2q0sUHftPaxZk4dsZje U1AK9xm+L8GgkdsETct7c+sjtKU0dQ62dz/PftGaOiTiScyysDoMIeNkT9NaOu1E082n A10w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=1q5oLNtDReJ7p0+YX28Bu8psSH2hz+Z8tqtHbnD/3Rs=; b=4FBLAGl682jAoZvKqV3mIisJJdXnGIjDeLCv0PYRkHkGlY0mgC4hnkaQsq0cVkZhT6 6jsomu5r7Y2mGirLhE0IAzgo3kOKsiXKNOzH+1nvNOdymxBv0JHmb6x9cPaCCjofAJMn O7iIrjZmJI1Mn2uj7skiT/flV9YebXZd2JyxIGRxCzTrzyLf8HtDWJWRugMP4hw6H9Xg Uagl85Dd8I46zy5x+/F+4ikG2qvEib0YoAmp9CT+lgYyIL+pP/5VOb7qUk6KCuKxuoyw Sk+74QkYlL+y7T6ecMiV7NuvcX4MoHI924r0qnWnoB4R6NsUPQ5IdtOOyn0cPJcuW97R SRDA== X-Gm-Message-State: AOAM533sMm5XxUsWuYKvSyYSu/MdvWijZDXIeV9q1hhRa60h2BhNJyhB kgazskgPNgvtzOA7Fhgp/U8GfIfir1hdMYxJ1r9IuurCAyvsz7SRpOz7+zIL42lD8WwO1R68iUN t1goq4ugzTCciHiXaxwXLd5IkXlXhBEYG8fXtG8lPuhNCiq046NUUbU51bBA2HOA= X-Google-Smtp-Source: ABdhPJyvkqC3jLzTu6e5T6xTqEIIxE4urWr6yq3ydJi8f3aJJ3hRBECYv6O0orbxQw2G4HE2VeDf2aZaQ0E/SA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:e885:: with SMTP id w5mr6502827plg.147.1644485336379; Thu, 10 Feb 2022 01:28:56 -0800 (PST) Date: Thu, 10 Feb 2022 17:28:17 +0800 In-Reply-To: <20220210092833.55360-1-chooglen@google.com> Message-Id: <20220210092833.55360-5-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> <20220210092833.55360-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v7 04/20] submodule--helper: run update using child process struct From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar We switch to using the run-command API function that takes a 'struct child process', since we are using a lot of the options. This will also make it simple to switch over to using 'capture_command()' when we start handling the output of the command completely in C. Mentored-by: Christian Couder Mentored-by: Shourya Shukla Signed-off-by: Atharva Raykar Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 09cda67c1e..db71e6f4ec 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2344,47 +2344,45 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str static int run_update_command(struct update_data *ud, int subforce) { - struct strvec args = STRVEC_INIT; - struct strvec child_env = STRVEC_INIT; + struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); int must_die_on_failure = 0; - int git_cmd; switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: - git_cmd = 1; - strvec_pushl(&args, "checkout", "-q", NULL); + cp.git_cmd = 1; + strvec_pushl(&cp.args, "checkout", "-q", NULL); if (subforce) - strvec_push(&args, "-f"); + strvec_push(&cp.args, "-f"); break; case SM_UPDATE_REBASE: - git_cmd = 1; - strvec_push(&args, "rebase"); + cp.git_cmd = 1; + strvec_push(&cp.args, "rebase"); if (ud->quiet) - strvec_push(&args, "--quiet"); + strvec_push(&cp.args, "--quiet"); must_die_on_failure = 1; break; case SM_UPDATE_MERGE: - git_cmd = 1; - strvec_push(&args, "merge"); + cp.git_cmd = 1; + strvec_push(&cp.args, "merge"); if (ud->quiet) - strvec_push(&args, "--quiet"); + strvec_push(&cp.args, "--quiet"); must_die_on_failure = 1; break; case SM_UPDATE_COMMAND: - git_cmd = 0; - strvec_push(&args, ud->update_strategy.command); + cp.use_shell = 1; + strvec_push(&cp.args, ud->update_strategy.command); must_die_on_failure = 1; break; default: BUG("unexpected update strategy type: %s", submodule_strategy_to_string(&ud->update_strategy)); } - strvec_push(&args, oid); + strvec_push(&cp.args, oid); - prepare_submodule_repo_env(&child_env); - if (run_command_v_opt_cd_env(args.v, git_cmd ? RUN_GIT_CMD : RUN_USING_SHELL, - ud->sm_path, child_env.v)) { + cp.dir = xstrdup(ud->sm_path); + prepare_submodule_repo_env(&cp.env_array); + if (run_command(&cp)) { switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: printf(_("Unable to checkout '%s' in submodule path '%s'"),