From patchwork Sun Oct 30 11:42:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025071 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 89211C38A02 for ; Sun, 30 Oct 2022 11:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbiJ3LnK (ORCPT ); Sun, 30 Oct 2022 07:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3LnJ (ORCPT ); Sun, 30 Oct 2022 07:43:09 -0400 Received: from mout.web.de (mout.web.de [212.227.15.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9185CB841 for ; Sun, 30 Oct 2022 04:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130180; bh=hUPIERufh2YPKYUYEFtjKEriqayeFlciFf3o4OX2rFY=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=DTUoBa8VGTqcdy0pknLcNcVY4lzElaNoIluMf3ARctN6od3YozP8PEc/e0JiUvz9b kW7XebAcFZ9cLVwoCAny9JrGraM1gOv2SpRatn958n57+HV3qs6p804Y+NT/oNUOxP mUH/G3QqSYI3PoEIWXRljLa8LAuMu75hbHI3gEowm5YnCmiUd19fuBRzej8OZX3W0D Kurq+RO0hUkZR5Q2xcEePGKFQXVvfnAkfFuJW0k94TZSGU4KPBV1dM0AACKyKW6Tbv L0XQi4o/Tc5VmWcXKTwAoTs9GWpcKpmYRzs5JrdtURmjRL/dtVGqJupjqfpmBwCq3i oIHEagQLNcY3A== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MXXRL-1oYG0B0tyR-00Yx7b; Sun, 30 Oct 2022 12:43:00 +0100 Message-ID: <1281ea52-cb10-638b-7612-8fa9dbecc31e@web.de> Date: Sun, 30 Oct 2022 12:42:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 01/12] merge: remove always-the-same "verbose" arguments Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:+Q4TZ8Gm4EnoECWdHuOiEDylQp3kBMmQZ2g+EL8ufoirGSY3aMC f8Hkfw0z9jPpQB2i7LktSY1O1b5QyTlAg/Be0MpXNFPZGmURJK4IGcHOpgsE7SvTedcIqeY IiXbSKF/vVSFrhk7o7OtLZxn+x6J463/36CqYTNKoVY9hJUAcvdUmGM5ci3WB/8SiUGogNL pYZFH1KFeYnjIOH2oPjRQ== UI-OutboundReport: notjunk:1;M01:P0:KJr2DI4Qqhg=;RqCuGGS0wtNREzE/ZdAIz3sXEhz bLqgKu4Nv3ZDOoY2gFFklNODbhvvFUHEhM6TtoEf61uewTP5mL448ujx1902BzUIfoukxOJt+ sAKiB6ssC5jjm/KEBdOJReRUCC3D/rBcZ9E4G1Kagna5y2700mh/h5PmIG2dl4fzA2TaYtTKd FBOjKFNXyDmnzWK0fYMW/NigN6Hyz3Or9H7OpG5JXbF+ZpnFgUnXQjLCMuEM+pt2LNJQo6W0z 5xnyFQFT70q70vga0bH5urj/layEDRTTyeY7t/CDXjjrQuQeKXWiR2Pq1oJeCuLukl84G5wKt DIFlZ8k74WZEWnKzCBTVsgC88aAp0GEAdJlyhqOCkcduHu2CB4ICiw2EJHUpIyPmg3q5k33XY +J+6SiyDQ0BAVaKb7Um0DWcaTjT8e5bZmew+jB/MIicuRm7L6s/bBpAJc3QevlD9XFEJpa+yM 00Vtx9Y4xBq8ORD21NHmdLmVi4M+THfNcEcRnQUkH8kpjBGvll3WjaG9wKwnCdVx9xjyqXy/Q hDl+81N9znTMQTrrSgVe3goJxbpBfNIRwMWuusd1t+n1LVGboiBqjNqEBXyr03ZnuMXKLW5W+ wtHeamAyf0opYE3kb9BoxCgiuZ2mtqzIYRUEMEyyFjYL9v/igBXRqHPaWVkc3lh7HpzKg4uZe o3ujOP8DGuD+7QmmoWPZ6Elii7WHuiLGB5ITrPNCR6NPb4TXF0V9SPxFW3ULvWwQPHFZdbfI5 5fkzYluvpMdS/PJQee60b0IAyc+aqhQb87tHN/beZICf0QZpNSjSptnKZRSVuDFXMgHRZdpHC TunEZS6tYnb+HP+OhmL66pESJGF7USqgfKSu7XqVzt8Ms5lwcepT64uDU6+Xcs60qtIHKZcOI y6YFJ7TOM/G05Pg9hGBpV+hr8GrKarEVM27QSGq6vYpVpJRhF30Avh1zWUN/088ADn7ydWD3T XL1vgulNVB+w83xgNhSr9Pb6tWA= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Simplify the code that builds the arguments for the "read-tree" invocation in reset_hard() and read_empty() to remove the "verbose" parameter. Before 172b6428d06 (do not overwrite untracked during merge from unborn branch, 2010-11-14) there was a "reset_hard()" function that would be called in two places, one of those passed a "verbose=1", the other a "verbose=0". After 172b6428d06 when read_empty() was split off from reset_hard() both of these functions only had one caller. The "verbose" in read_empty() would always be false, and the one in reset_hard() would always be true. There was never a good reason for the code to act this way, it happened because the read_empty() function was a copy/pasted and adjusted version of reset_hard(). Since we're no longer conditionally adding the "-v" parameter here (and we'd only add it for "reset_hard()" we'll be able to move to a simpler and safer run-command API in the subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: René Scharfe --- builtin/merge.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.38.1 diff --git a/builtin/merge.c b/builtin/merge.c index 5900b81729..3bb49d805b 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -345,14 +345,12 @@ static int save_state(struct object_id *stash) return rc; } -static void read_empty(const struct object_id *oid, int verbose) +static void read_empty(const struct object_id *oid) { int i = 0; const char *args[7]; args[i++] = "read-tree"; - if (verbose) - args[i++] = "-v"; args[i++] = "-m"; args[i++] = "-u"; args[i++] = empty_tree_oid_hex(); @@ -363,14 +361,13 @@ static void read_empty(const struct object_id *oid, int verbose) die(_("read-tree failed")); } -static void reset_hard(const struct object_id *oid, int verbose) +static void reset_hard(const struct object_id *oid) { int i = 0; const char *args[6]; args[i++] = "read-tree"; - if (verbose) - args[i++] = "-v"; + args[i++] = "-v"; args[i++] = "--reset"; args[i++] = "-u"; args[i++] = oid_to_hex(oid); @@ -385,7 +382,7 @@ static void restore_state(const struct object_id *head, { struct strvec args = STRVEC_INIT; - reset_hard(head, 1); + reset_hard(head); if (is_null_oid(stash)) goto refresh_cache; @@ -1470,7 +1467,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) check_trust_level); remote_head_oid = &remoteheads->item->object.oid; - read_empty(remote_head_oid, 0); + read_empty(remote_head_oid); update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR); goto done; From patchwork Sun Oct 30 11:45:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025072 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 73204FA373D for ; Sun, 30 Oct 2022 11:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbiJ3LpZ (ORCPT ); Sun, 30 Oct 2022 07:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3LpX (ORCPT ); Sun, 30 Oct 2022 07:45:23 -0400 Received: from mout.web.de (mout.web.de [212.227.15.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD62B247 for ; Sun, 30 Oct 2022 04:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130315; bh=Cfb8QYuM+IvFuTs6O759WFqIR9u3UgE/B8Eanz9QL2w=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=icJTYrYizpNa0Ra0TLb3pEHTL6V/Pa0iwEfc/6rfz6NiUFNIu4X5LfiAOzLY0Dqzl IahANsfIWzle2ur8XqB9VbB61L9r1whAG7z9fM8OPtZUFaaxX4S/j9sROftg+c7f7i 4YUQgDdNDJSburRIZS/Bjzych7Kg0v4P2Et9yE1oUZa9Y+JV195gQyYEHzZb4BEtcA nPYgJSXrW1yqsjk2cWXKCP9DVK64vtuHukyUT9lDiy+qzfvWLCDyC5eslo2sWIm+PJ pqcHDDzhDfllR5xtJHRrOdLVpFXDoYPQv/41NuTtNZ51Zng7IZn2/xOP84i1W8RxOb sf+AGPnTUS1Ng== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MRF3I-1oRxhW3lye-00NB32; Sun, 30 Oct 2022 12:45:14 +0100 Message-ID: Date: Sun, 30 Oct 2022 12:45:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 02/12] run-command: fix return value comment Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:GXdil/9ckvGQqECzEah0Ni6Bd85u4g1IwVzS3/gl9NPu22YUs9e rv9sOO6CykAutKWjyixRbrw8yX+ltMhG+ys10XoZCf+SvzyVJU4E0NvHwSecBkdcAMoHbol osAYG667SdOraRggE41usimvE8fG/ATaSXvuwWaeATq94VUh5FPhxVKui9AiGV0iG6aKOgs qNjfU/R2AklAYPn2oE6dA== UI-OutboundReport: notjunk:1;M01:P0:JIvtRHG7yjI=;2u3RMIm1MYCJ3BuS5knZZoDlqqw hc5WRcHlfXlMPkq8VAEon70d22dOPjuTzUxy6hT02G3IuUfhZcGhhWJfGTzlY63zTKUHtX5uQ /1yd+TbckG6Yj3ND0qPu3ddtrTK27RDlOgtI1EYuRcyZWJsKT7VY85au86oCj5aF9jBohIsO8 DQ2kvxbGWH+Sf0pdE913Iy4AiepStimLPhThHmFmOQ7hzfoHOZ1SrgwhBcMjCXpap1rL4GxpE PUVrKm6OakX4JGJHDUF+MwnFDECoxyUFNF235BRqFs470br1RHslrSthNIwgwcNlXme3pNIeb KhWZDNmcVm7uG6YSfwpSqF56IsQYJvD3NVnIvnVehUdP39nbP9TDHqBgonoJyPcwUcgMPoXh6 B+FrNsjegcz4EfLAUTBmINlJbxEeZgYkskwi+pFryPt5nK0Ts0qjDEivOWHQJuvlk1osRkE0x o8w7D99W6SivWLaaIsINNFCDay+yNw8L6YLWY0U2Q2cDkAqTe6E900l0etx/jLOFMDLbhTzEJ cWSAOBBl3plPFxpSCdMbYH1BioWiDnSRazTrx3pwfv9sTpV/cyn9s9lZotdBbrPF2TyOB1e+i pFoBAWSwTtEx/+fuvSxWpf1xtmo0wWBKqYIAGqhznjzM1RmN1EfhaO/oVGpeT+j2wm06N2Mtg VaabzHdbjTJFBA+5riU/WlJPshvo5n9FOd0vK61klSv9g+4++Sc2IXckb0lnVE/kTVBpQWmPk wzFh7YsYkVZqetR4COxLdLbyuPIv4QDOgSS5Lthm0tbHOF+i0cqOc59FmAgLlbDxzem5mkHtA CF+QeKY/vVyRGi//Pit1g6nlKg6kQji/zB7t8XOsE4bXBVgT1heTV6u2n8gjfRBlNs4us2F+C ELB0Mm2kbBJbGRSIn/m30mxHzPyYIEQm39xaNNpGsR1jivJhj2UelskKsXxCIgBo8B2TNBjSq eeOHNC7YRXIfICn35LOKNZaC8Mw= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 483bbd4e4c (run-command: introduce child_process_init(), 2014-08-19) and 2d71608ec0 (run-command: factor out child_process_clear(), 2015-10-24) added help texts about child_process_init() and child_process_clear() without updating the immediately following documentation of return codes that only applied to the preexisting functions. 4c4066d95d (run-command: move doc to run-command.h, 2019-11-17) started to list the functions explicitly that this paragraph applies to, but still wrongly included child_process_init() and child_process_clear(). Remove their names from that list. Suggested-by: Ævar Arnfjörð Bjarmason Signed-off-by: René Scharfe --- run-command.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.38.1 diff --git a/run-command.h b/run-command.h index e3e1ea01ad..820fc25b02 100644 --- a/run-command.h +++ b/run-command.h @@ -150,9 +150,8 @@ struct child_process { } /** - * The functions: child_process_init, start_command, finish_command, - * run_command, run_command_v_opt, run_command_v_opt_cd_env, child_process_clear - * do the following: + * The functions: start_command, finish_command, run_command, + * run_command_v_opt, run_command_v_opt_cd_env do the following: * * - If a system call failed, errno is set and -1 is returned. A diagnostic * is printed. From patchwork Sun Oct 30 11:46:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025073 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 359FEFA373D for ; Sun, 30 Oct 2022 11:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiJ3Lqa (ORCPT ); Sun, 30 Oct 2022 07:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3Lq2 (ORCPT ); Sun, 30 Oct 2022 07:46:28 -0400 Received: from mout.web.de (mout.web.de [212.227.15.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89F72247 for ; Sun, 30 Oct 2022 04:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130372; bh=OMFxcxxR/9U2amqabgibiRfaHL3ATz069Bsk5rxfbcU=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=I4oZbNUj/XyNX8dRXwOtkJDRVQddKtvFS3L734uK7TRXQwNjuzs5YPO6MoLF9NvKo x9H0dhr2HA6xFAyLRjEeN2EyLMWdQt/VTHkKaMLmqWdcq6IVMhnOaCs0lBrDlLQNb4 UA3g36iH1hyCx3cW9fh8/nI9iFvVR/Otj1LDk9J79+RO8u1U3zb5G615MZIbpBuuoQ H1c/iSTL51EuwXbNnJAgFY42ef9XNn9pJmYcv9Oxf+pMNGCQxGa2XSSJkEoMoFemIK cRQxPnkoZegGvDz7QEyXeVNrPe6xIzyj+ASB8IX0sSMCVhfjCidKZm7RsBEgVboOsE Zu9N8iqxjrm9Q== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MsaWF-1p4JVA3NhT-00u07i; Sun, 30 Oct 2022 12:46:11 +0100 Message-ID: Date: Sun, 30 Oct 2022 12:46:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 03/12] am: simplify building "show" argument list Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:9poGmCsvovbM6O3dTwk7oSRIbKB9T5d6mxC4bX9fQERe/kjeDjd KyYo+JwOTFr9he5rDacNK57SFiqnONQz1WDC5ub8vtcur05rFYVUw5Tf07+NSGVVFFPLt3I eE6oEm6FhS//h+DA0+/uZbuH66ETJpLE8vJjo31KLhgNaO/KZcFIbG0DylajYPaEI89n97c J4vUsJ+6Cq5h6kkteOIXg== UI-OutboundReport: notjunk:1;M01:P0:d0YNJt9E2KI=;IbfSpF35G67n8X4LuzxvyF1AI7w aPgT0xPGF2teww9FmNzbNZ6G2e4FyRJdkjTOHV2vKZXF30bfQdYDIRZjVfES4qfNqPO/3ey80 tt5bJnoixg2olFBOmMWtV8xElkDFjh+dbpI8PwGugJonjlSI5zdHDe0+9KcRAM0wjvNPPzwRu VAJxLaN5IE+m95byH3xEEKOmp2aq8Vz9enwUDB6i00SkqkH006XEOGbStN35Ec9jedNXjy688 cRQL0nxpp2JTgJRO4ADLwRelsFWFtxBYGHJkghm/H350hjvphkJ2lP92ByrDv1B01yMVP2wsx AggGSxS2FNn420ytScnd5/bu6Q0weLLeERyBBhPIUE16xwgp62lNkcnXlWUhSaVucEexzafrg GIezpojIMc1IhMWxgS2vVWpBA1dnhzRxpjK+5n81T/FpiOeljHs0CLJTdmyF/+DmFRZuBWNkd QahLOZoEWTykrpSjGzGI+eK3wFd+AqYhvE/5oHuGhufC/zBeDymCn+3cPE2cI+D2aUQeqnUFk VQRZiQE+tRICxBcTsjqsF17OUTC/zeFl5sKlkwWMXowPWhb7LYOybQ4KeqgNXQhu0hfLLXR2c FuapVvu/4I7WySASRdH0m/yDmqwU/B6UbjfJqHAzRRciFbX1adJhi+Nbq1wxsRkr2WfhBrVM+ Z44lk8xBsEJ1uajo/9Kcz8f+/W/BgqMRohoEafMW+/3bzOXysxuwIz/DBlpCWy+ewMkmsHtRU hLLh91Jxs9jGVbAGfQmA5uS0tpPIC/TnRe3GYG7E4ZEVzZUcCQoN63XtNH6XcaZy645vuBvgF TuLibmVAnVJof5zBe5IVFHlv1R6U9O6pMCStZORd+ROD3fL6bjsy1YrE7laF9FFJ3d5jl+xyB 9KcHpnP6m3oNOAKro/8uCPQHzIkBwAkQrzTBD+KEryPsqZaJ5vvEC4DZGuoocLcvW3uG/lSl/ OdV5ooSRCe7+O3plpd9+SoUFfQ4= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Build the string array av during initialization, without any magic numbers or heap allocations. Not duplicating the result of oid_to_hex() is safe because run_command_v_opt() duplicates all arguments already. (It would even be safe if it didn't, but that's a different story.) Signed-off-by: René Scharfe --- builtin/am.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) -- 2.38.1 diff --git a/builtin/am.c b/builtin/am.c index 39fea24833..5781e7a95e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2187,14 +2187,11 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode) int len; if (!is_null_oid(&state->orig_commit)) { - const char *av[4] = { "show", NULL, "--", NULL }; - char *new_oid_str; - int ret; + const char *av[] = { + "show", oid_to_hex(&state->orig_commit), "--", NULL + }; - av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit)); - ret = run_command_v_opt(av, RUN_GIT_CMD); - free(new_oid_str); - return ret; + return run_command_v_opt(av, RUN_GIT_CMD); } switch (sub_mode) { From patchwork Sun Oct 30 11:47:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025074 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 16DA2FA373D for ; Sun, 30 Oct 2022 11:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbiJ3LrL (ORCPT ); Sun, 30 Oct 2022 07:47:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3LrK (ORCPT ); Sun, 30 Oct 2022 07:47:10 -0400 Received: from mout.web.de (mout.web.de [212.227.15.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45C56C2D for ; Sun, 30 Oct 2022 04:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130423; bh=1R6QDc7nNQhEPKz47mDhFf0HX/0OCep8fX/4pqMkC3c=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=IgDN2opEB2rR3MdcnvakJ60dNQkIn+HSXfSRO2vwR6U/4lAI467+naBbgpvkZmIaf TEk0UIsTVftda65rTS6rNZv2Ul/lUOv+o9B9dd15QW2S7yrerDHYCNf39G0Ec5NIWu 0mMF6A0oKwCyISHtFGqb8q3UGyY9CAt/qwVXymYmpSjTi2Km1usIX0DDshk7bRFUIu Vvnwf4WXzufoGo/xKdkenisl/eo2ElDLFkqtaVYob75s2f51c6gGGMLy4umdod4zC2 bRdNJuepe4P7RdU/qSu7Jz+tcKNBlVGcVT5m1W+RJEvG7QZ474Gu7wX2Mq0tNKU3s4 NxztPC6Z5vS6A== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MpU1w-1pPWyx0RYK-00ps4D; Sun, 30 Oct 2022 12:47:03 +0100 Message-ID: <78a5fb6d-4728-e6dc-a3e2-2d38c95ad381@web.de> Date: Sun, 30 Oct 2022 12:47:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 04/12] bisect: simplify building "checkout" argument list Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:QemJmEfPvvMV0AeX1w5e5kBLvudmvlgmhnQUyjLlnF8G6rlqkpx mhkHV0CKLYvzitn2Ilc8Ff0S2U4ZZrm4qymvl314Ot1M0YrvPdDLND78fjTPyUiK7N0bNnu 8+uPmZ3Phtm/JEUMEkfbQAzLMD2SXI/KNd4sC9nIqhoA0YOqsLeIhzki8VDmiQ1uGB1YC9D NTOZYbvgpFTbzYjJdB/zA== UI-OutboundReport: notjunk:1;M01:P0:jDhFse6RQg0=;Oj0OEJ4rvNZgT62RyHU+k1/uHpS XJNEcMB2UJUUKmeinHHAwWta4pd6jzG58KLEiPpH/F+G9z0PayGXwkLAfBzRvEuPW9u4P6+Y/ XY3i/vinbnK+iNRPG0dip5tWPwWSuJUnjblAWSNurk9AG5tiyLBu+bpn92nemVEQLaTOCToNx EIBIh7AC06pWcrpXEOhCbrRNX5tc8Wvb1eNwCZ83cA6AANJ/2bVqC/T9fHg+Xjn+eCg93lZFl +CxW59rni28+hbnTzoqijuCYgfhvMqEhJM0W1zy8aVclMID50Y5WP5iF2gwHBKH+vXElkH1cy CL5KiP8VAQWBHz2uPYpfPOuSYqIqj3rCBGFGLAB2ccmY7Fk0dXqTZiAnmwaI6Fa6sh6u6uGWk vzgnAc94jda4HtShCneNpahqBqeUV9uA9CLZPFiEiLnShHXlrdqQNTICuaybe1G8kxWLjhnhF UgA4Hoe6rc2iQSe4lpgmYPnFZFUQ6MzbcO2pZhiB+MmuXUrUyxDNYgNyRlR2alLcOU1JkStze uaUGdYt2lSecuoymZNsAH+qB7M0mUG3SnMfArFGtZjs+vitmvksTDimdWw/dJyosyCU1Yfblt kanhymiVqDBR+wuRg1Uf3dzoxXF8pXVV4dWQw+pbcRM9uwgQSXCqpNCXScdhd4f+rOw5LKXkq tZWdNY6X+R7qtlacyQLd0UIUDYlf9g346p9jRJxa09LYRbZX45lxVWuMWXZM3mK1rw8xnkE6C hl8drcUTbA3tVgwvIxlSOIh3G6g1FRdut2dJnwhMEAF5l4BBGRkN0LMnd4rg5jTJt/rfcNRUb UBnWFVRDuPnYqZ+V0y5C+67PqiXYQzCO/ordHjkLWmG7jTJ1FEsRxVpkJUNmq8Up8TYisKiAu IXKc8KMNTrCyqhECBi+X/UUW5viDBOk+tlhbIN5U3aIfs4GNkdz/Gdan8kHrYSgg9O8EpTuIn gPyglsSzIhITtyL+BZ7g1fnDR+E= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Reduce the scope of argv_checkout, which allows to fully build it during initialization. Use oid_to_hex() instead of oid_to_hex_r(), because that's simpler and using the static buffer of the former is just as safe as the old static argv_checkout. Signed-off-by: René Scharfe --- bisect.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) -- 2.38.1 diff --git a/bisect.c b/bisect.c index fd581b85a7..090aa5c4b4 100644 --- a/bisect.c +++ b/bisect.c @@ -22,8 +22,6 @@ static struct oid_array skipped_revs; static struct object_id *current_bad_oid; -static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL}; - static const char *term_bad; static const char *term_good; @@ -729,19 +727,20 @@ static int is_expected_rev(const struct object_id *oid) enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int no_checkout) { - char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; struct commit *commit; struct pretty_print_context pp = {0}; struct strbuf commit_msg = STRBUF_INIT; - oid_to_hex_r(bisect_rev_hex, bisect_rev); update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); - argv_checkout[2] = bisect_rev_hex; if (no_checkout) { update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); } else { + const char *argv_checkout[] = { + "checkout", "-q", oid_to_hex(bisect_rev), "--", NULL + }; + if (run_command_v_opt(argv_checkout, RUN_GIT_CMD)) /* * Errors in `run_command()` itself, signaled by res < 0, From patchwork Sun Oct 30 11:48:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025075 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 EFB3EC38A02 for ; Sun, 30 Oct 2022 11:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbiJ3Ls0 (ORCPT ); Sun, 30 Oct 2022 07:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3LsZ (ORCPT ); Sun, 30 Oct 2022 07:48:25 -0400 Received: from mout.web.de (mout.web.de [212.227.15.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98519B852 for ; Sun, 30 Oct 2022 04:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130496; bh=2GRrFBWZ4Y2h4z5MGFMt+f4CSdPpDbxq5Rm/vTOXe3o=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=rhz8xBsz9lHXYQKix45ncal2YS8zrF12l7a4P9Ka/6snTGYrrPfFpmoN0RtpsyVnF /4050xdcw1tNTu65v3XodzTPn2H3+YbPqnC9lYU+mV+p+Ku5QEjzFi5m8FPFIN/s3T nMGeqMBMoSYAqUl9OV1Lmd3m9F6a4qFNkbpw1IIOyjvHtSd9VJBdWc6GmiEiQasI1W qgc1en3gQaJDJ8wgyAweFoT/7WrHFapEKHZ1nO+zphaG/NjbdEoWSQsIrWV0IiefU6 2AwpAaCOUEtWcie+Mhr4CPi+bS6EJvU0Ahe/WSV4T3gRT0mtiDe8FbZ34JDmxaoWAU yRsOQvjIkqGfw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MAcpg-1ovgNs2zY8-00B50h; Sun, 30 Oct 2022 12:48:16 +0100 Message-ID: <434b9dde-8e87-6890-d2b1-581e88bd3c03@web.de> Date: Sun, 30 Oct 2022 12:48:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 05/12] bisect--helper: factor out do_bisect_run() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:5x7WX3DD9YZObnYYsmgqnNb2VEOrOTdSkE/3uqMvGUCjisX7Sei Wm3MbMteBf940lf3S8evtbrQ7C58ovTFGLIelcd1Gq+wb1Oomn8Y8SyeoRx9CKDt/zfjFnp D290yD45EvR2Qqz9bYf41IxfX95NsnCGFoJ5oHQ1X8zgadab5HyF48d/xaw9iZp446UWlHy /HtZbf/NBF45DzvBCTs1w== UI-OutboundReport: notjunk:1;M01:P0:NNhfd/re/fg=;a7Hwfp3eVZJiujoQcbRazJBcn09 6ofUCA0pC53UX8InKcMDURacvQAWLYtv7FFrPO/Q2h3WlphaWxWlrGGC4uC9rPDED2LDNd1KK 7ziCfxvt7kIrbVGka4NzrkeXWrvzwrpOtFWednNut+DWf+lnwh5SD0W0R7sC6TmBNySgr/rEz JCoxJAEZKYTmbdeR9CZnk6ZeZj4Jh2eukH5cnW9MEfY9gOPR6NiFDB1Jpj+xJw8vbZx5IVCI1 zZEcKLz1dd6Q9J7h3tYoXTXU+X0NaoFS2/kKb1Uin9nRbgmMF8knX/1drkIiUUQV3xNumKGQj lsa16RiWccTwiRe7zhn49gymY+U8seXzkfw4UjAXZgYWYro57LBddwz2mBUKbVESX5qeP6blz AP8Dl7dj+NYaWN9E4Q0/jmfX4dgHh+8qgmYuqknFsZt4A78P1h3FuGyx7reaRryTPRBVtE+yo /4EGqLBdMCWcJtGNOM+sgSpY6rHGoo2jUr4HEGCD0R5VF3x0Nx+M++mOAouFZYC8DOyqBuQHl qxLvTG0DWV8dKOVMWy2rZQ46fxgorGRowlFsI2IRrqJg09Ca5PvVkzP8r8/GC93txu0et4O7L EGbiH+2UTROjvwms+EhLejr56+Hm8AUIgqMaCIUXvmuRF6tphcJPt0v8NdIIM++Tp/+bgwKkD 1mGuiXgU+1egpqgKJLMCaVyFZy3JZVvk1S85EBX4NQoS1ZRXnQeuqgSGubTAb9RpHIPZ8YQxJ jAjMWMFz6gqhLJNJGKGUictOMfSOm6sl25QcrI/oakDjZVk/H8vEMbtKnH2v+l6Q5PnoRaCcA 7LlLQTEi6G5RygyDgpPUwCMUituXbApdiZltuH/xetc2En6RG1hkf1QGXJrqfSA8cuHb5g7Jo 3+rAHT04Ko2ZCWiDf39YigN7OgA8AsbO5rHIYqIcifC4VY0PIYuGW/B7RMtdJVSCNPe8vPpUU uyxXP4qSCHgncDHNd+1dtII1zaw= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Deduplicate the code for reporting and starting the bisect run command by moving it to a short helper function. Use a string array instead of a strvec to prepare the arguments, for simplicity. Signed-off-by: René Scharfe --- builtin/bisect--helper.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) -- 2.38.1 diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 28ef7ec2a4..70d1e9d1ad 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -1142,8 +1142,14 @@ static int get_first_good(const char *refname UNUSED, return 1; } -static int verify_good(const struct bisect_terms *terms, - const char **quoted_argv) +static int do_bisect_run(const char *command) +{ + const char *argv[] = { command, NULL }; + printf(_("running %s\n"), command); + return run_command_v_opt(argv, RUN_USING_SHELL); +} + +static int verify_good(const struct bisect_terms *terms, const char *command) { int rc; enum bisect_error res; @@ -1163,8 +1169,7 @@ static int verify_good(const struct bisect_terms *terms, if (res != BISECT_OK) return -1; - printf(_("running %s\n"), quoted_argv[0]); - rc = run_command_v_opt(quoted_argv, RUN_USING_SHELL); + rc = do_bisect_run(command); res = bisect_checkout(¤t_rev, no_checkout); if (res != BISECT_OK) @@ -1177,7 +1182,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) { int res = BISECT_OK; struct strbuf command = STRBUF_INIT; - struct strvec run_args = STRVEC_INIT; const char *new_state; int temporary_stdout_fd, saved_stdout; int is_first_run = 1; @@ -1192,11 +1196,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) return BISECT_FAILED; } - strvec_push(&run_args, command.buf); - while (1) { - printf(_("running %s\n"), command.buf); - res = run_command_v_opt(run_args.v, RUN_USING_SHELL); + res = do_bisect_run(command.buf); /* * Exit code 126 and 127 can either come from the shell @@ -1206,7 +1207,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) * missing or non-executable script. */ if (is_first_run && (res == 126 || res == 127)) { - int rc = verify_good(terms, run_args.v); + int rc = verify_good(terms, command.buf); is_first_run = 0; if (rc < 0) { error(_("unable to verify '%s' on good" @@ -1273,7 +1274,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) } strbuf_release(&command); - strvec_clear(&run_args); return res; } From patchwork Sun Oct 30 11:49:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025076 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 1FD52FA373D for ; Sun, 30 Oct 2022 11:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbiJ3Ltr (ORCPT ); Sun, 30 Oct 2022 07:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3Ltq (ORCPT ); Sun, 30 Oct 2022 07:49:46 -0400 Received: from mout.web.de (mout.web.de [212.227.15.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E41AB852 for ; Sun, 30 Oct 2022 04:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130578; bh=3mOJrWY80LHqXpkDaeJlVPJZQfdngJVNQB8xErYRF/k=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=B6IJRXvu1sBXfZWnXh985M79SpZNzItszlBs2UIl52v/B1uUHHwD+v/bojk1V+Ub3 CoWrhXdtG6vX3siRyVkR6ElA8j7JFgzKmrvKWmvkrOkdixt9NXJzZxvgRHuRv3tTiu xeYWto4EJOvXHHSYdh6WBibYZUSpcOQQMZgejk/ezWQr+PDi8nkIpL8mzTUUzWW5Am 0udJIHSZDKKv90oBLq2ew6ztn1ngb6y1JXLxPbRXiTOzYi0wuZrQp5c6QKbGAN2euH fg3mEwf20XbrR/8D4QGcFm3wLB0XWlT44RcYEXnmBA7sXeKRWahGUsM73+GgIFuKwb mXTTo/My365IQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MQxnv-1oRgNZ0cqd-00O0Ef; Sun, 30 Oct 2022 12:49:38 +0100 Message-ID: <3ba55be2-c0f7-77e6-1b40-323786ccc2bb@web.de> Date: Sun, 30 Oct 2022 12:49:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 06/12] sequencer: simplify building argument list in do_exec() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:zW5fwTCLN+SxDYlIN2V6TDVm1Y620gutSPHu/unEQ9H+y+m4RmT wKsBuzJ1B0QB/gqgs72q2fmrbC6NFfh8/m3ExZk/7nhPuDQA4PyP0qM0bh9EUxjPNrj9Eru sVQeVY6OfNonlXXNtXxTL2U1TgRyetoqrCBuCcaVn7x8zxQXAg5SzAs2UupiMys7R2o0367 4Q3J8CpHUP6RZ1b0dh1gw== UI-OutboundReport: notjunk:1;M01:P0:BJ0OXUDRlu8=;fy0EurksraJ+0Zc+UZzgQrNniD+ Fn4jxPWtjdukSt5lqP2f2jgzNHYG/TwGSshgF5c6mWJ+3oY9gmwpZz+jmMOXEwr1Cqt9zlq3w V5F4JAIDOlK7EDvySorD+26U5EqIlsjHQTnelAFD9kT39Mf7G52n0Uj1blXU87jbCGNd/8P4+ 1IZDlA1a3IhD2qRxaCAQlxmWjLIwQ7L4BM5hoQ/XlTwNodtqnlFHD5fqoNYN8Psm+Dp2q+Pnp cv7YDKeBb/ZinkVr3pdK+RQIE9Uvr9WaqtoSXezbXMkqN8pvD8aj/949w7AxOvUfurNBKnFBB hugruVwgy50D7HDWvaXjglmFtR0/8jjrag6UTJ1ReYwDS4kJl/lHrvwtW0PMfZxtsDikc3+xJ geflRB/T0FICxeOprKLg2sQ7LQJCksndbo5mMtvAMKtatOTKB8wcTDeMN+4wsYUZUjmK+Eo05 JA0IOG4Tzk/jPzUXr4K63WUZiUYe0Twa3OhXfBOtdbbwKHxp7MNxUUFV4hfi6QPn94Ynvo6mz 5LXkbyzxHHwwAnrjAp4WY+EFR/Yk8/eh/xtMcLYwdTA2PmbtLX/x1Z827AbDGzmcR893PGD8/ NmhcfPZ5moCQ5YAqv+0ymLGFFzG1PNaGpkbLAA8iraIjobOSz3GaldiL9BHwtgeoAElmtyPeq +unq3TSFhVgYRA4Q1VTIHtrCo/pyT2dFj/OZqfti9ffLZWq2D6vOO7AMH50QCjio3tylu7THU ZyK70wThPjnS2D0ccuuXckYJxU9UMvK9OsQOQNq68p70bAm+DqEEOyL3sU/ui7SxGSmPQOMaR SQST40aJ30Guzd8DZ9yW/DcKHUTNg48oMpwSRAxkLezdzGDf70GZ+vVjnH+6d0aDu+HKBKUav W9fN+xE5scR19xsdqP8thd0MTKyhiHGEeYv2wCFuvZfRX0FCYK12u4y3LWhrQc+ow7WO9WdcW 0WzB/LwJkTTUvn1rAbwqpxTPTs4= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Build child_argv during initialization, taking advantage of the C99 support for initialization expressions that are not compile time constants. This avoids the use of a magic index constant and is shorter and simpler. Signed-off-by: René Scharfe --- sequencer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.38.1 diff --git a/sequencer.c b/sequencer.c index debb2ecbaf..66eedd2c76 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3558,11 +3558,10 @@ static int error_failed_squash(struct repository *r, static int do_exec(struct repository *r, const char *command_line) { - const char *child_argv[] = { NULL, NULL }; + const char *child_argv[] = { command_line, NULL }; int dirty, status; fprintf(stderr, _("Executing: %s\n"), command_line); - child_argv[0] = command_line; status = run_command_v_opt(child_argv, RUN_USING_SHELL); /* force re-reading of the cache */ From patchwork Sun Oct 30 11:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025077 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 5E656FA373D for ; Sun, 30 Oct 2022 11:50:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229824AbiJ3Luj (ORCPT ); Sun, 30 Oct 2022 07:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3Lug (ORCPT ); Sun, 30 Oct 2022 07:50:36 -0400 Received: from mout.web.de (mout.web.de [212.227.15.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB6B3BF65 for ; Sun, 30 Oct 2022 04:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130628; bh=Hq2rQl7gfH4NohPce2Myn+NHwb5z1VuO6g5tTQl9MDY=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=YuHwefh5eOAOZhOzyKEOIt1lHABxRFIUdDxWj6z05jC0qOQMoKd0GLjuqoet/ZnHJ L9DVD8wQ8JBGHQ/3BxmvtMxGKdyEMJ/U88aK/oG3IQgKQMuD0+UqvzfW4+EJ3RBvc3 NylPNklRa9zPW6h9RPODCnqaI7Wi4aIm/5k50T0w1J1Fabklan+P/cAq+mY7U1S7pg n0HogXRF5ZciHvaWWV7qV217WbwtuQ1cAMvI3Kvm0kXHpKXAHEnkLGt/Fwb7G5cMgW EFRclobT9V/JdMMF8UVOkevbNB2CI539o4R1Dc4V5VEUaTQiSd0fPJu8VhGXkHbBen 4xmfkHDwpXJbw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MNwfU-1oQrt53e7U-00OGSH; Sun, 30 Oct 2022 12:50:27 +0100 Message-ID: <76272512-1e37-0206-5518-5c9c5e646fe8@web.de> Date: Sun, 30 Oct 2022 12:50:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 07/12] use child_process member "args" instead of string array variable Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:Mj7zfp5m6TSXxzUPIdINoq8zuMKjHbnv+gI9MpsCKabg2Dq0/zh 5TZiM9V8allRINQlRz5v1VVTUKTi7CSrQeNbPApI2q/1UUrydGjF/9xWubK50z5505FIjS9 MvqifR0wH0XSr2yYxyVFj9bTTCujXx2Y+gLy8yOkVrJNdAImfGaAXWaz8lHfSr9Bw+ca9W5 +WddV/+LJwn3ArDrIlqTg== UI-OutboundReport: notjunk:1;M01:P0:/LKnNlpkl2A=;3UsxPzp4C1n7r3YstH/VvRHEDEs u8DftsOJCFc9bMa5YEHhAR++wCYfR66U8hfZ3WdAmeUifwzaJbMpBuoK4YNCbLAfS8nkjaGA4 PR2ji99JoxtHCxPMYARZPSiJkDoDBpLDIu7K6jeSPE/L5Wplv6gqsAWUvqJXNSuKsR58NI/kW Hzsefk1GwNxPLp7VBT3X3nKGDa2zJ32DlXMKD9dx6vkqU81kMtG9N791mYrXOKjaXoZmVhrUV kqVwsEfPmfLn+feQCl/QQrImkRSHKIFBk7KfJru7XeqNmEk5y4UxEy1UBLJVbTdJtDhAXfA5n YpHKxYDPE6E2xgnGvic7df+vTvzZscfWKhXz16ziOrmO+ZEDFvvTnbOIf6UEU1dBGFCigfOGT 7L/thx4r00sVzmZS9PwYwRaApwGC1MZatAf6nv9t4ePV5ENTeP3zYmVoUZNFO0pfGixcprNe9 sN/HeWJm8/TM93GPzUDYn3woKloxwcavCifg++T7VQAvefd03BqqyOmFC0gdb9OFFSSvKGgse thAInw/ccwuvgbVEnfEXACYIpWHF245ls2gmpS3XiReug9IiuH+vjI5oktsQK9iHpLDK5bm/3 iMskT+vljTcTjHnMjDnvzz3a27zTWDFUvmCc2y8klwCtKsfXFoxE7tNtlkTAK56aUKxmBicVH 9evP0/0asFn3aILpjJNTl+LX3IuFgvRN6gkliQxHJonVnKa565ttE/JqZpejGLOyGWpopdli2 Ohq/RD80DBYpzOGC+9D9YlEe/SbZa4sbZ1sacHqCnPOeYc1g+W9d/c5WLZiLasgPza5tccSS7 D9w96o+WPEqjrlB30SDS+IYAIOgY2z2inoQJ16QatTOsZCPFacW3L+M9ZQcAvBEsiqbfzPzRg OFLHn4nEZj1QVbkfnRj5f4ZAITg78eKfv2QcUzzBLj0ybnRUzcatejoOKLqurpYMoelF5bjpc v2DCyoQkH134Pv71S9N1f7npv+Q= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use run_command() with a struct child_process variable and populate its "args" member directly instead of building a string array and passing it to run_command_v_opt(). This avoids the use of magic index numbers and makes simplifies the possible addition of more arguments in the future. Signed-off-by: René Scharfe --- builtin/difftool.c | 17 +++++++++-------- builtin/merge.c | 32 ++++++++++++-------------------- builtin/remote.c | 14 ++++++++------ compat/mingw.c | 11 +++++++---- ll-merge.c | 7 ++++--- t/helper/test-fake-ssh.c | 7 ++++--- 6 files changed, 44 insertions(+), 44 deletions(-) -- 2.38.1 diff --git a/builtin/difftool.c b/builtin/difftool.c index 4b10ad1a36..22bcc3444b 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -360,8 +360,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, struct pair_entry *entry; struct index_state wtindex; struct checkout lstate, rstate; - int flags = RUN_GIT_CMD, err = 0; - const char *helper_argv[] = { "difftool--helper", NULL, NULL, NULL }; + int err = 0; + struct child_process cmd = CHILD_PROCESS_INIT; struct hashmap wt_modified, tmp_modified; int indices_loaded = 0; @@ -563,16 +563,17 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, } strbuf_setlen(&ldir, ldir_len); - helper_argv[1] = ldir.buf; strbuf_setlen(&rdir, rdir_len); - helper_argv[2] = rdir.buf; if (extcmd) { - helper_argv[0] = extcmd; - flags = 0; - } else + strvec_push(&cmd.args, extcmd); + } else { + strvec_push(&cmd.args, "difftool--helper"); + cmd.git_cmd = 1; setenv("GIT_DIFFTOOL_DIRDIFF", "true", 1); - ret = run_command_v_opt(helper_argv, flags); + } + strvec_pushl(&cmd.args, ldir.buf, rdir.buf, NULL); + ret = run_command(&cmd); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&wtindex); diff --git a/builtin/merge.c b/builtin/merge.c index 3bb49d805b..3481577145 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -347,33 +347,25 @@ static int save_state(struct object_id *stash) static void read_empty(const struct object_id *oid) { - int i = 0; - const char *args[7]; - - args[i++] = "read-tree"; - args[i++] = "-m"; - args[i++] = "-u"; - args[i++] = empty_tree_oid_hex(); - args[i++] = oid_to_hex(oid); - args[i] = NULL; + struct child_process cmd = CHILD_PROCESS_INIT; + + strvec_pushl(&cmd.args, "read-tree", "-m", "-u", empty_tree_oid_hex(), + oid_to_hex(oid), NULL); + cmd.git_cmd = 1; - if (run_command_v_opt(args, RUN_GIT_CMD)) + if (run_command(&cmd)) die(_("read-tree failed")); } static void reset_hard(const struct object_id *oid) { - int i = 0; - const char *args[6]; - - args[i++] = "read-tree"; - args[i++] = "-v"; - args[i++] = "--reset"; - args[i++] = "-u"; - args[i++] = oid_to_hex(oid); - args[i] = NULL; + struct child_process cmd = CHILD_PROCESS_INIT; + + strvec_pushl(&cmd.args, "read-tree", "-v", "--reset", "-u", + oid_to_hex(oid), NULL); + cmd.git_cmd = 1; - if (run_command_v_opt(args, RUN_GIT_CMD)) + if (run_command(&cmd)) die(_("read-tree failed")); } diff --git a/builtin/remote.c b/builtin/remote.c index 93285fc06e..f0c11fa301 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -92,13 +92,15 @@ static int verbose; static int fetch_remote(const char *name) { - const char *argv[] = { "fetch", name, NULL, NULL }; - if (verbose) { - argv[1] = "-v"; - argv[2] = name; - } + struct child_process cmd = CHILD_PROCESS_INIT; + + strvec_push(&cmd.args, "fetch"); + if (verbose) + strvec_push(&cmd.args, "-v"); + strvec_push(&cmd.args, name); + cmd.git_cmd = 1; printf_ln(_("Updating %s"), name); - if (run_command_v_opt(argv, RUN_GIT_CMD)) + if (run_command(&cmd)) return error(_("Could not fetch %s"), name); return 0; } diff --git a/compat/mingw.c b/compat/mingw.c index 901375d584..d614f156df 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -196,16 +196,19 @@ static int read_yes_no_answer(void) static int ask_yes_no_if_possible(const char *format, ...) { char question[4096]; - const char *retry_hook[] = { NULL, NULL, NULL }; + const char *retry_hook; va_list args; va_start(args, format); vsnprintf(question, sizeof(question), format, args); va_end(args); - if ((retry_hook[0] = mingw_getenv("GIT_ASK_YESNO"))) { - retry_hook[1] = question; - return !run_command_v_opt(retry_hook, 0); + retry_hook = mingw_getenv("GIT_ASK_YESNO"); + if (retry_hook) { + struct child_process cmd = CHILD_PROCESS_INIT; + + strvec_pushl(&cmd.args, retry_hook, question, NULL); + return !run_command(&cmd); } if (!isatty(_fileno(stdin)) || !isatty(_fileno(stderr))) diff --git a/ll-merge.c b/ll-merge.c index a8e2db9336..22a603e8af 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -193,7 +193,7 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn, struct strbuf cmd = STRBUF_INIT; struct strbuf_expand_dict_entry dict[6]; struct strbuf path_sq = STRBUF_INIT; - const char *args[] = { NULL, NULL }; + struct child_process child = CHILD_PROCESS_INIT; int status, fd, i; struct stat st; enum ll_merge_result ret; @@ -219,8 +219,9 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn, strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict); - args[0] = cmd.buf; - status = run_command_v_opt(args, RUN_USING_SHELL); + child.use_shell = 1; + strvec_push(&child.args, cmd.buf); + status = run_command(&child); fd = open(temp[1], O_RDONLY); if (fd < 0) goto bad; diff --git a/t/helper/test-fake-ssh.c b/t/helper/test-fake-ssh.c index 12beee99ad..2e576bcc11 100644 --- a/t/helper/test-fake-ssh.c +++ b/t/helper/test-fake-ssh.c @@ -8,7 +8,7 @@ int cmd_main(int argc, const char **argv) struct strbuf buf = STRBUF_INIT; FILE *f; int i; - const char *child_argv[] = { NULL, NULL }; + struct child_process cmd = CHILD_PROCESS_INIT; /* First, print all parameters into $TRASH_DIRECTORY/ssh-output */ if (!trash_directory) @@ -25,6 +25,7 @@ int cmd_main(int argc, const char **argv) /* Now, evaluate the *last* parameter */ if (argc < 2) return 0; - child_argv[0] = argv[argc - 1]; - return run_command_v_opt(child_argv, RUN_USING_SHELL); + cmd.use_shell = 1; + strvec_push(&cmd.args, argv[argc - 1]); + return run_command(&cmd); } From patchwork Sun Oct 30 11:51:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025078 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 ADDFAC38A02 for ; Sun, 30 Oct 2022 11:51:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbiJ3Lva (ORCPT ); Sun, 30 Oct 2022 07:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3Lv2 (ORCPT ); Sun, 30 Oct 2022 07:51:28 -0400 Received: from mout.web.de (mout.web.de [212.227.15.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8335BBF65 for ; Sun, 30 Oct 2022 04:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130674; bh=xISGsPDPXJcIEmQyC7MBr4WejaokRVxbBRkJkE54phk=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=Ry2cU6lNhn8Ig3oBFCgyM+pj8rnhZ0n+JR8J09DDGqyVXyzxdQH1wIC1teq4mQm18 mUqKMBBAd9bkYpjGSdaUuSM3TeE3TGvMESJ8wS7wXaEd8HhuGIhAm5p2xGq9CfyKyX QqssoWOI3m07XhyKE/3noVGXIs5RiOpwexErvG73xDo3iKNIpPJwIg3Y9+b5hFOLqa 6WlrD/xsr5CjByRPINGyU8Vz0fOL7Or6xMcYpGrdMG89JKii9InjK8NIgFvPWO/jUg SUAe+qAN00bQTryXBRFE5DOJvQ8GAkJlWwwNAplO9NgymU2ftECv6ABplet/I2kd5R 55X6WlMr1tdHw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1M8kAH-1ol06d3CGP-004gd7; Sun, 30 Oct 2022 12:51:14 +0100 Message-ID: <97566ec6-ad18-a53a-ed1f-2148706fbd25@web.de> Date: Sun, 30 Oct 2022 12:51:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 08/12] use child_process members "args" and "env" directly Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:lpHuooQHfW3BB2Ej3IaMzfv998ca2MFTZQyeoawmhqSZTH/yLGe S0t6dgOa5M9G3NAiMkxioeJnJYzTB40T7xg90sP6mI/7bYohZ8ZITbmXaxtZIgpDlxZfjgF qlo/UcyKStMn9YRJnGZE5c01n0MtdW7oVxr4G6FTQHTYaMUFbsRvjNgaw2N/A7bdFm4V1q4 IW1aoyv3hc2eVnFMDag5A== UI-OutboundReport: notjunk:1;M01:P0:ZCuM4R2sk6M=;GAVIsCgqhbnAqSYJfrubenOWhKP BMQdBsH4ZQOm2zq7q6+TJot/oIgGKwbdNE6xFO47m8FJM0sSqew+Pk2ysnI8WZF6QGlfJI+an Wqzj59IlOOjuEc6OC81iPQLPiyZHhwE0anrIRsBfqWsEbvTzzuzDWBaDS//JeamClAT6szi4y 5AU5sjrbSYmDVkHFgMG3UgOZYsay6sKGIdeLA2CHe+n0b42aSiE9O3M5m/ZQsGUygY7mKO2wZ Lmt16W2AFblgTRrlA0KErC1safeURYZSj6+xMLo25V/4Pz8TwC1vhz/W51Jh9PY6kLYlX66EX Ubno7HWu6WsFKsMW+EcNXDSlWWXNb7bRbQlRFePYDuk+49iOOuNiTjEY97k8Z0zBCV4uqmcTf EJ2aDH1Abz8dPJUoNlGv1YZrHglElxmR9pXQsHUMf9aD1ORCYSl5iKAhK5Ou54lJfBRBG0VAV CxRX4qt8ClVeAqPoPMXOOMRAQhlkewTy5qWOmcuY7DMTg2bab4ICg1AzlbtBYxHE1EJ/RXitV mWLMfaN3ApzlATr9Q0Sl1Oj+vErbbd/N8sQSagkZdLDTksHiSxm72INm34uXU7Uj/GCXxsDug GTcHBJahxGPuRTtM2mmP6eT7Pg1JIb0lAI8LOR7W2Cw+tJQPCCIpiuL0ByFm7Nq4WJ65Kgfed Fpi+bCYQXIwUls+oWkAm3KO5wuraHzK4F+jqDlZdtwC9GeB8TlFq/wJN+Ry3wRv6spsSOImLP JdYAlTip2YVNwIzuCs8uivQ/SM/A0bxU9NF+V+xEMV2aktMCh1IhH8KUAZvyEoEllxThisnxH uLO+OsoDdSHHn2ONtdi358K/SBXuam9PZIenwUO77tIhAJAwqnlHnBKGrVziWHMyl1XRdvbU7 XAhb1sZelmbnwYgTjghRvWTGeQ7ky+5gMz+sNEkHiWkw/pyQtQG9teLCvlvWagQveZ1eL6BMV ZRV5DitaAK0WCVdGPIpVWIoH8BE= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Build argument list and environment of child processes by using struct child_process and populating its members "args" and "env" directly instead of maintaining separate strvecs and letting run_command_v_opt() and friends populate these members. This is simpler, shorter and slightly more efficient. Signed-off-by: René Scharfe --- add-interactive.c | 9 ++- builtin/add.c | 19 +++-- builtin/bisect--helper.c | 35 +++++----- builtin/clone.c | 33 ++++----- builtin/gc.c | 14 ++-- builtin/merge.c | 10 +-- builtin/pull.c | 147 +++++++++++++++++++-------------------- builtin/remote.c | 26 ++++--- diff.c | 27 ++++--- git.c | 15 ++-- merge.c | 18 ++--- scalar.c | 13 ++-- sequencer.c | 25 +++---- 13 files changed, 185 insertions(+), 206 deletions(-) -- 2.38.1 diff --git a/add-interactive.c b/add-interactive.c index f071b2a1b4..ecc5ae1b24 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -997,18 +997,17 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps, count = list_and_choose(s, files, opts); opts->flags = 0; if (count > 0) { - struct strvec args = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; - strvec_pushl(&args, "git", "diff", "-p", "--cached", + strvec_pushl(&cmd.args, "git", "diff", "-p", "--cached", oid_to_hex(!is_initial ? &oid : s->r->hash_algo->empty_tree), "--", NULL); for (i = 0; i < files->items.nr; i++) if (files->selected[i]) - strvec_push(&args, + strvec_push(&cmd.args, files->items.items[i].string); - res = run_command_v_opt(args.v, 0); - strvec_clear(&args); + res = run_command(&cmd); } putchar('\n'); diff --git a/builtin/add.c b/builtin/add.c index f84372964c..626c71ec6a 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -240,8 +240,8 @@ static int refresh(int verbose, const struct pathspec *pathspec) int run_add_interactive(const char *revision, const char *patch_mode, const struct pathspec *pathspec) { - int status, i; - struct strvec argv = STRVEC_INIT; + int i; + struct child_process cmd = CHILD_PROCESS_INIT; int use_builtin_add_i = git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1); @@ -272,19 +272,18 @@ int run_add_interactive(const char *revision, const char *patch_mode, return !!run_add_p(the_repository, mode, revision, pathspec); } - strvec_push(&argv, "add--interactive"); + strvec_push(&cmd.args, "add--interactive"); if (patch_mode) - strvec_push(&argv, patch_mode); + strvec_push(&cmd.args, patch_mode); if (revision) - strvec_push(&argv, revision); - strvec_push(&argv, "--"); + strvec_push(&cmd.args, revision); + strvec_push(&cmd.args, "--"); for (i = 0; i < pathspec->nr; i++) /* pass original pathspec, to be re-parsed */ - strvec_push(&argv, pathspec->items[i].original); + strvec_push(&cmd.args, pathspec->items[i].original); - status = run_command_v_opt(argv.v, RUN_GIT_CMD); - strvec_clear(&argv); - return status; + cmd.git_cmd = 1; + return run_command(&cmd); } int interactive_add(const char **argv, const char *prefix, int patch) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 70d1e9d1ad..5c63ba6994 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -220,18 +220,17 @@ static int bisect_reset(const char *commit) } if (!ref_exists("BISECT_HEAD")) { - struct strvec argv = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; - strvec_pushl(&argv, "checkout", branch.buf, "--", NULL); - if (run_command_v_opt(argv.v, RUN_GIT_CMD)) { + cmd.git_cmd = 1; + strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL); + if (run_command(&cmd)) { error(_("could not check out original" " HEAD '%s'. Try 'git bisect" " reset '."), branch.buf); strbuf_release(&branch); - strvec_clear(&argv); return -1; } - strvec_clear(&argv); } strbuf_release(&branch); @@ -1098,40 +1097,38 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar static int bisect_visualize(struct bisect_terms *terms, const char **argv, int argc) { - struct strvec args = STRVEC_INIT; - int flags = RUN_COMMAND_NO_STDIN, res = 0; + struct child_process cmd = CHILD_PROCESS_INIT; struct strbuf sb = STRBUF_INIT; if (bisect_next_check(terms, NULL) != 0) return BISECT_FAILED; + cmd.no_stdin = 1; if (!argc) { if ((getenv("DISPLAY") || getenv("SESSIONNAME") || getenv("MSYSTEM") || getenv("SECURITYSESSIONID")) && exists_in_PATH("gitk")) { - strvec_push(&args, "gitk"); + strvec_push(&cmd.args, "gitk"); } else { - strvec_push(&args, "log"); - flags |= RUN_GIT_CMD; + strvec_push(&cmd.args, "log"); + cmd.git_cmd = 1; } } else { if (argv[0][0] == '-') { - strvec_push(&args, "log"); - flags |= RUN_GIT_CMD; + strvec_push(&cmd.args, "log"); + cmd.git_cmd = 1; } else if (strcmp(argv[0], "tig") && !starts_with(argv[0], "git")) - flags |= RUN_GIT_CMD; + cmd.git_cmd = 1; - strvec_pushv(&args, argv); + strvec_pushv(&cmd.args, argv); } - strvec_pushl(&args, "--bisect", "--", NULL); + strvec_pushl(&cmd.args, "--bisect", "--", NULL); strbuf_read_file(&sb, git_path_bisect_names(), 0); - sq_dequote_to_strvec(sb.buf, &args); + sq_dequote_to_strvec(sb.buf, &cmd.args); strbuf_release(&sb); - res = run_command_v_opt(args.v, flags); - strvec_clear(&args); - return res; + return run_command(&cmd); } static int get_first_good(const char *refname UNUSED, diff --git a/builtin/clone.c b/builtin/clone.c index 547d6464b3..56e7775dae 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -653,9 +653,9 @@ static void update_head(const struct ref *our, const struct ref *remote, static int git_sparse_checkout_init(const char *repo) { - struct strvec argv = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; int result = 0; - strvec_pushl(&argv, "-C", repo, "sparse-checkout", "set", NULL); + strvec_pushl(&cmd.args, "-C", repo, "sparse-checkout", "set", NULL); /* * We must apply the setting in the current process @@ -663,12 +663,12 @@ static int git_sparse_checkout_init(const char *repo) */ core_apply_sparse_checkout = 1; - if (run_command_v_opt(argv.v, RUN_GIT_CMD)) { + cmd.git_cmd = 1; + if (run_command(&cmd)) { error(_("failed to initialize sparse-checkout")); result = 1; } - strvec_clear(&argv); return result; } @@ -733,37 +733,38 @@ static int checkout(int submodule_progress, int filter_submodules) oid_to_hex(&oid), "1", NULL); if (!err && (option_recurse_submodules.nr > 0)) { - struct strvec args = STRVEC_INIT; - strvec_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL); + struct child_process cmd = CHILD_PROCESS_INIT; + strvec_pushl(&cmd.args, "submodule", "update", "--require-init", + "--recursive", NULL); if (option_shallow_submodules == 1) - strvec_push(&args, "--depth=1"); + strvec_push(&cmd.args, "--depth=1"); if (max_jobs != -1) - strvec_pushf(&args, "--jobs=%d", max_jobs); + strvec_pushf(&cmd.args, "--jobs=%d", max_jobs); if (submodule_progress) - strvec_push(&args, "--progress"); + strvec_push(&cmd.args, "--progress"); if (option_verbosity < 0) - strvec_push(&args, "--quiet"); + strvec_push(&cmd.args, "--quiet"); if (option_remote_submodules) { - strvec_push(&args, "--remote"); - strvec_push(&args, "--no-fetch"); + strvec_push(&cmd.args, "--remote"); + strvec_push(&cmd.args, "--no-fetch"); } if (filter_submodules && filter_options.choice) - strvec_pushf(&args, "--filter=%s", + strvec_pushf(&cmd.args, "--filter=%s", expand_list_objects_filter_spec(&filter_options)); if (option_single_branch >= 0) - strvec_push(&args, option_single_branch ? + strvec_push(&cmd.args, option_single_branch ? "--single-branch" : "--no-single-branch"); - err = run_command_v_opt(args.v, RUN_GIT_CMD); - strvec_clear(&args); + cmd.git_cmd = 1; + err = run_command(&cmd); } return err; diff --git a/builtin/gc.c b/builtin/gc.c index 24ea85c7af..a185bec813 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1910,20 +1910,16 @@ static char *schtasks_task_name(const char *frequency) static int schtasks_remove_task(enum schedule_priority schedule) { const char *cmd = "schtasks"; - int result; - struct strvec args = STRVEC_INIT; + struct child_process child = CHILD_PROCESS_INIT; const char *frequency = get_frequency(schedule); char *name = schtasks_task_name(frequency); get_schedule_cmd(&cmd, NULL); - strvec_split(&args, cmd); - strvec_pushl(&args, "/delete", "/tn", name, "/f", NULL); - - result = run_command_v_opt(args.v, 0); - - strvec_clear(&args); + strvec_split(&child.args, cmd); + strvec_pushl(&child.args, "/delete", "/tn", name, "/f", NULL); free(name); - return result; + + return run_command(&child); } static int schtasks_remove_tasks(void) diff --git a/builtin/merge.c b/builtin/merge.c index 3481577145..b3f75f55c8 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -372,22 +372,22 @@ static void reset_hard(const struct object_id *oid) static void restore_state(const struct object_id *head, const struct object_id *stash) { - struct strvec args = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; reset_hard(head); if (is_null_oid(stash)) goto refresh_cache; - strvec_pushl(&args, "stash", "apply", "--index", "--quiet", NULL); - strvec_push(&args, oid_to_hex(stash)); + strvec_pushl(&cmd.args, "stash", "apply", "--index", "--quiet", NULL); + strvec_push(&cmd.args, oid_to_hex(stash)); /* * It is OK to ignore error here, for example when there was * nothing to restore. */ - run_command_v_opt(args.v, RUN_GIT_CMD); - strvec_clear(&args); + cmd.git_cmd = 1; + run_command(&cmd); refresh_cache: if (discard_cache() < 0 || read_cache() < 0) diff --git a/builtin/pull.c b/builtin/pull.c index 403a24d7ca..b21edd767a 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -515,76 +515,75 @@ static void parse_repo_refspecs(int argc, const char **argv, const char **repo, */ static int run_fetch(const char *repo, const char **refspecs) { - struct strvec args = STRVEC_INIT; - int ret; + struct child_process cmd = CHILD_PROCESS_INIT; - strvec_pushl(&args, "fetch", "--update-head-ok", NULL); + strvec_pushl(&cmd.args, "fetch", "--update-head-ok", NULL); /* Shared options */ - argv_push_verbosity(&args); + argv_push_verbosity(&cmd.args); if (opt_progress) - strvec_push(&args, opt_progress); + strvec_push(&cmd.args, opt_progress); /* Options passed to git-fetch */ if (opt_all) - strvec_push(&args, opt_all); + strvec_push(&cmd.args, opt_all); if (opt_append) - strvec_push(&args, opt_append); + strvec_push(&cmd.args, opt_append); if (opt_upload_pack) - strvec_push(&args, opt_upload_pack); - argv_push_force(&args); + strvec_push(&cmd.args, opt_upload_pack); + argv_push_force(&cmd.args); if (opt_tags) - strvec_push(&args, opt_tags); + strvec_push(&cmd.args, opt_tags); if (opt_prune) - strvec_push(&args, opt_prune); + strvec_push(&cmd.args, opt_prune); if (recurse_submodules_cli != RECURSE_SUBMODULES_DEFAULT) switch (recurse_submodules_cli) { case RECURSE_SUBMODULES_ON: - strvec_push(&args, "--recurse-submodules=on"); + strvec_push(&cmd.args, "--recurse-submodules=on"); break; case RECURSE_SUBMODULES_OFF: - strvec_push(&args, "--recurse-submodules=no"); + strvec_push(&cmd.args, "--recurse-submodules=no"); break; case RECURSE_SUBMODULES_ON_DEMAND: - strvec_push(&args, "--recurse-submodules=on-demand"); + strvec_push(&cmd.args, "--recurse-submodules=on-demand"); break; default: BUG("submodule recursion option not understood"); } if (max_children) - strvec_push(&args, max_children); + strvec_push(&cmd.args, max_children); if (opt_dry_run) - strvec_push(&args, "--dry-run"); + strvec_push(&cmd.args, "--dry-run"); if (opt_keep) - strvec_push(&args, opt_keep); + strvec_push(&cmd.args, opt_keep); if (opt_depth) - strvec_push(&args, opt_depth); + strvec_push(&cmd.args, opt_depth); if (opt_unshallow) - strvec_push(&args, opt_unshallow); + strvec_push(&cmd.args, opt_unshallow); if (opt_update_shallow) - strvec_push(&args, opt_update_shallow); + strvec_push(&cmd.args, opt_update_shallow); if (opt_refmap) - strvec_push(&args, opt_refmap); + strvec_push(&cmd.args, opt_refmap); if (opt_ipv4) - strvec_push(&args, opt_ipv4); + strvec_push(&cmd.args, opt_ipv4); if (opt_ipv6) - strvec_push(&args, opt_ipv6); + strvec_push(&cmd.args, opt_ipv6); if (opt_show_forced_updates > 0) - strvec_push(&args, "--show-forced-updates"); + strvec_push(&cmd.args, "--show-forced-updates"); else if (opt_show_forced_updates == 0) - strvec_push(&args, "--no-show-forced-updates"); + strvec_push(&cmd.args, "--no-show-forced-updates"); if (set_upstream) - strvec_push(&args, set_upstream); - strvec_pushv(&args, opt_fetch.v); + strvec_push(&cmd.args, set_upstream); + strvec_pushv(&cmd.args, opt_fetch.v); if (repo) { - strvec_push(&args, repo); - strvec_pushv(&args, refspecs); + strvec_push(&cmd.args, repo); + strvec_pushv(&cmd.args, refspecs); } else if (*refspecs) BUG("refspecs without repo?"); - ret = run_command_v_opt(args.v, RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE); - strvec_clear(&args); - return ret; + cmd.git_cmd = 1; + cmd.close_object_store = 1; + return run_command(&cmd); } /** @@ -653,52 +652,50 @@ static int update_submodules(void) */ static int run_merge(void) { - int ret; - struct strvec args = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; - strvec_pushl(&args, "merge", NULL); + strvec_pushl(&cmd.args, "merge", NULL); /* Shared options */ - argv_push_verbosity(&args); + argv_push_verbosity(&cmd.args); if (opt_progress) - strvec_push(&args, opt_progress); + strvec_push(&cmd.args, opt_progress); /* Options passed to git-merge */ if (opt_diffstat) - strvec_push(&args, opt_diffstat); + strvec_push(&cmd.args, opt_diffstat); if (opt_log) - strvec_push(&args, opt_log); + strvec_push(&cmd.args, opt_log); if (opt_signoff) - strvec_push(&args, opt_signoff); + strvec_push(&cmd.args, opt_signoff); if (opt_squash) - strvec_push(&args, opt_squash); + strvec_push(&cmd.args, opt_squash); if (opt_commit) - strvec_push(&args, opt_commit); + strvec_push(&cmd.args, opt_commit); if (opt_edit) - strvec_push(&args, opt_edit); + strvec_push(&cmd.args, opt_edit); if (cleanup_arg) - strvec_pushf(&args, "--cleanup=%s", cleanup_arg); + strvec_pushf(&cmd.args, "--cleanup=%s", cleanup_arg); if (opt_ff) - strvec_push(&args, opt_ff); + strvec_push(&cmd.args, opt_ff); if (opt_verify) - strvec_push(&args, opt_verify); + strvec_push(&cmd.args, opt_verify); if (opt_verify_signatures) - strvec_push(&args, opt_verify_signatures); - strvec_pushv(&args, opt_strategies.v); - strvec_pushv(&args, opt_strategy_opts.v); + strvec_push(&cmd.args, opt_verify_signatures); + strvec_pushv(&cmd.args, opt_strategies.v); + strvec_pushv(&cmd.args, opt_strategy_opts.v); if (opt_gpg_sign) - strvec_push(&args, opt_gpg_sign); + strvec_push(&cmd.args, opt_gpg_sign); if (opt_autostash == 0) - strvec_push(&args, "--no-autostash"); + strvec_push(&cmd.args, "--no-autostash"); else if (opt_autostash == 1) - strvec_push(&args, "--autostash"); + strvec_push(&cmd.args, "--autostash"); if (opt_allow_unrelated_histories > 0) - strvec_push(&args, "--allow-unrelated-histories"); + strvec_push(&cmd.args, "--allow-unrelated-histories"); - strvec_push(&args, "FETCH_HEAD"); - ret = run_command_v_opt(args.v, RUN_GIT_CMD); - strvec_clear(&args); - return ret; + strvec_push(&cmd.args, "FETCH_HEAD"); + cmd.git_cmd = 1; + return run_command(&cmd); } /** @@ -879,43 +876,41 @@ static int get_rebase_newbase_and_upstream(struct object_id *newbase, static int run_rebase(const struct object_id *newbase, const struct object_id *upstream) { - int ret; - struct strvec args = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; - strvec_push(&args, "rebase"); + strvec_push(&cmd.args, "rebase"); /* Shared options */ - argv_push_verbosity(&args); + argv_push_verbosity(&cmd.args); /* Options passed to git-rebase */ if (opt_rebase == REBASE_MERGES) - strvec_push(&args, "--rebase-merges"); + strvec_push(&cmd.args, "--rebase-merges"); else if (opt_rebase == REBASE_INTERACTIVE) - strvec_push(&args, "--interactive"); + strvec_push(&cmd.args, "--interactive"); if (opt_diffstat) - strvec_push(&args, opt_diffstat); - strvec_pushv(&args, opt_strategies.v); - strvec_pushv(&args, opt_strategy_opts.v); + strvec_push(&cmd.args, opt_diffstat); + strvec_pushv(&cmd.args, opt_strategies.v); + strvec_pushv(&cmd.args, opt_strategy_opts.v); if (opt_gpg_sign) - strvec_push(&args, opt_gpg_sign); + strvec_push(&cmd.args, opt_gpg_sign); if (opt_signoff) - strvec_push(&args, opt_signoff); + strvec_push(&cmd.args, opt_signoff); if (opt_autostash == 0) - strvec_push(&args, "--no-autostash"); + strvec_push(&cmd.args, "--no-autostash"); else if (opt_autostash == 1) - strvec_push(&args, "--autostash"); + strvec_push(&cmd.args, "--autostash"); if (opt_verify_signatures && !strcmp(opt_verify_signatures, "--verify-signatures")) warning(_("ignoring --verify-signatures for rebase")); - strvec_push(&args, "--onto"); - strvec_push(&args, oid_to_hex(newbase)); + strvec_push(&cmd.args, "--onto"); + strvec_push(&cmd.args, oid_to_hex(newbase)); - strvec_push(&args, oid_to_hex(upstream)); + strvec_push(&cmd.args, oid_to_hex(upstream)); - ret = run_command_v_opt(args.v, RUN_GIT_CMD); - strvec_clear(&args); - return ret; + cmd.git_cmd = 1; + return run_command(&cmd); } static int get_can_ff(struct object_id *orig_head, diff --git a/builtin/remote.c b/builtin/remote.c index f0c11fa301..729f6f3643 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1510,37 +1510,35 @@ static int update(int argc, const char **argv, const char *prefix) N_("prune remotes after fetching")), OPT_END() }; - struct strvec fetch_argv = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; int default_defined = 0; - int retval; argc = parse_options(argc, argv, prefix, options, builtin_remote_update_usage, PARSE_OPT_KEEP_ARGV0); - strvec_push(&fetch_argv, "fetch"); + strvec_push(&cmd.args, "fetch"); if (prune != -1) - strvec_push(&fetch_argv, prune ? "--prune" : "--no-prune"); + strvec_push(&cmd.args, prune ? "--prune" : "--no-prune"); if (verbose) - strvec_push(&fetch_argv, "-v"); - strvec_push(&fetch_argv, "--multiple"); + strvec_push(&cmd.args, "-v"); + strvec_push(&cmd.args, "--multiple"); if (argc < 2) - strvec_push(&fetch_argv, "default"); + strvec_push(&cmd.args, "default"); for (i = 1; i < argc; i++) - strvec_push(&fetch_argv, argv[i]); + strvec_push(&cmd.args, argv[i]); - if (strcmp(fetch_argv.v[fetch_argv.nr-1], "default") == 0) { + if (strcmp(cmd.args.v[cmd.args.nr-1], "default") == 0) { git_config(get_remote_default, &default_defined); if (!default_defined) { - strvec_pop(&fetch_argv); - strvec_push(&fetch_argv, "--all"); + strvec_pop(&cmd.args); + strvec_push(&cmd.args, "--all"); } } - retval = run_command_v_opt(fetch_argv.v, RUN_GIT_CMD); - strvec_clear(&fetch_argv); - return retval; + cmd.git_cmd = 1; + return run_command(&cmd); } static int remove_all_fetch_refspecs(const char *key) diff --git a/diff.c b/diff.c index 285d6e2d57..2f1bb18772 100644 --- a/diff.c +++ b/diff.c @@ -4301,35 +4301,34 @@ static void run_external_diff(const char *pgm, const char *xfrm_msg, struct diff_options *o) { - struct strvec argv = STRVEC_INIT; - struct strvec env = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; struct diff_queue_struct *q = &diff_queued_diff; - strvec_push(&argv, pgm); - strvec_push(&argv, name); + strvec_push(&cmd.args, pgm); + strvec_push(&cmd.args, name); if (one && two) { - add_external_diff_name(o->repo, &argv, name, one); + add_external_diff_name(o->repo, &cmd.args, name, one); if (!other) - add_external_diff_name(o->repo, &argv, name, two); + add_external_diff_name(o->repo, &cmd.args, name, two); else { - add_external_diff_name(o->repo, &argv, other, two); - strvec_push(&argv, other); - strvec_push(&argv, xfrm_msg); + add_external_diff_name(o->repo, &cmd.args, other, two); + strvec_push(&cmd.args, other); + strvec_push(&cmd.args, xfrm_msg); } } - strvec_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); - strvec_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr); + strvec_pushf(&cmd.env, "GIT_DIFF_PATH_COUNTER=%d", + ++o->diff_path_counter); + strvec_pushf(&cmd.env, "GIT_DIFF_PATH_TOTAL=%d", q->nr); diff_free_filespec_data(one); diff_free_filespec_data(two); - if (run_command_v_opt_cd_env(argv.v, RUN_USING_SHELL, NULL, env.v)) + cmd.use_shell = 1; + if (run_command(&cmd)) die(_("external diff died, stopping at %s"), name); remove_tempfile(); - strvec_clear(&argv); - strvec_clear(&env); } static int similarity_index(struct diff_filepair *p) diff --git a/git.c b/git.c index ee7758dcb0..6662548986 100644 --- a/git.c +++ b/git.c @@ -787,7 +787,7 @@ static int run_argv(int *argcp, const char ***argv) if (!done_alias) handle_builtin(*argcp, *argv); else if (get_builtin(**argv)) { - struct strvec args = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; int i; /* @@ -804,18 +804,21 @@ static int run_argv(int *argcp, const char ***argv) commit_pager_choice(); - strvec_push(&args, "git"); + strvec_push(&cmd.args, "git"); for (i = 0; i < *argcp; i++) - strvec_push(&args, (*argv)[i]); + strvec_push(&cmd.args, (*argv)[i]); - trace_argv_printf(args.v, "trace: exec:"); + trace_argv_printf(cmd.args.v, "trace: exec:"); /* * if we fail because the command is not found, it is * OK to return. Otherwise, we just pass along the status code. */ - i = run_command_v_opt_tr2(args.v, RUN_SILENT_EXEC_FAILURE | - RUN_CLEAN_ON_EXIT | RUN_WAIT_AFTER_CLEAN, "git_alias"); + cmd.silent_exec_failure = 1; + cmd.clean_on_exit = 1; + cmd.wait_after_clean = 1; + cmd.trace2_child_class = "git_alias"; + i = run_command(&cmd); if (i >= 0 || errno != ENOENT) exit(i); die("could not execute builtin %s", **argv); diff --git a/merge.c b/merge.c index 2382ff66d3..445b4f19aa 100644 --- a/merge.c +++ b/merge.c @@ -19,22 +19,22 @@ int try_merge_command(struct repository *r, const char **xopts, struct commit_list *common, const char *head_arg, struct commit_list *remotes) { - struct strvec args = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; int i, ret; struct commit_list *j; - strvec_pushf(&args, "merge-%s", strategy); + strvec_pushf(&cmd.args, "merge-%s", strategy); for (i = 0; i < xopts_nr; i++) - strvec_pushf(&args, "--%s", xopts[i]); + strvec_pushf(&cmd.args, "--%s", xopts[i]); for (j = common; j; j = j->next) - strvec_push(&args, merge_argument(j->item)); - strvec_push(&args, "--"); - strvec_push(&args, head_arg); + strvec_push(&cmd.args, merge_argument(j->item)); + strvec_push(&cmd.args, "--"); + strvec_push(&cmd.args, head_arg); for (j = remotes; j; j = j->next) - strvec_push(&args, merge_argument(j->item)); + strvec_push(&cmd.args, merge_argument(j->item)); - ret = run_command_v_opt(args.v, RUN_GIT_CMD); - strvec_clear(&args); + cmd.git_cmd = 1; + ret = run_command(&cmd); discard_index(r->index); if (repo_read_index(r) < 0) diff --git a/scalar.c b/scalar.c index 6de9c0ee52..03f9e480dd 100644 --- a/scalar.c +++ b/scalar.c @@ -69,21 +69,18 @@ static void setup_enlistment_directory(int argc, const char **argv, static int run_git(const char *arg, ...) { - struct strvec argv = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; va_list args; const char *p; - int res; va_start(args, arg); - strvec_push(&argv, arg); + strvec_push(&cmd.args, arg); while ((p = va_arg(args, const char *))) - strvec_push(&argv, p); + strvec_push(&cmd.args, p); va_end(args); - res = run_command_v_opt(argv.v, RUN_GIT_CMD); - - strvec_clear(&argv); - return res; + cmd.git_cmd = 1; + return run_command(&cmd); } struct scalar_config { diff --git a/sequencer.c b/sequencer.c index 66eedd2c76..31e24f38f8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3183,18 +3183,15 @@ static int rollback_is_safe(void) static int reset_merge(const struct object_id *oid) { - int ret; - struct strvec argv = STRVEC_INIT; + struct child_process cmd = CHILD_PROCESS_INIT; - strvec_pushl(&argv, "reset", "--merge", NULL); + cmd.git_cmd = 1; + strvec_pushl(&cmd.args, "reset", "--merge", NULL); if (!is_null_oid(oid)) - strvec_push(&argv, oid_to_hex(oid)); + strvec_push(&cmd.args, oid_to_hex(oid)); - ret = run_command_v_opt(argv.v, RUN_GIT_CMD); - strvec_clear(&argv); - - return ret; + return run_command(&cmd); } static int rollback_single_pick(struct repository *r) @@ -4866,14 +4863,14 @@ static int pick_commits(struct repository *r, static int continue_single_pick(struct repository *r, struct replay_opts *opts) { - struct strvec argv = STRVEC_INIT; - int ret; + struct child_process cmd = CHILD_PROCESS_INIT; if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") && !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) return error(_("no cherry-pick or revert in progress")); - strvec_push(&argv, "commit"); + cmd.git_cmd = 1; + strvec_push(&cmd.args, "commit"); /* * continue_single_pick() handles the case of recovering from a @@ -4886,11 +4883,9 @@ static int continue_single_pick(struct repository *r, struct replay_opts *opts) * Include --cleanup=strip as well because we don't want the * "# Conflicts:" messages. */ - strvec_pushl(&argv, "--no-edit", "--cleanup=strip", NULL); + strvec_pushl(&cmd.args, "--no-edit", "--cleanup=strip", NULL); - ret = run_command_v_opt(argv.v, RUN_GIT_CMD); - strvec_clear(&argv); - return ret; + return run_command(&cmd); } static int commit_staged_changes(struct repository *r, From patchwork Sun Oct 30 11:51:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025079 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 B8222C38A02 for ; Sun, 30 Oct 2022 11:52:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbiJ3LwG (ORCPT ); Sun, 30 Oct 2022 07:52:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3LwF (ORCPT ); Sun, 30 Oct 2022 07:52:05 -0400 Received: from mout.web.de (mout.web.de [212.227.15.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CCD1BF65 for ; Sun, 30 Oct 2022 04:52:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130716; bh=Fv1hB6tG5iiVpp6Rw+u+dNHfWLutR6Zt9i9eoxFbfrE=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=qnpcQDPgBT5ppGp1KeG39002QihR6WLgobTHgVG577o5XopbtBGzQgvFdQXMQL6t4 gFyba+9IYZoy8irmBz/cAhTm3IApr7r8C9oJNi+Egvu36T634mB3xpIc3Whpu5GtCO a4hujIUAm4CNQ6DL/vgaTJvsYq8mwaAs+3/LG+HEUWsJqof3SXfuS9sbrSfY3742fx VI6MOzB7DkV8zDEfIcF3qfem9A2TdTIS7uhbtnQzD14y5RJrj86heejG4SZcg2yFoK M1lGsQn+Eca+f7xVPAlwjsioBYjuoAZQlSu+9xCkrfNABLB749gGtuxBztw5zBjh1d XCm5sia+qpVkQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1Mcpuw-1pNti23H5W-00Zuq1; Sun, 30 Oct 2022 12:51:56 +0100 Message-ID: Date: Sun, 30 Oct 2022 12:51:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 09/12] replace and remove run_command_v_opt_cd_env() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:ibnxsrebPLEzKFFT81Rk1UhKwDai2lZgq4BLpc/p4Wt5yY6sDy0 LQeqWXaHRzMAne4YJ3WSUoZdBfqfE3dwOjECOKzxolByEFTbuOFzfSOjmfI6ath/4ItX09x lUT1qz1RXHFP58x301us7IutMgHi0JRoRnG5S0X2364dErcXqQm98SWt/fbMUzGz7oTHL4L yMw0EOrWJXND6pvnDLSrg== UI-OutboundReport: notjunk:1;M01:P0:2Et6/IyJKQk=;BuTPtJCV4gZNkHtTcfsoFX0hiGK oW2cgNcv2Q1F2KC6hRD3VhfUJjVpyhK9HxZTforqGpCpWpXO1u4rI4p2bT+7HhNp3eDaSuiaU 5savr413KDokJN3kLotznXSh//hqmX3kB0/thzpXe//xvzzXwjhp5dC/aKOBfE9S5C1sRh5is Q3IlxrkS6wIaIlfFAc0E7knaeKpYlmYT0UtEPDtIW2MhrnDlaLgYFngyKraqwZXyczG/eYt4r JbBnZDn0Oiy/A2QoFnedFkK8/KfDNunbHBh2dbLe3dgAsWpaiHClkl4BucKsly8PtHF59fFjS Y9cfxrM4vE2uOkwZwdRYfSV9H9a/FGb3A1iUfthvGa51HZwBRteXAcRAqnbZXfsZGc4VK2Q1I YVkzkCTqaf5XPMDq3ML9CBnveezPlzwBvHrNv8DamAHN8aQGGeaHamoUyrxKFwsMzuCX8F+Pk LorccQbX3mVV2/4IXAEbjvLXgW8OWGQxCww/fbvWJ8H05NrwmagzOAYM30Mf9Bso4uvyQNSS2 eDwd8H0cKtlVNV8Fp30SdPcX3cWmcBe4xTnFp5RQ2fF+rhpqY8c7/Sy67bGpe0AEAd2Nrc78P lpU1y9CAfUXpDGomsLcbBWizw2dxqgIBua8fo1az1sY7bxqtR1Yccc6YMyNF/zASpYGE9MQ1w gWVaNu+VgFlXPoI5WCgezHDmdCeOLYnva8ZZdpwGD+UgbJve4VtMk+xKVjq/C7xDv8EiZJc9y KBTi8grB0ZbsueaVcZpSNcWa5BwVAyviMUZQoWZglnkNLd2irz55pO5BaChwc4EVlX+m7OM8g sunAJWBrEhX6ysfdjUZl7bm063d7fIWe3Pl4Pn8tN3V9f4KOT/ZP1Fhi48l3cdRDv72M0wJfB JiOdUUxPydczsceMTfdLUwyvxZ9igCfDyr+wcBC4/NHNlhm0A8jcqd17xNW5KCX+O0Tp0UCSx gJXFzjzEO21rJNqk95TwZgIvZQ0= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org run_command_v_opt_cd_env() is only used in an example in a comment. Use the struct child_process member "env" and run_command() directly instead and then remove the unused convenience function. Signed-off-by: René Scharfe --- run-command.c | 7 +------ run-command.h | 3 +-- tmp-objdir.h | 6 ++++-- 3 files changed, 6 insertions(+), 10 deletions(-) -- 2.38.1 diff --git a/run-command.c b/run-command.c index c772acd743..954257abb5 100644 --- a/run-command.c +++ b/run-command.c @@ -1006,7 +1006,7 @@ int run_command(struct child_process *cmd) int run_command_v_opt(const char **argv, int opt) { - return run_command_v_opt_cd_env(argv, opt, NULL, NULL); + return run_command_v_opt_cd_env_tr2(argv, opt, NULL, NULL, NULL); } int run_command_v_opt_tr2(const char **argv, int opt, const char *tr2_class) @@ -1014,11 +1014,6 @@ int run_command_v_opt_tr2(const char **argv, int opt, const char *tr2_class) return run_command_v_opt_cd_env_tr2(argv, opt, NULL, NULL, tr2_class); } -int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env) -{ - return run_command_v_opt_cd_env_tr2(argv, opt, dir, env, NULL); -} - int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, const char *const *env, const char *tr2_class) { diff --git a/run-command.h b/run-command.h index 820fc25b02..05c02485df 100644 --- a/run-command.h +++ b/run-command.h @@ -151,7 +151,7 @@ struct child_process { /** * The functions: start_command, finish_command, run_command, - * run_command_v_opt, run_command_v_opt_cd_env do the following: + * run_command_v_opt do the following: * * - If a system call failed, errno is set and -1 is returned. A diagnostic * is printed. @@ -249,7 +249,6 @@ int run_command_v_opt_tr2(const char **argv, int opt, const char *tr2_class); * env (the environment) is to be formatted like environ: "VAR=VALUE". * To unset an environment variable use just "VAR". */ -int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env); int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, const char *const *env, const char *tr2_class); diff --git a/tmp-objdir.h b/tmp-objdir.h index 76efc7edee..237d96b660 100644 --- a/tmp-objdir.h +++ b/tmp-objdir.h @@ -10,9 +10,11 @@ * * Example: * + * struct child_process child = CHILD_PROCESS_INIT; * struct tmp_objdir *t = tmp_objdir_create("incoming"); - * if (!run_command_v_opt_cd_env(cmd, 0, NULL, tmp_objdir_env(t)) && - * !tmp_objdir_migrate(t)) + * strvec_push(&child.args, cmd); + * strvec_pushv(&child.env, tmp_objdir_env(t)); + * if (!run_command(&child)) && !tmp_objdir_migrate(t)) * printf("success!\n"); * else * die("failed...tmp_objdir will clean up for us"); From patchwork Sun Oct 30 11:52:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025080 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 3FD69FA373D for ; Sun, 30 Oct 2022 11:52:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbiJ3Lwv (ORCPT ); Sun, 30 Oct 2022 07:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229868AbiJ3Lwt (ORCPT ); Sun, 30 Oct 2022 07:52:49 -0400 Received: from mout.web.de (mout.web.de [212.227.15.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD26EC763 for ; Sun, 30 Oct 2022 04:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130760; bh=jK6l5u0ox8IwbsczueR08s5F/LyA/aGjVHFSNfJ84Ms=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=i+UtU3g0M+LmZ0TfSmb0apVHZedgiP451+Xg4oUBJi43vWZ324uDOTacztbmGQehl KyW43X/bEgh9hTgtqsnFog05flaqVepCic87sxEkwcnLUWlQwogjzJzCOP87Ji/G9D zeOwmZumIL+X/hGOq8gLyyskynS3WswhePZxut2khGYpUlgVxrVCeBxF08uKmBBgpo HTa8wTo6MT236aSsky2H3gzLm5JetmdJGP8wEnJjaKkBjRAwgGeKrNix5Fgpesxsqb UNV0IUveCXPRzuZ5gpEccTY/dSzRTOkBA4ShvGOU3dJKU3rkQUZC363HIDrol9rSAQ e0WRpiiwj+yjA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1Mq1CA-1pSHNq1wFm-00n8Eq; Sun, 30 Oct 2022 12:52:40 +0100 Message-ID: Date: Sun, 30 Oct 2022 12:52:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 10/12] replace and remove run_command_v_opt_tr2() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:J4Cowx5Ru9wQpYB41y4DpEb189aMlJr5EozG8zVtpUVKIpWiq1J jBYC5bRGp1JeK/Tpi6zS64URTEIr1QNf841bdcQg3F/LY3FwDhOGqfH38dujqAOREOOWrvO /dC0SWdM4kzoTFvP1Z2hS8Bru8jTwNSsEeQaJk9xIU8XtN7InxqnxBZR0O2yZCDJ4+I+/H1 Ha8ED6r0BVGqIoRRkwfSg== UI-OutboundReport: notjunk:1;M01:P0:7cAF4+GIyzE=;yxh1i+V3ht4N1lYaerR3HEPJlL6 cfMhnLRtya73ZPrAnHdKTIF6gkwlDc5fnE44dNtjgJYFWjsfXsBnBr/fc7n9jL+TAAt8wGij9 BKAAWX5zL8xolAwF3C1iztTErI05oHPQhRkWKmZ0LbEtGr/AAB2IQI0HryP7K9BBNpJcTIR2O owYvO8kfyxqz2fgjcTpFwTPQ2GX1LvJTceqkNr6z4WxbtTrEMogXlVWpN43QyNrKfScO45bBq FpbSpRKEmKRWkxLotDp1agB4PknoQOoPb278o+Vg/7g7JV3YxJyGpClFNjG50upg38lfNSSbm eXYTrVsUGTYivjBWCVeqO+WgFutu43Wcqqu3fsY24wC2sboBK097p7yQ6T5IcXK2YOHLfJ2tj ugFz+Oo1lF30/ufgVVScZsxIVdzzDmZ6wTGVJZIZv1FGX/z4a6mk/QXjFq+y2Q4Qak51wMHGx F1QNUn4pSky9yKaJ3capYoJaaOBz8zGOLYYyp0o88cqcUdpqzLliMFCjF+1L41Gm0i1s+WKKZ Alp+MuZgDu1o8/fXrfHjjHev6IoFEdc48BUXCdq7a3xfrseXoTX2rPgBTGz2YNmHTAvieAGfC U39Ur4Anr4JENh3Rh+Ncs8Y89zw4IA6tFj9Wx/QqexjF18IH+6JX/1fIgrQrnJzJdaqikzA79 blrb7uMKawjlZADzP2ebpAmK4i5mLR22NeR57MV2QtkPCG95UBZSFYAYahmauCvNm8cbTLkHT uUubr5ngwCqGCbRw4YVNL0kp0L2F5ICo/0vfgYmctuR/TUIYUeZNl7TvY8ObovNHQAcsJyjfN T1Zei4aWpp2Ssxc+Vboz7y95BOajdw/At8gY6kln4QvhuD9QmC6BC4gnAENPD3SEVXXPZ231m HKbs7IqkEixiT5cSmS9Ek23mdTHpd1heLrMyL/hJS96hfYcD99hURS6ckdG/Cwk0ukS957LNj y24o9HPDS+G54KUuLMuhUlTRxXk= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The convenience function run_command_v_opt_tr2() is only used by a single caller. Use struct child_process and run_command() directly instead and remove the underused function. Signed-off-by: René Scharfe --- fsmonitor-ipc.c | 10 +++++++--- run-command.c | 5 ----- run-command.h | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) -- 2.38.1 diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c index c0f42301c8..19d772f0f3 100644 --- a/fsmonitor-ipc.c +++ b/fsmonitor-ipc.c @@ -54,10 +54,14 @@ enum ipc_active_state fsmonitor_ipc__get_state(void) static int spawn_daemon(void) { - const char *args[] = { "fsmonitor--daemon", "start", NULL }; + struct child_process cmd = CHILD_PROCESS_INIT; - return run_command_v_opt_tr2(args, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD, - "fsmonitor"); + cmd.git_cmd = 1; + cmd.no_stdin = 1; + cmd.trace2_child_class = "fsmonitor"; + strvec_pushl(&cmd.args, "fsmonitor--daemon", "start", NULL); + + return run_command(&cmd); } int fsmonitor_ipc__send_query(const char *since_token, diff --git a/run-command.c b/run-command.c index 954257abb5..3a8d578f72 100644 --- a/run-command.c +++ b/run-command.c @@ -1009,11 +1009,6 @@ int run_command_v_opt(const char **argv, int opt) return run_command_v_opt_cd_env_tr2(argv, opt, NULL, NULL, NULL); } -int run_command_v_opt_tr2(const char **argv, int opt, const char *tr2_class) -{ - return run_command_v_opt_cd_env_tr2(argv, opt, NULL, NULL, tr2_class); -} - int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, const char *const *env, const char *tr2_class) { diff --git a/run-command.h b/run-command.h index 05c02485df..ac67791c81 100644 --- a/run-command.h +++ b/run-command.h @@ -244,7 +244,6 @@ int run_auto_maintenance(int quiet); * corresponds to the member .env. */ int run_command_v_opt(const char **argv, int opt); -int run_command_v_opt_tr2(const char **argv, int opt, const char *tr2_class); /* * env (the environment) is to be formatted like environ: "VAR=VALUE". * To unset an environment variable use just "VAR". From patchwork Sun Oct 30 11:53:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025081 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 C265CC38A02 for ; Sun, 30 Oct 2022 11:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbiJ3Lxw (ORCPT ); Sun, 30 Oct 2022 07:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiJ3Lxt (ORCPT ); Sun, 30 Oct 2022 07:53:49 -0400 Received: from mout.web.de (mout.web.de [212.227.15.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 931C6BE03 for ; Sun, 30 Oct 2022 04:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130821; bh=bX0rHYHmphu/qealS7JFhJdLCrrcBuifUie9wQgq+G0=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=UUSDtp2v01Xt/AF1525VrB/594b0UUzgTetoSjLcLVqSFwBj70isjlUau1IkgB10U FneDDzxGvBX+tv9E7/kEDh/T7BFgT+kprtQDStj2Nrj8QPJgzrKDW3gQZcut9TYFJX nT+HEtjk+kNdG2HZ/G+0Ggnc75vyahsm1kq24kFC07NvcbRuHTJdyb31w3i3OLCMsz P8eonyU1MtylXmXbFKLhZIvpTXeGa0UCbtM9+FScUNL7aUllLnr72qkK6TJj7fxAlP AOYzr7nEcG5BmzCbCTKL2W823pwUMRrlqZmyc0eBvHmTxxnajnGW7w4j8uGICiUx84 zz89AvgMVEQtg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MVrft-1ofNR20Hjx-00RmBu; Sun, 30 Oct 2022 12:53:41 +0100 Message-ID: <44d50eb3-210e-d946-625b-6df06898b629@web.de> Date: Sun, 30 Oct 2022 12:53:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 11/12] replace and remove run_command_v_opt_cd_env_tr2() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:+gU/MQZ+ZCXkMmnJlUj/W/kZV6Ttph2VIFug0EnxXmieVXeYoq/ uLrkOA9ty3lqEoU6cqJIBKSRNpHrxZeLVGsponxsxuaMIjxhgF722MDLLnwTuSAE9V+xpBs jxKsfxtnpVH2bGKOVoB/xKHERpEPhxNuuO0NuVstNtCcyf8EgSsadrwjFHk0wqf0fAKZkTL HmgPLOAsAkiV94Hp8mn/A== UI-OutboundReport: notjunk:1;M01:P0:/sxTnirqx2Y=;DQHMhHXeAu1XjaXweZ20m2yP//6 QEojs2yX3xQuWqB4ZVG0Nif/vwIvqDe1AnSme7QnNDdBtuTtTaEYsh0GLIY+OoZeJ8Z3RW8yc mU5IZl8Sl9wyqqlri3/pLT+VsKcXYUyMuJmqKb71XYb0vTBBg63KWjk6XVKEVdTDj7AgBBpi2 rk+IC4n3KngThygSBU1v9MsEO79+RJBDawotNqTvo1Ig7KG2XH/AJxvPLwqJ4/mMt4Hn+TbL8 CtwU/JM7Yo+rN1WTIUEl41cQ4oh+yGuw43cvj/Jz1ZBm/Eja3DVvWWbXfIijp71TQEiyY25fq YIjT2m7s5rX70HVIxgpOOsNNDDlhCP3b7h/oAKj4AXwjlP4p1lgzMs5m9B5GBn6UNiV6970mc xuv8bODMuoFuNK6kDGDOkCCLkKilZC+/ls6RRnYwD+sdN4z2zQUeJwQttiNHw912io1MkdS5L xcbKtivNky4h45NSBIO7SovZY9Uu8/XWgydAb187/eZZALkuBY5FTfg6QzdNYnV1r3Mor4SHo k7AHcMdrd0ewrxYiwhPQxZwgfmssTuOf+McMNFZcWcowIFxlkKr5nUA2C+PRS5r61vQt5qmAN pD/vsEBRV6Yjj0L7NJv8wkzukJDhl5mKPm0Gv3SToYmNSj5TB5bE7Cou4XEEWmk4lWyE281p2 L0SNFrBOnhaIWsYqYy1tCEq+79B7VgssaiQhaFBWYXgOaZhDNND1BcZ3sf/rm8Utya2MCv3L7 cvSHcu1VIV/EKjjBN1JtGtm8h4hRTTctwR/Yo2Ay9iD6zBTizW3aeNaQr8fjwu0OF+eZsxJ0l 8Zjct+ka0Czg+yvagREhRhfuK3eGzjDituVhlSndxuCUIahJvDWmCKpMSmPD8BCftpT+P9+eE qlRsNrMLiNXTTSCisV2AP3gk7PMoF7w7xa1zO9EEBhN/Mhy1kSsY60/IYAx9SCxeqDpEV2dyU VAXPRUdrBvIIc0tUZCfRTBkIQVs= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The convenience function run_command_v_opt_cd_env_tr2() has no external callers left. Inline it and remove it from the API. Signed-off-by: René Scharfe --- run-command.c | 10 ---------- run-command.h | 10 +--------- 2 files changed, 1 insertion(+), 19 deletions(-) -- 2.38.1 diff --git a/run-command.c b/run-command.c index 3a8d578f72..f8f810d755 100644 --- a/run-command.c +++ b/run-command.c @@ -1005,12 +1005,6 @@ int run_command(struct child_process *cmd) } int run_command_v_opt(const char **argv, int opt) -{ - return run_command_v_opt_cd_env_tr2(argv, opt, NULL, NULL, NULL); -} - -int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, - const char *const *env, const char *tr2_class) { struct child_process cmd = CHILD_PROCESS_INIT; strvec_pushv(&cmd.args, argv); @@ -1022,10 +1016,6 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0; cmd.wait_after_clean = opt & RUN_WAIT_AFTER_CLEAN ? 1 : 0; cmd.close_object_store = opt & RUN_CLOSE_OBJECT_STORE ? 1 : 0; - cmd.dir = dir; - if (env) - strvec_pushv(&cmd.env, (const char **)env); - cmd.trace2_child_class = tr2_class; return run_command(&cmd); } diff --git a/run-command.h b/run-command.h index ac67791c81..4391696bf0 100644 --- a/run-command.h +++ b/run-command.h @@ -233,23 +233,15 @@ int run_auto_maintenance(int quiet); #define RUN_CLOSE_OBJECT_STORE (1<<7) /** - * Convenience functions that encapsulate a sequence of + * Convenience function that encapsulates a sequence of * start_command() followed by finish_command(). The argument argv * specifies the program and its arguments. The argument opt is zero * or more of the flags `RUN_COMMAND_NO_STDIN`, `RUN_GIT_CMD`, * `RUN_COMMAND_STDOUT_TO_STDERR`, or `RUN_SILENT_EXEC_FAILURE` * that correspond to the members .no_stdin, .git_cmd, * .stdout_to_stderr, .silent_exec_failure of `struct child_process`. - * The argument dir corresponds the member .dir. The argument env - * corresponds to the member .env. */ int run_command_v_opt(const char **argv, int opt); -/* - * env (the environment) is to be formatted like environ: "VAR=VALUE". - * To unset an environment variable use just "VAR". - */ -int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, - const char *const *env, const char *tr2_class); /** * Execute the given command, sending "in" to its stdin, and capturing its From patchwork Sun Oct 30 11:55:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13025082 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 54EF7C38A02 for ; Sun, 30 Oct 2022 11:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbiJ3LzS (ORCPT ); Sun, 30 Oct 2022 07:55:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiJ3LzQ (ORCPT ); Sun, 30 Oct 2022 07:55:16 -0400 Received: from mout.web.de (mout.web.de [212.227.15.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 988ABBF63 for ; Sun, 30 Oct 2022 04:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1667130907; bh=LnbE6Om4mcxPaf3PE8ovErtbUYaLFVHrvTuJwnmX12Q=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=JYW0bwthBsKZY3hpXPty362rOS4jTQC1UEVGYdPFRYExAymOLahJdHnLfRVuFBrf3 2DBC8Joxz+olczAT9s1tfDllH8f8hXB6GxMzQsgDKJ50XQa9YcGQJlxjUmh0XoGwqH EhclnT3qYpIeIHMMm4DzwmWj3tJb8zQDgSwLRdein6DN+s0GhT4KxSRSDTvxNZK2pj yq1qtdUkBvEWcTD8nsMrjuoWj7qHoSrPBVJt9e8ZwS/t8+/tPQArvshSZQq9s1gGv2 GMnu0MvdiRdzU0ezjGyw7K2ebEySMHukSP+Nlf/JTNXVK6RgXb/6MBw2XCBBg8wNS8 TZ+A1i0pE7oDA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.23.191]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1M1rTQ-1omv2o40Xg-002DsB; Sun, 30 Oct 2022 12:55:07 +0100 Message-ID: <0c13812c-dcb6-7319-4b41-ccba3f27a5fd@web.de> Date: Sun, 30 Oct 2022 12:55:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v2 12/12] replace and remove run_command_v_opt() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Taylor Blau , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <7407e074-4bd8-b351-7fa4-baf59b41880c@web.de> In-Reply-To: X-Provags-ID: V03:K1:47GRYJweGAtJL+otSY6gcfzrgwXIV46MeHT/RtBZRSk0yOiY8yx NOrXCQ6rzgjqkLXNHqUruyuaEVdgCtLVGsg5g3czU3DYLsKSL70ZmMXPnHkI/LLC45X5Eoj WI926ifeMf8YyfhuSeIlBwuMvM6aq5MsMrS0uLVR6L9GUmaWaEfekWGFTKhbcgLUv2tHdf8 cpwIBSLgUIs2LvzAMNCOg== UI-OutboundReport: notjunk:1;M01:P0:Xxgvo6PUsyo=;7y3+FrHDxFMHzCuIVn6oJl8pHPt 8F/P0zdqebFY2Fdlp18RWyMfImMNGt2lW1zreXle4r36EOiwgfH+lNrnBTZCpsdKqG4qlCAI+ /SNsr5InXr7JgliskQfnOTnr3nWhTLa+Pe1n4VVieexlri9/c33o53rePPPTqrAit5Y6dvVc6 oKNioKX7eyHWHvtzzYRQJTNcSQnY/XMJp2OLG/m3OgyUak+FVky7Y23+ueiWE2eu2hYOgE6H9 GIIfma7+LTR/aCJX24xV4kMjIB61GBXqqln4sNNPoEHjtRFe8FRgaeIjk6XYFvd8TiYRPnSfI jxBNZe48XQp3mA1CpMD+tqI0ldG2daINT1aRRJCw/KjYNYPLP8Jf8eiabtpa9o8KEmMSgbQLa 7g+dOUIbGcbq45zQNKUHHJfvvLwVMSFemB3MIeKi+IqEtdPjtXE9hkMCIW8k3JLXChYWl6iyq avqVKHvMawi2P1g889G2U5hklheaDbOUsTNrWP8SXj7vmYqNb7HKWbu+KhfaDMmTCKVMAKTeQ O4jGlb67ydURwGZ0F0jSu1t8RAF152XHExy8vXfrJNbrIAsGXLp6Ij8QFqE+qzHUlcayWFK+S LVDKisE4AiOzN1nbEqSMe9ET9CJdp+4fSihpxXFTjrjpIKGGy6rHad63WAF2dnih3Sva6K/0E QZroLnWTmaaLdXKnTGvxO28JbApdR3ZxZxe6pdWgjmIGzkbOKDHpoZt3b0T0SIdy3WTWdCbaJ 6E+AJw/AOj7n5+cuN3DtdmthJ9aaIQqUjoWwIQZtovi4c0LxzzNfYD/97DeKLLFr+5ZZaNr2Q HqROs4PGZCzuNdkm4w6m2qX6W5l8ccPtCf6CYL9jK+rgjR5nLVIlCRnjbZ79rZbQsAmwZs8rg UDu8fRs8N4XU7Gfw5td2c4GQHExNdIWp53Iaqqv6R7WN/Fy+VjynY2oBKXbktALM+38SupHlA 2DQXkJ7DIQmayYGNF/1MDg0CW0E= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Replace the remaining calls of run_command_v_opt() with run_command() calls and explict struct child_process variables. This is more verbose, but not by much overall. The code becomes more flexible, e.g. it's easy to extend to conditionally add a new argument. Then remove the now unused function and its own flag names, simplifying the run-command API. Suggested-by: Jeff King Signed-off-by: René Scharfe --- bisect.c | 9 +++++---- builtin/am.c | 9 +++++---- builtin/bisect--helper.c | 15 ++++++++++----- builtin/clone.c | 8 ++++++-- builtin/difftool.c | 7 +++++-- builtin/fetch.c | 9 ++++++--- builtin/gc.c | 41 +++++++++++++++++++++++++++++++--------- builtin/merge-index.c | 4 +++- run-command.c | 15 --------------- run-command.h | 23 +--------------------- sequencer.c | 6 ++++-- shell.c | 17 ++++++++++++----- t/helper/test-trace2.c | 4 +++- 13 files changed, 92 insertions(+), 75 deletions(-) -- 2.38.1 diff --git a/bisect.c b/bisect.c index 090aa5c4b4..ec7487e683 100644 --- a/bisect.c +++ b/bisect.c @@ -737,11 +737,12 @@ enum bisect_error bisect_checkout(const struct object_id *bisect_rev, update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); } else { - const char *argv_checkout[] = { - "checkout", "-q", oid_to_hex(bisect_rev), "--", NULL - }; + struct child_process cmd = CHILD_PROCESS_INIT; - if (run_command_v_opt(argv_checkout, RUN_GIT_CMD)) + cmd.git_cmd = 1; + strvec_pushl(&cmd.args, "checkout", "-q", + oid_to_hex(bisect_rev), "--", NULL); + if (run_command(&cmd)) /* * Errors in `run_command()` itself, signaled by res < 0, * and errors in the child process, signaled by res > 0 diff --git a/builtin/am.c b/builtin/am.c index 5781e7a95e..20aea0d248 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2187,11 +2187,12 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode) int len; if (!is_null_oid(&state->orig_commit)) { - const char *av[] = { - "show", oid_to_hex(&state->orig_commit), "--", NULL - }; + struct child_process cmd = CHILD_PROCESS_INIT; - return run_command_v_opt(av, RUN_GIT_CMD); + strvec_pushl(&cmd.args, "show", oid_to_hex(&state->orig_commit), + "--", NULL); + cmd.git_cmd = 1; + return run_command(&cmd); } switch (sub_mode) { diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 5c63ba6994..1d2ce8a0e1 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -764,10 +764,12 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, const char **a strbuf_read_file(&start_head, git_path_bisect_start(), 0); strbuf_trim(&start_head); if (!no_checkout) { - const char *argv[] = { "checkout", start_head.buf, - "--", NULL }; + struct child_process cmd = CHILD_PROCESS_INIT; - if (run_command_v_opt(argv, RUN_GIT_CMD)) { + cmd.git_cmd = 1; + strvec_pushl(&cmd.args, "checkout", start_head.buf, + "--", NULL); + if (run_command(&cmd)) { res = error(_("checking out '%s' failed." " Try 'git bisect start " "'."), @@ -1141,9 +1143,12 @@ static int get_first_good(const char *refname UNUSED, static int do_bisect_run(const char *command) { - const char *argv[] = { command, NULL }; + struct child_process cmd = CHILD_PROCESS_INIT; + printf(_("running %s\n"), command); - return run_command_v_opt(argv, RUN_USING_SHELL); + cmd.use_shell = 1; + strvec_push(&cmd.args, command); + return run_command(&cmd); } static int verify_good(const struct bisect_terms *terms, const char *command) diff --git a/builtin/clone.c b/builtin/clone.c index 56e7775dae..0e4348686b 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -865,11 +865,15 @@ static void write_refspec_config(const char *src_ref_prefix, static void dissociate_from_references(void) { - static const char* argv[] = { "repack", "-a", "-d", NULL }; char *alternates = git_pathdup("objects/info/alternates"); if (!access(alternates, F_OK)) { - if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN)) + struct child_process cmd = CHILD_PROCESS_INIT; + + cmd.git_cmd = 1; + cmd.no_stdin = 1; + strvec_pushl(&cmd.args, "repack", "-a", "-d", NULL); + if (run_command(&cmd)) die(_("cannot repack to clean up")); if (unlink(alternates) && errno != ENOENT) die_errno(_("cannot unlink temporary alternates file")); diff --git a/builtin/difftool.c b/builtin/difftool.c index 22bcc3444b..d7f08c8a7f 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -44,8 +44,11 @@ static int difftool_config(const char *var, const char *value, void *cb) static int print_tool_help(void) { - const char *argv[] = { "mergetool", "--tool-help=diff", NULL }; - return run_command_v_opt(argv, RUN_GIT_CMD); + struct child_process cmd = CHILD_PROCESS_INIT; + + cmd.git_cmd = 1; + strvec_pushl(&cmd.args, "mergetool", "--tool-help=diff", NULL); + return run_command(&cmd); } static int parse_index_info(char *p, int *mode1, int *mode2, diff --git a/builtin/fetch.c b/builtin/fetch.c index b06e454cbd..7378cafeec 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1972,14 +1972,17 @@ static int fetch_multiple(struct string_list *list, int max_children) } else for (i = 0; i < list->nr; i++) { const char *name = list->items[i].string; - strvec_push(&argv, name); + struct child_process cmd = CHILD_PROCESS_INIT; + + strvec_pushv(&cmd.args, argv.v); + strvec_push(&cmd.args, name); if (verbosity >= 0) printf(_("Fetching %s\n"), name); - if (run_command_v_opt(argv.v, RUN_GIT_CMD)) { + cmd.git_cmd = 1; + if (run_command(&cmd)) { error(_("could not fetch %s"), name); result = 1; } - strvec_pop(&argv); } strvec_clear(&argv); diff --git a/builtin/gc.c b/builtin/gc.c index a185bec813..6504c0b729 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -167,9 +167,11 @@ static void gc_config(void) struct maintenance_run_opts; static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *opts) { - const char *argv[] = { "pack-refs", "--all", "--prune", NULL }; + struct child_process cmd = CHILD_PROCESS_INIT; - return run_command_v_opt(argv, RUN_GIT_CMD); + cmd.git_cmd = 1; + strvec_pushl(&cmd.args, "pack-refs", "--all", "--prune", NULL); + return run_command(&cmd); } static int too_many_loose_objects(void) @@ -535,8 +537,14 @@ static void gc_before_repack(void) if (pack_refs && maintenance_task_pack_refs(NULL)) die(FAILED_RUN, "pack-refs"); - if (prune_reflogs && run_command_v_opt(reflog.v, RUN_GIT_CMD)) - die(FAILED_RUN, reflog.v[0]); + if (prune_reflogs) { + struct child_process cmd = CHILD_PROCESS_INIT; + + cmd.git_cmd = 1; + strvec_pushv(&cmd.args, reflog.v); + if (run_command(&cmd)) + die(FAILED_RUN, reflog.v[0]); + } } int cmd_gc(int argc, const char **argv, const char *prefix) @@ -550,6 +558,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) int daemonized = 0; int keep_largest_pack = -1; timestamp_t dummy; + struct child_process rerere_cmd = CHILD_PROCESS_INIT; struct option builtin_gc_options[] = { OPT__QUIET(&quiet, N_("suppress progress reporting")), @@ -671,11 +680,17 @@ int cmd_gc(int argc, const char **argv, const char *prefix) gc_before_repack(); if (!repository_format_precious_objects) { - if (run_command_v_opt(repack.v, - RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE)) + struct child_process repack_cmd = CHILD_PROCESS_INIT; + + repack_cmd.git_cmd = 1; + repack_cmd.close_object_store = 1; + strvec_pushv(&repack_cmd.args, repack.v); + if (run_command(&repack_cmd)) die(FAILED_RUN, repack.v[0]); if (prune_expire) { + struct child_process prune_cmd = CHILD_PROCESS_INIT; + /* run `git prune` even if using cruft packs */ strvec_push(&prune, prune_expire); if (quiet) @@ -683,18 +698,26 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (has_promisor_remote()) strvec_push(&prune, "--exclude-promisor-objects"); - if (run_command_v_opt(prune.v, RUN_GIT_CMD)) + prune_cmd.git_cmd = 1; + strvec_pushv(&prune_cmd.args, prune.v); + if (run_command(&prune_cmd)) die(FAILED_RUN, prune.v[0]); } } if (prune_worktrees_expire) { + struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT; + strvec_push(&prune_worktrees, prune_worktrees_expire); - if (run_command_v_opt(prune_worktrees.v, RUN_GIT_CMD)) + prune_worktrees_cmd.git_cmd = 1; + strvec_pushv(&prune_worktrees_cmd.args, prune_worktrees.v); + if (run_command(&prune_worktrees_cmd)) die(FAILED_RUN, prune_worktrees.v[0]); } - if (run_command_v_opt(rerere.v, RUN_GIT_CMD)) + rerere_cmd.git_cmd = 1; + strvec_pushv(&rerere_cmd.args, rerere.v); + if (run_command(&rerere_cmd)) die(FAILED_RUN, rerere.v[0]); report_garbage = report_pack_garbage; diff --git a/builtin/merge-index.c b/builtin/merge-index.c index c0383fe9df..012f52bd00 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -12,6 +12,7 @@ static int merge_entry(int pos, const char *path) const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL }; char hexbuf[4][GIT_MAX_HEXSZ + 1]; char ownbuf[4][60]; + struct child_process cmd = CHILD_PROCESS_INIT; if (pos >= active_nr) die("git merge-index: %s not in the cache", path); @@ -31,7 +32,8 @@ static int merge_entry(int pos, const char *path) if (!found) die("git merge-index: %s not in the cache", path); - if (run_command_v_opt(arguments, 0)) { + strvec_pushv(&cmd.args, arguments); + if (run_command(&cmd)) { if (one_shot) err++; else { diff --git a/run-command.c b/run-command.c index f8f810d755..48b9ba6d6f 100644 --- a/run-command.c +++ b/run-command.c @@ -1004,21 +1004,6 @@ int run_command(struct child_process *cmd) return finish_command(cmd); } -int run_command_v_opt(const char **argv, int opt) -{ - struct child_process cmd = CHILD_PROCESS_INIT; - strvec_pushv(&cmd.args, argv); - cmd.no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0; - cmd.git_cmd = opt & RUN_GIT_CMD ? 1 : 0; - cmd.stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0; - cmd.silent_exec_failure = opt & RUN_SILENT_EXEC_FAILURE ? 1 : 0; - cmd.use_shell = opt & RUN_USING_SHELL ? 1 : 0; - cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0; - cmd.wait_after_clean = opt & RUN_WAIT_AFTER_CLEAN ? 1 : 0; - cmd.close_object_store = opt & RUN_CLOSE_OBJECT_STORE ? 1 : 0; - return run_command(&cmd); -} - #ifndef NO_PTHREADS static pthread_t main_thread; static int main_thread_set; diff --git a/run-command.h b/run-command.h index 4391696bf0..072db56a4d 100644 --- a/run-command.h +++ b/run-command.h @@ -150,8 +150,7 @@ struct child_process { } /** - * The functions: start_command, finish_command, run_command, - * run_command_v_opt do the following: + * The functions: start_command, finish_command, run_command do the following: * * - If a system call failed, errno is set and -1 is returned. A diagnostic * is printed. @@ -223,26 +222,6 @@ int run_command(struct child_process *); */ int run_auto_maintenance(int quiet); -#define RUN_COMMAND_NO_STDIN (1<<0) -#define RUN_GIT_CMD (1<<1) -#define RUN_COMMAND_STDOUT_TO_STDERR (1<<2) -#define RUN_SILENT_EXEC_FAILURE (1<<3) -#define RUN_USING_SHELL (1<<4) -#define RUN_CLEAN_ON_EXIT (1<<5) -#define RUN_WAIT_AFTER_CLEAN (1<<6) -#define RUN_CLOSE_OBJECT_STORE (1<<7) - -/** - * Convenience function that encapsulates a sequence of - * start_command() followed by finish_command(). The argument argv - * specifies the program and its arguments. The argument opt is zero - * or more of the flags `RUN_COMMAND_NO_STDIN`, `RUN_GIT_CMD`, - * `RUN_COMMAND_STDOUT_TO_STDERR`, or `RUN_SILENT_EXEC_FAILURE` - * that correspond to the members .no_stdin, .git_cmd, - * .stdout_to_stderr, .silent_exec_failure of `struct child_process`. - */ -int run_command_v_opt(const char **argv, int opt); - /** * Execute the given command, sending "in" to its stdin, and capturing its * stdout and stderr in the "out" and "err" strbufs. Any of the three may diff --git a/sequencer.c b/sequencer.c index 31e24f38f8..643744fb9b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3555,11 +3555,13 @@ static int error_failed_squash(struct repository *r, static int do_exec(struct repository *r, const char *command_line) { - const char *child_argv[] = { command_line, NULL }; + struct child_process cmd = CHILD_PROCESS_INIT; int dirty, status; fprintf(stderr, _("Executing: %s\n"), command_line); - status = run_command_v_opt(child_argv, RUN_USING_SHELL); + cmd.use_shell = 1; + strvec_push(&cmd.args, command_line); + status = run_command(&cmd); /* force re-reading of the cache */ if (discard_index(r->index) < 0 || repo_read_index(r) < 0) diff --git a/shell.c b/shell.c index 7ff4109db7..af0d7c734f 100644 --- a/shell.c +++ b/shell.c @@ -52,21 +52,24 @@ static void cd_to_homedir(void) static void run_shell(void) { int done = 0; - static const char *help_argv[] = { HELP_COMMAND, NULL }; + struct child_process help_cmd = CHILD_PROCESS_INIT; if (!access(NOLOGIN_COMMAND, F_OK)) { /* Interactive login disabled. */ - const char *argv[] = { NOLOGIN_COMMAND, NULL }; + struct child_process nologin_cmd = CHILD_PROCESS_INIT; int status; - status = run_command_v_opt(argv, 0); + strvec_push(&nologin_cmd.args, NOLOGIN_COMMAND); + status = run_command(&nologin_cmd); if (status < 0) exit(127); exit(status); } /* Print help if enabled */ - run_command_v_opt(help_argv, RUN_SILENT_EXEC_FAILURE); + help_cmd.silent_exec_failure = 1; + strvec_push(&help_cmd.args, HELP_COMMAND); + run_command(&help_cmd); do { const char *prog; @@ -125,9 +128,13 @@ static void run_shell(void) !strcmp(prog, "exit") || !strcmp(prog, "bye")) { done = 1; } else if (is_valid_cmd_name(prog)) { + struct child_process cmd = CHILD_PROCESS_INIT; + full_cmd = make_cmd(prog); argv[0] = full_cmd; - code = run_command_v_opt(argv, RUN_SILENT_EXEC_FAILURE); + cmd.silent_exec_failure = 1; + strvec_pushv(&cmd.args, argv); + code = run_command(&cmd); if (code == -1 && errno == ENOENT) { fprintf(stderr, "unrecognized command '%s'\n", prog); } diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index a714130ece..94fd8ccf51 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -132,6 +132,7 @@ static int ut_003error(int argc, const char **argv) */ static int ut_004child(int argc, const char **argv) { + struct child_process cmd = CHILD_PROCESS_INIT; int result; /* @@ -141,7 +142,8 @@ static int ut_004child(int argc, const char **argv) if (!argc) return 0; - result = run_command_v_opt(argv, 0); + strvec_pushv(&cmd.args, argv); + result = run_command(&cmd); exit(result); }