All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Jeff King" <peff@peff.net>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 2/4] difftool: prepare "diff" cmdline in cmd_difftool()
Date: Mon, 13 Sep 2021 05:35:38 +0200	[thread overview]
Message-ID: <patch-v2-2.4-1c2794115c7-20210913T033204Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-0.4-00000000000-20210913T033204Z-avarab@gmail.com>

From: Jeff King <peff@peff.net>

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 <peff@peff.net>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 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);
 }
-- 
2.33.0.999.ga5f89b684e9


  parent reply	other threads:[~2021-09-13  3:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 18:21 [PATCH 0/2] parse-options.c: remove OPT_ARGUMENT Ævar Arnfjörð Bjarmason
2021-09-11 18:21 ` [PATCH 1/2] difftool: use "struct strvec" API in run_{dir,file}_diff() Ævar Arnfjörð Bjarmason
2021-09-12 22:39   ` Jeff King
2021-09-12 22:41     ` Jeff King
2021-09-13  0:10     ` Junio C Hamano
2021-09-11 18:21 ` [PATCH 2/2] parse-options API: remove OPTION_ARGUMENT feature Ævar Arnfjörð Bjarmason
2021-09-12 22:43   ` Jeff King
2021-09-13  3:35 ` [PATCH v2 0/4] difftool refactoring + remove OPT_ARGUMENT() macro Ævar Arnfjörð Bjarmason
2021-09-13  3:35   ` [PATCH v2 1/4] difftool: prepare "struct child_process" in cmd_difftool() Ævar Arnfjörð Bjarmason
2021-09-13  3:35   ` Ævar Arnfjörð Bjarmason [this message]
2021-09-13  3:35   ` [PATCH v2 3/4] difftool: use run_command() API in run_file_diff() Ævar Arnfjörð Bjarmason
2021-09-13 18:04     ` Jeff King
2021-09-13 19:13       ` Ævar Arnfjörð Bjarmason
2021-09-13 19:27         ` Jeff King
2021-09-13  3:35   ` [PATCH v2 4/4] parse-options API: remove OPTION_ARGUMENT feature Ævar Arnfjörð Bjarmason
2021-09-13  6:27     ` Junio C Hamano
2021-09-13 18:04   ` [PATCH v2 0/4] difftool refactoring + remove OPT_ARGUMENT() macro Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-v2-2.4-1c2794115c7-20210913T033204Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.