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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Apr 19, 2014 at 15:22 UTC
f3efe78782b36d68dc71a4f48a7bd3381c6b5669
1 file changed
+15
-11
diff.c
+15
-11
@@ -2892,6 +2892,16 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2892
return temp;
2893
}
2894
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
+
2905
/* An external diff command takes:
2906
*
2907
* diff-cmd name infile1 infile1-sha1 infile1-mode \
@@ -2915,17 +2925,11 @@ static void run_external_diff(const char *pgm,
2925
argv_array_push(&argv, name);
2926
2927
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);
2933
argv_array_push(&argv, other);
2934
argv_array_push(&argv, xfrm_msg);
2935
}