difftool: prepare "struct child_process" in cmd_difftool()

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 13, 2021 at 05:35 UTC ec3cc27ab06c0b7ebaf9aee3eaa6e35719eef8da
1 file changed +15 -14
builtin/difftool.c
+15 -14
@@ -331,7 +331,8 @@ static int checkout_path(unsigned mode, struct object_id *oid,
331 }
332
333 static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
334 - int argc, const char **argv)
334 + int argc, const char **argv,
335 + struct child_process *child)
336 {
337 char tmpdir[PATH_MAX];
338 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,
353 struct index_state wtindex;
354 struct checkout lstate, rstate;
355 int rc, flags = RUN_GIT_CMD, err = 0;
355 - struct child_process child = CHILD_PROCESS_INIT;
356 const char *helper_argv[] = { "difftool--helper", NULL, NULL, NULL };
357 struct hashmap wt_modified, tmp_modified;
358 int indices_loaded = 0;
@@ -387,19 +387,19 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
387 rdir_len = rdir.len;
388 wtdir_len = wtdir.len;
389
390 - child.no_stdin = 1;
391 - child.git_cmd = 1;
392 - child.use_shell = 0;
393 - child.clean_on_exit = 1;
394 - child.dir = prefix;
395 - child.out = -1;
396 - strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z",
390 + child->no_stdin = 1;
391 + child->git_cmd = 1;
392 + child->use_shell = 0;
393 + child->clean_on_exit = 1;
394 + child->dir = prefix;
395 + child->out = -1;
396 + strvec_pushl(&child->args, "diff", "--raw", "--no-abbrev", "-z",
397 NULL);
398 for (i = 0; i < argc; i++)
399 - strvec_push(&child.args, argv[i]);
400 - if (start_command(&child))
399 + strvec_push(&child->args, argv[i]);
400 + if (start_command(child))
401 die("could not obtain raw diff");
402 - fp = xfdopen(child.out, "r");
402 + fp = xfdopen(child->out, "r");
403
404 /* Build index info for left and right sides of the diff */
405 i = 0;
@@ -525,7 +525,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
525
526 fclose(fp);
527 fp = NULL;
528 - if (finish_command(&child)) {
528 + if (finish_command(child)) {
529 ret = error("error occurred running diff --raw");
530 goto finish;
531 }
@@ -719,6 +719,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
719 OPT_ARGUMENT("no-index", &no_index, N_("passed to `diff`")),
720 OPT_END()
721 };
722 + struct child_process child = CHILD_PROCESS_INIT;
723
724 git_config(difftool_config, NULL);
725 symlinks = has_symlinks;
@@ -769,6 +770,6 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
770 * each file that changed.
771 */
772 if (dir_diff)
772 - return run_dir_diff(extcmd, symlinks, prefix, argc, argv);
773 + return run_dir_diff(extcmd, symlinks, prefix, argc, argv, &child);
774 return run_file_diff(prompt, prefix, argc, argv);
775 }