From patchwork Mon Sep 13 03:35:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12487821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 585F9C433F5 for ; Mon, 13 Sep 2021 03:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3368560F6D for ; Mon, 13 Sep 2021 03:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238443AbhIMDq6 (ORCPT ); Sun, 12 Sep 2021 23:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235475AbhIMDq4 (ORCPT ); Sun, 12 Sep 2021 23:46:56 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAF30C061574 for ; Sun, 12 Sep 2021 20:45:40 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id m9so12367772wrb.1 for ; Sun, 12 Sep 2021 20:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7dm3dW3T1dZXmNkSAf2F7eqEB3ZH1aj6jR+HCuIkobU=; b=ZokyLigoNsb//ZhfFw7JTI3vmszy4ddCAbgNe9g+iKWzSt0VVMJx6FqHPNsH/GtBhU fSBcc5mn4vSoYxQ/4GfMmesi7jfl9+VyWCPMuNyJGhcQQlZulA1AflOy59PiEWb9drJd 5frHI3AUo3R1knXz9QhLfSJICeX38OMvrbulRTwvrSIvLPR6r0c4psDVs88uT6mCMJHh FF7hZLEWVkc/yD6lXCvp1KLSfN9Lekgso4tqOd8npkAimrhuwVprBaKb0NafVQ4kkVBX crSnRW3qjLvzS49KIEfM4ViMjrDXfkdcdg35smkzK7HFwViN4nkYm32lZ0bRUd8lrbyb ra9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7dm3dW3T1dZXmNkSAf2F7eqEB3ZH1aj6jR+HCuIkobU=; b=AU53wQgHneusadVX51yjHZ/XGVGDmDUkrtptUm1hA+VZPTrf/eQWXvhZudq+9zDF/R ExI66A5iTmWmJedRP+DMCvxHHJCMC/KB8rKRUxHkBsdwzxdSw5XYdFCHgWuy6qaPidjB Ws+vDo6/lWWLurwIYS2BfberXznUDKfsihy+7WvTHcf5e7pr7RGwmoDTnLOzHcBlLCHW cGcWYjqfLvMOu2OizSugoFHYzv2FduIEPCxzDwnMQucw+SUR/kVuWD5Dn7cfKxtCPyf/ ULY2f/E/CTiKeFSPs1C6Szgj2Ed12PkN3TelUqLTzAtKPuvSSCPIi60y05WdELtGwFts Qj/w== X-Gm-Message-State: AOAM531fs8uhi+nFIjDc6cnE9cmFNoOTgt7R0sF3m10bgdcJEoUppxDt 1zjgZLuCPtqS/LWJ0APUOjAqKK2wr5zveg== X-Google-Smtp-Source: ABdhPJy7PLob0UQnyxMjp469kbaIafCRBPRU8dRvXSASftrL21Iu+krzEDYN4TPtgWKc34qElVAb8A== X-Received: by 2002:adf:d193:: with SMTP id v19mr10335956wrc.377.1631504739319; Sun, 12 Sep 2021 20:45:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o10sm6631472wrc.16.2021.09.12.20.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 20:45:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/4] difftool: prepare "struct child_process" in cmd_difftool() Date: Mon, 13 Sep 2021 05:35:37 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.999.ga5f89b684e9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the preparation of the "struct child_process" from run_dir_diff() to its only caller, cmd_difftool(). This is in preparation for migrating run_file_diff() to using the run_command() API directly, and to move more of the shared setup of the two to cmd_difftool(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/difftool.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index 6a9242a8032..9f08a8f3fd2 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -331,7 +331,8 @@ static int checkout_path(unsigned mode, struct object_id *oid, } static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, - int argc, const char **argv) + int argc, const char **argv, + struct child_process *child) { char tmpdir[PATH_MAX]; struct strbuf info = STRBUF_INIT, lpath = STRBUF_INIT; @@ -352,7 +353,6 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, struct index_state wtindex; struct checkout lstate, rstate; int rc, flags = RUN_GIT_CMD, err = 0; - struct child_process child = CHILD_PROCESS_INIT; const char *helper_argv[] = { "difftool--helper", NULL, NULL, NULL }; struct hashmap wt_modified, tmp_modified; int indices_loaded = 0; @@ -387,19 +387,19 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, rdir_len = rdir.len; wtdir_len = wtdir.len; - child.no_stdin = 1; - child.git_cmd = 1; - child.use_shell = 0; - child.clean_on_exit = 1; - child.dir = prefix; - child.out = -1; - strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z", + child->no_stdin = 1; + child->git_cmd = 1; + child->use_shell = 0; + child->clean_on_exit = 1; + child->dir = prefix; + child->out = -1; + strvec_pushl(&child->args, "diff", "--raw", "--no-abbrev", "-z", NULL); for (i = 0; i < argc; i++) - strvec_push(&child.args, argv[i]); - if (start_command(&child)) + strvec_push(&child->args, argv[i]); + if (start_command(child)) die("could not obtain raw diff"); - fp = xfdopen(child.out, "r"); + fp = xfdopen(child->out, "r"); /* Build index info for left and right sides of the diff */ i = 0; @@ -525,7 +525,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, fclose(fp); fp = NULL; - if (finish_command(&child)) { + if (finish_command(child)) { ret = error("error occurred running diff --raw"); goto finish; } @@ -719,6 +719,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) OPT_ARGUMENT("no-index", &no_index, N_("passed to `diff`")), OPT_END() }; + struct child_process child = CHILD_PROCESS_INIT; git_config(difftool_config, NULL); symlinks = has_symlinks; @@ -769,6 +770,6 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) * each file that changed. */ if (dir_diff) - return run_dir_diff(extcmd, symlinks, prefix, argc, argv); + return run_dir_diff(extcmd, symlinks, prefix, argc, argv, &child); return run_file_diff(prompt, prefix, argc, argv); } From patchwork Mon Sep 13 03:35:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12487819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6323DC433EF for ; Mon, 13 Sep 2021 03:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 435F361027 for ; Mon, 13 Sep 2021 03:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238527AbhIMDq6 (ORCPT ); Sun, 12 Sep 2021 23:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238423AbhIMDq5 (ORCPT ); Sun, 12 Sep 2021 23:46:57 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C585BC061574 for ; Sun, 12 Sep 2021 20:45:41 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso5853267wmb.2 for ; Sun, 12 Sep 2021 20:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9eY7hWSNSEDzM9zTx+6Te8+LTHa2wP+SVnhxSnSDFJc=; b=Wz3Av+WdpSYAxEpJXAhuvtTvwpp9qDpDR6c/zuwPPbmCWvlORrTh6cLs+LlnA4S8RT t2CvcL1Et1x4pdWW8xwyoXQoaPQkVkTjStDyjlQjE0T5rUDencq2bN4wcDG9UqV84JFM GjJ+M1BKbEU3AC/UvQIfw9FRvfy276kc+KdQ2pPhsqR6oV0efP4C/3eX9seQFl5Jh2jc 1gGbFZZNyHDQ061BC13FfJO5nBdAKolVzZg58egmlzYCJLSvWQojUiqZeN60sZ6RrnKa mg6Mymg1JL3SliVQP/Vs43zW2UvXSQcyzq5fHXGwcN7Vjbsqm+ofaQ1LDXGhUHGM0OYK 5YYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9eY7hWSNSEDzM9zTx+6Te8+LTHa2wP+SVnhxSnSDFJc=; b=sKm9T9kfBRIWYposkDjU17VUyq7lUis9dYZGBcAnMqEknbC66iB1/57caisl1ZYakM Wbe+6AuRqu41teLAPKEA2qk3Nj9NTSQOiJxw1Nbw9Pc16qF8gpTVxKCfsOCDtPc88NJk FMgWbTyXxTVy0zn5rK9NRY+Rq5BLYcXXsOHe9VCuQky8ruP2eQPNyFXjArVGVVySZ873 1sPrB0VsSTZ3o9fBcCrH320+Wv48AbLxLYNYdtmln6oiarwLksinSVd+xWyduF9dKf11 PIcKrpOcI3AgORfh6wdCO8d++WcO4jzzb+e9hUHa9f67mxPrFVIhNsIl7vk43LmeDPQ5 dJ+g== X-Gm-Message-State: AOAM531GHDzj4YtltMotLjLirIKRxo/lnJTtB68gMmG4Hypj1MundgFx uUXRAicZ0l6r3AIPwqGqrsicVjwHZ1XXSg== X-Google-Smtp-Source: ABdhPJzfIhb3mRC1Nf6ea8q8HowaCbojzMruk9KUY73N7qqaLPR72wtCqGXxcWlwFWJYJbfT1eHYXg== X-Received: by 2002:a7b:c052:: with SMTP id u18mr9034900wmc.105.1631504740094; Sun, 12 Sep 2021 20:45:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o10sm6631472wrc.16.2021.09.12.20.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 20:45:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/4] difftool: prepare "diff" cmdline in cmd_difftool() Date: Mon, 13 Sep 2021 05:35:38 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.999.ga5f89b684e9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff King We call into either run_dir_diff() or run_file_diff(), each of which sets up a child argv starting with "diff" and some hard-coded options (depending on which mode we're using). Let's extract that logic into the caller, which will make it easier to modify the options for cases which affect both functions. Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/difftool.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index 9f08a8f3fd2..f8fcc67640f 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -331,7 +331,6 @@ static int checkout_path(unsigned mode, struct object_id *oid, } static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, - int argc, const char **argv, struct child_process *child) { char tmpdir[PATH_MAX]; @@ -393,10 +392,6 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, child->clean_on_exit = 1; child->dir = prefix; child->out = -1; - strvec_pushl(&child->args, "diff", "--raw", "--no-abbrev", "-z", - NULL); - for (i = 0; i < argc; i++) - strvec_push(&child->args, argv[i]); if (start_command(child)) die("could not obtain raw diff"); fp = xfdopen(child->out, "r"); @@ -683,7 +678,6 @@ static int run_file_diff(int prompt, const char *prefix, env[2] = "GIT_DIFFTOOL_NO_PROMPT=true"; - strvec_push(&args, "diff"); for (i = 0; i < argc; i++) strvec_push(&args, argv[i]); return run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env); @@ -769,7 +763,12 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) * will invoke a separate instance of 'git-difftool--helper' for * each file that changed. */ + strvec_push(&child.args, "diff"); + if (dir_diff) + strvec_pushl(&child.args, "--raw", "--no-abbrev", "-z", NULL); + strvec_pushv(&child.args, argv); + if (dir_diff) - return run_dir_diff(extcmd, symlinks, prefix, argc, argv, &child); - return run_file_diff(prompt, prefix, argc, argv); + return run_dir_diff(extcmd, symlinks, prefix, &child); + return run_file_diff(prompt, prefix, child.args.nr, child.args.v); } From patchwork Mon Sep 13 03:35:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12487823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AC97C4332F for ; Mon, 13 Sep 2021 03:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B5D960F6D for ; Mon, 13 Sep 2021 03:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238533AbhIMDq7 (ORCPT ); Sun, 12 Sep 2021 23:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238426AbhIMDq5 (ORCPT ); Sun, 12 Sep 2021 23:46:57 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CD8CC061574 for ; Sun, 12 Sep 2021 20:45:42 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id i3so5569270wmq.3 for ; Sun, 12 Sep 2021 20:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SY4yWdNO3Kwd9iJTgu/txS0z+qdGS47qjWvWeIzJcWg=; b=mflFJBv+yQftaRJNJIQyz+n+9wZj0OOSgeHtyITpimueG1rtzEVAALzUmdzQ/b/t8k PC5iwIhnMThQP85cWEEh3vlQ8LBGtKGZHTKWhu5SYzOdw5k8ePCELobDFYGNfeLDLMz1 z6AbzgugfaYMtXPWgQ587rOARE6UkScs8XonsBEFLEcPrfQHh9mqGOEZ2KzvVmPuU1vh kI+G5ZA7NVA8HVRre+rF6xJyS0MpJFJ6aTiEe+oi7OPxM93LIyXrCdmmTWVhxcyTsEtj 2bixLCP1v2CRRuWbwoO7ocYGRjg3ftAPVRCbMq+fs9Im7IyRYEVJe3fuoNI7WbJEGUtH JmAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SY4yWdNO3Kwd9iJTgu/txS0z+qdGS47qjWvWeIzJcWg=; b=m3TyNaeBbRClWAisTaRt6keGunbEoZrDCtAlfIP21ZgVSiHsFcnxnFLWmuITVob32t 1rA1jhkSakUgtqgT/yvT9vppR586RmQ2HWOXItOUcXmQcKjdtr4W3qqwsH15c/nI1vGV ouPHnkx9o1Vb6rmcp17wTJ6Ms8ypjrUS6sCEd4JTMUX+3GB3PYX5RL8qTpn58ibvd4+h 7quf/60Xlk2CqNP5YeIuqzvReZ8u3tocZ0+Fkl62NcPhIbUOdQuCOyPhXwtNHIECq7Fp jN9Q3tXymTuS7/sSh+DmW40y8p+mhIzct4v3VhbC/YUlwshHGaFh+Jp2cZq1MVrKYRoE ZRgQ== X-Gm-Message-State: AOAM530nAV46BmjUyXAvZZEZESq40DLYe9xl6zzVziYII6Dknf9BfajQ uddFQvcfq73LzKduALPUFbfa6iJVLuGL/w== X-Google-Smtp-Source: ABdhPJzQCdUD7c8uAnJYQzSmB9ZpEyvirl6SNp/alDueYIyNYyxakEzxFXuT4TBYPAEeXbGnXy/c9g== X-Received: by 2002:a1c:7713:: with SMTP id t19mr3467318wmi.162.1631504740960; Sun, 12 Sep 2021 20:45:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o10sm6631472wrc.16.2021.09.12.20.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 20:45:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/4] difftool: use run_command() API in run_file_diff() Date: Mon, 13 Sep 2021 05:35:39 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.999.ga5f89b684e9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the run_file_diff() function to use the run_command() API directly, instead of invoking the run_command_v_opt_cd_env() wrapper. This allows it, like run_dir_diff(), to use the "args" from "struct strvec", instead of the "const char **argv" passed into cmd_difftool(). This will be used in the subsequent commit to get rid of OPT_ARGUMENT() from cmd_difftool(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/difftool.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index f8fcc67640f..de2e5545c81 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -663,24 +663,23 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, } static int run_file_diff(int prompt, const char *prefix, - int argc, const char **argv) + struct child_process *child) { - struct strvec args = STRVEC_INIT; const char *env[] = { "GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL, NULL }; - int i; if (prompt > 0) env[2] = "GIT_DIFFTOOL_PROMPT=true"; else if (!prompt) env[2] = "GIT_DIFFTOOL_NO_PROMPT=true"; + child->git_cmd = 1; + child->dir = prefix; + strvec_pushv(&child->env_array, env); - for (i = 0; i < argc; i++) - strvec_push(&args, argv[i]); - return run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env); + return run_command(child); } int cmd_difftool(int argc, const char **argv, const char *prefix) @@ -770,5 +769,5 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) if (dir_diff) return run_dir_diff(extcmd, symlinks, prefix, &child); - return run_file_diff(prompt, prefix, child.args.nr, child.args.v); + return run_file_diff(prompt, prefix, &child); } From patchwork Mon Sep 13 03:35:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12487825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E700C433F5 for ; Mon, 13 Sep 2021 03:45:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4626660FE3 for ; Mon, 13 Sep 2021 03:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238534AbhIMDrB (ORCPT ); Sun, 12 Sep 2021 23:47:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238456AbhIMDq6 (ORCPT ); Sun, 12 Sep 2021 23:46:58 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A6F5C061574 for ; Sun, 12 Sep 2021 20:45:43 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso5538250wmi.5 for ; Sun, 12 Sep 2021 20:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vJhNIFUXNmsJ4mipmiuIU3wDYfb6vB56Fe4/OdokhGw=; b=OwX8TuRZb7Uz8gY/nJaHPOhVxPXkX9DjW1bm3/MFA5MlVcGaDYK4kfahTuIpV2ikzX SKcAPwGpvS9nJp185XWQc3Wq3xctZJ0h+5LejshbMMHDDuP2t/EluKexeZxYWwElunAb VZIjB1RshhowPjaoHs4T+fYeJkWwDUufxVhS7NJunDbaSP2T9vIxiNt50Kkmj6BiG/lJ rJShvmdfJgHu08TLvpJ/yRMd7HNfkKYMy17jYUkkHC61j5suoagAhNiLLXDGX12j8lWy YVdfaFkSm/dYnCNgO987QuQgwUDuU4UOQDKBnLY3ZChCtPC5Hpn0s28uOhtUejnxDK3n LD0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vJhNIFUXNmsJ4mipmiuIU3wDYfb6vB56Fe4/OdokhGw=; b=sTaHrexYggisLr//kSQUQRE05DJYe4POYFiSVgyyfZWL0h5eVoggihc+Qf1+sJPs7E M1HawoEvhDuXytPMUPZdL/ajsk9yl+ReRgvlPEg9x0xCLGH0JID+Zu2Fcl9sxEC4bDmy EPDt5PbwBd0M8N6QnzW4KyEoEmUn8UwoNqTiKxpzpPyyCEeln04rCAiWK+FYROUMB2vi HV/RmIFcMda/oc9RIbluntur/x82GQkrBNhb2FcV9g752/nxT2P1lIsRUrsEkesq8hgC 5RFyydwiQmM79ygYvvNLcneg+Uu8LSl799FTQb2dBF+bLF0kwdX0nIBJPiue6LnczAwh 25YQ== X-Gm-Message-State: AOAM53303nKTYo/76RssIudtoxOii1PMDlOPnIiNF4ZU+aNsc8V0f338 e+3Z1pPPrZUaB/97FZA34lwsJGzr58o84Q== X-Google-Smtp-Source: ABdhPJz9MxsMLcfgx9CvvK/oFzBeeCHdW/aW7pYKSJAQcURAvfJtTF7JqyocjNXr2RM4HMQQ9OC/IQ== X-Received: by 2002:a1c:cc03:: with SMTP id h3mr8885807wmb.73.1631504741827; Sun, 12 Sep 2021 20:45:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o10sm6631472wrc.16.2021.09.12.20.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 20:45:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 4/4] parse-options API: remove OPTION_ARGUMENT feature Date: Mon, 13 Sep 2021 05:35:40 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.999.ga5f89b684e9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As was noted in 1a85b49b87a (parse-options: make OPT_ARGUMENT() more useful, 2019-03-14) there's only ever been one user of the OPT_ARGUMENT(), that user was added in 20de316e334 (difftool: allow running outside Git worktrees with --no-index, 2019-03-14). The OPT_ARGUMENT() feature itself was added way back in 580d5bffdea (parse-options: new option type to treat an option-like parameter as an argument., 2008-03-02), but as discussed in 1a85b49b87a wasn't used until 20de316e334 in 2019. Now that the preceding commit has migrated this code over to using "struct strvec" to manage the "args" member of a "struct child_process", we can just use that directly instead of relying on OPT_ARGUMENT. This has a minor change in behavior in that if we'll pass --no-index we'll now always pass it as the first argument, before we'd pass it in whatever position the caller did. Preserving this was the real value of OPT_ARGUMENT(), but as it turns out we didn't need that either. We can always inject it as the first argument, the other end will parse it just the same. Note that we cannot remove the "out" and "cpidx" members of "struct parse_opt_ctx_t" added in 580d5bffdea, while they were introduced with OPT_ARGUMENT() we since used them for other things. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/technical/api-parse-options.txt | 5 ----- builtin/difftool.c | 4 +++- parse-options.c | 13 ------------- parse-options.h | 3 --- t/helper/test-parse-options.c | 1 - t/t0040-parse-options.sh | 5 ----- 6 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt index 5a60bbfa7f4..acfd5dc1d8b 100644 --- a/Documentation/technical/api-parse-options.txt +++ b/Documentation/technical/api-parse-options.txt @@ -198,11 +198,6 @@ There are some macros to easily define options: The filename will be prefixed by passing the filename along with the prefix argument of `parse_options()` to `prefix_filename()`. -`OPT_ARGUMENT(long, &int_var, description)`:: - Introduce a long-option argument that will be kept in `argv[]`. - If this option was seen, `int_var` will be set to one (except - if a `NULL` pointer was passed). - `OPT_NUMBER_CALLBACK(&var, description, func_ptr)`:: Recognize numerical options like -123 and feed the integer as if it was an argument to the function given by `func_ptr`. diff --git a/builtin/difftool.c b/builtin/difftool.c index de2e5545c81..bb9fe7245a4 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -709,7 +709,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) "tool returns a non - zero exit code")), OPT_STRING('x', "extcmd", &extcmd, N_("command"), N_("specify a custom command for viewing diffs")), - OPT_ARGUMENT("no-index", &no_index, N_("passed to `diff`")), + OPT_BOOL(0, "no-index", &no_index, N_("passed to `diff`")), OPT_END() }; struct child_process child = CHILD_PROCESS_INIT; @@ -763,6 +763,8 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) * each file that changed. */ strvec_push(&child.args, "diff"); + if (no_index) + strvec_push(&child.args, "--no-index"); if (dir_diff) strvec_pushl(&child.args, "--raw", "--no-abbrev", "-z", NULL); strvec_pushv(&child.args, argv); diff --git a/parse-options.c b/parse-options.c index 2abff136a17..55c5821b08d 100644 --- a/parse-options.c +++ b/parse-options.c @@ -310,19 +310,6 @@ static enum parse_opt_result parse_long_opt( again: if (!skip_prefix(arg, long_name, &rest)) rest = NULL; - if (options->type == OPTION_ARGUMENT) { - if (!rest) - continue; - if (*rest == '=') - return error(_("%s takes no value"), - optname(options, flags)); - if (*rest) - continue; - if (options->value) - *(int *)options->value = options->defval; - p->out[p->cpidx++] = arg - 2; - return PARSE_OPT_DONE; - } if (!rest) { /* abbreviated? */ if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) && diff --git a/parse-options.h b/parse-options.h index a845a9d9527..39d90882548 100644 --- a/parse-options.h +++ b/parse-options.h @@ -8,7 +8,6 @@ enum parse_opt_type { /* special types */ OPTION_END, - OPTION_ARGUMENT, OPTION_GROUP, OPTION_NUMBER, OPTION_ALIAS, @@ -155,8 +154,6 @@ struct option { #define OPT_INTEGER_F(s, l, v, h, f) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) } #define OPT_END() { OPTION_END } -#define OPT_ARGUMENT(l, v, h) { OPTION_ARGUMENT, 0, (l), (v), NULL, \ - (h), PARSE_OPT_NOARG, NULL, 1 } #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } #define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0) #define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \ diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index 2051ce57db7..a282b6ff13e 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -134,7 +134,6 @@ int cmd__parse_options(int argc, const char **argv) OPT_NOOP_NOARG(0, "obsolete"), OPT_STRING_LIST(0, "list", &list, "str", "add str to list"), OPT_GROUP("Magic arguments"), - OPT_ARGUMENT("quux", NULL, "means --quux"), OPT_NUMBER_CALLBACK(&integer, "set integer to NUM", number_callback), { OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b", diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index ad4746d899a..da310ed29b1 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -37,7 +37,6 @@ String options --list add str to list Magic arguments - --quux means --quux -NUM set integer to NUM + same as -b --ambiguous positive ambiguity @@ -263,10 +262,6 @@ test_expect_success 'detect possible typos' ' test_cmp typo.err output.err ' -test_expect_success 'keep some options as arguments' ' - test-tool parse-options --expect="arg 00: --quux" --quux -' - cat >expect <<\EOF Callback: "four", 0 boolean: 5