Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit f3efe78

Browse files
peffgitster
authored andcommitted
run_external_diff: refactor cmdline setup logic
The current logic makes it hard to see what gets put onto the command line in which cases. Pulling out a helper function lets us see that we have two sets of file data, and the second set either uses the original name, or the "other" renamed/copy name. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d4217d commit f3efe78

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

diff.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,16 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
28922892
return temp;
28932893
}
28942894

2895+
static void add_external_diff_name(struct argv_array *argv,
2896+
const char *name,
2897+
struct diff_filespec *df)
2898+
{
2899+
struct diff_tempfile *temp = prepare_temp_file(name, df);
2900+
argv_array_push(argv, temp->name);
2901+
argv_array_push(argv, temp->hex);
2902+
argv_array_push(argv, temp->mode);
2903+
}
2904+
28952905
/* An external diff command takes:
28962906
*
28972907
* diff-cmd name infile1 infile1-sha1 infile1-mode \
@@ -2915,17 +2925,11 @@ static void run_external_diff(const char *pgm,
29152925
argv_array_push(&argv, name);
29162926

29172927
if (one && two) {
2918-
struct diff_tempfile *temp_one, *temp_two;
2919-
const char *othername = (other ? other : name);
2920-
temp_one = prepare_temp_file(name, one);
2921-
temp_two = prepare_temp_file(othername, two);
2922-
argv_array_push(&argv, temp_one->name);
2923-
argv_array_push(&argv, temp_one->hex);
2924-
argv_array_push(&argv, temp_one->mode);
2925-
argv_array_push(&argv, temp_two->name);
2926-
argv_array_push(&argv, temp_two->hex);
2927-
argv_array_push(&argv, temp_two->mode);
2928-
if (other) {
2928+
add_external_diff_name(&argv, name, one);
2929+
if (!other)
2930+
add_external_diff_name(&argv, name, two);
2931+
else {
2932+
add_external_diff_name(&argv, other, two);
29292933
argv_array_push(&argv, other);
29302934
argv_array_push(&argv, xfrm_msg);
29312935
}

0 commit comments

Comments
 (0)