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 1/4] difftool: prepare "struct child_process" in cmd_difftool()
Date: Mon, 13 Sep 2021 05:35:37 +0200 [thread overview]
Message-ID: <patch-v2-1.4-f57c6c9b069-20210913T033204Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-0.4-00000000000-20210913T033204Z-avarab@gmail.com>
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 <avarab@gmail.com>
---
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);
}
--
2.33.0.999.ga5f89b684e9
next prev 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 ` Ævar Arnfjörð Bjarmason [this message]
2021-09-13 3:35 ` [PATCH v2 2/4] difftool: prepare "diff" cmdline in cmd_difftool() Ævar Arnfjörð Bjarmason
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-v2-1.4-f57c6c9b069-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).