Skip to content

Commit b4c7aab

Browse files
peffgitster
authored andcommitted
difftool: prepare "diff" cmdline in cmd_difftool()
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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec3cc27 commit b4c7aab

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

builtin/difftool.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ static int checkout_path(unsigned mode, struct object_id *oid,
331331
}
332332

333333
static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
334-
int argc, const char **argv,
335334
struct child_process *child)
336335
{
337336
char tmpdir[PATH_MAX];
@@ -393,10 +392,6 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
393392
child->clean_on_exit = 1;
394393
child->dir = prefix;
395394
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]);
400395
if (start_command(child))
401396
die("could not obtain raw diff");
402397
fp = xfdopen(child->out, "r");
@@ -683,7 +678,6 @@ static int run_file_diff(int prompt, const char *prefix,
683678
env[2] = "GIT_DIFFTOOL_NO_PROMPT=true";
684679

685680

686-
strvec_push(&args, "diff");
687681
for (i = 0; i < argc; i++)
688682
strvec_push(&args, argv[i]);
689683
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)
769763
* will invoke a separate instance of 'git-difftool--helper' for
770764
* each file that changed.
771765
*/
766+
strvec_push(&child.args, "diff");
767+
if (dir_diff)
768+
strvec_pushl(&child.args, "--raw", "--no-abbrev", "-z", NULL);
769+
strvec_pushv(&child.args, argv);
770+
772771
if (dir_diff)
773-
return run_dir_diff(extcmd, symlinks, prefix, argc, argv, &child);
774-
return run_file_diff(prompt, prefix, argc, argv);
772+
return run_dir_diff(extcmd, symlinks, prefix, &child);
773+
return run_file_diff(prompt, prefix, child.args.nr, child.args.v);
775774
}

0 commit comments

Comments
 (0)