merge-recursive: Introduce a merge_file convenience function

merge_file previously required diff_filespec arguments, but all callers only had sha1s and modes. Rename merge_file to merge_file_1 and introduce a new merge_file convenience function which takes the sha1s and modes and creates the temporary diff_filespec variables needed to call merge_file_1. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Aug 11, 2011 at 23:20 UTC 6bdaead1e58ab2aa3ea81a998117d1d5afb41a3b
1 file changed +37 -35
merge-recursive.c
+37 -35
@@ -844,12 +844,12 @@ static int merge_3way(struct merge_options *o,
844 return merge_status;
845 }
846
847 -static struct merge_file_info merge_file(struct merge_options *o,
848 - const struct diff_filespec *one,
849 - const struct diff_filespec *a,
850 - const struct diff_filespec *b,
851 - const char *branch1,
852 - const char *branch2)
847 +static struct merge_file_info merge_file_1(struct merge_options *o,
848 + const struct diff_filespec *one,
849 + const struct diff_filespec *a,
850 + const struct diff_filespec *b,
851 + const char *branch1,
852 + const char *branch2)
853 {
854 struct merge_file_info result;
855 result.merge = 0;
@@ -918,6 +918,26 @@ static struct merge_file_info merge_file(struct merge_options *o,
918 return result;
919 }
920
921 +static struct merge_file_info merge_file(struct merge_options *o,
922 + const char *path,
923 + const unsigned char *o_sha, int o_mode,
924 + const unsigned char *a_sha, int a_mode,
925 + const unsigned char *b_sha, int b_mode,
926 + const char *branch1,
927 + const char *branch2)
928 +{
929 + struct diff_filespec one, a, b;
930 +
931 + one.path = a.path = b.path = (char *)path;
932 + hashcpy(one.sha1, o_sha);
933 + one.mode = o_mode;
934 + hashcpy(a.sha1, a_sha);
935 + a.mode = a_mode;
936 + hashcpy(b.sha1, b_sha);
937 + b.mode = b_mode;
938 + return merge_file_1(o, &one, &a, &b, branch1, branch2);
939 +}
940 +
941 static void conflict_rename_delete(struct merge_options *o,
942 struct diff_filepair *pair,
943 const char *rename_branch,
@@ -1015,16 +1035,10 @@ static void conflict_rename_rename_2to1(struct merge_options *o,
1035 /* Two files were renamed to the same thing. */
1036 if (o->call_depth) {
1037 struct merge_file_info mfi;
1018 - struct diff_filespec one, a, b;
1019 -
1020 - one.path = a.path = b.path = path;
1021 - hashcpy(one.sha1, null_sha1);
1022 - one.mode = 0;
1023 - hashcpy(a.sha1, ren1->pair->two->sha1);
1024 - a.mode = ren1->pair->two->mode;
1025 - hashcpy(b.sha1, ren2->pair->two->sha1);
1026 - b.mode = ren2->pair->two->mode;
1027 - mfi = merge_file(o, &one, &a, &b, branch1, branch2);
1038 + mfi = merge_file(o, path, null_sha1, 0,
1039 + ren1->pair->two->sha1, ren1->pair->two->mode,
1040 + ren2->pair->two->sha1, ren2->pair->two->mode,
1041 + branch1, branch2);
1042 output(o, 1, "Adding merged %s", path);
1043 update_file(o, 0, mfi.sha, mfi.mode, path);
1044 } else {
@@ -1211,24 +1225,12 @@ static int process_renames(struct merge_options *o,
1225 ren1_dst, branch2);
1226 if (o->call_depth) {
1227 struct merge_file_info mfi;
1214 - struct diff_filespec one, a, b;
1215 -
1216 - one.path = a.path = b.path =
1217 - (char *)ren1_dst;
1218 - hashcpy(one.sha1, null_sha1);
1219 - one.mode = 0;
1220 - hashcpy(a.sha1, ren1->pair->two->sha1);
1221 - a.mode = ren1->pair->two->mode;
1222 - hashcpy(b.sha1, dst_other.sha1);
1223 - b.mode = dst_other.mode;
1224 - mfi = merge_file(o, &one, &a, &b,
1225 - branch1,
1226 - branch2);
1228 + mfi = merge_file(o, ren1_dst, null_sha1, 0,
1229 + ren1->pair->two->sha1, ren1->pair->two->mode,
1230 + dst_other.sha1, dst_other.mode,
1231 + branch1, branch2);
1232 output(o, 1, "Adding merged %s", ren1_dst);
1228 - update_file(o, 0,
1229 - mfi.sha,
1230 - mfi.mode,
1231 - ren1_dst);
1233 + update_file(o, 0, mfi.sha, mfi.mode, ren1_dst);
1234 try_merge = 0;
1235 } else {
1236 char *new_path = unique_path(o, ren1_dst, branch2);
@@ -1406,8 +1408,8 @@ static int merge_content(struct merge_options *o,
1408 if (dir_in_way(path, !o->call_depth))
1409 df_conflict_remains = 1;
1410 }
1409 - mfi = merge_file(o, &one, &a, &b,
1410 - side1 ? side1 : o->branch1, side2 ? side2 : o->branch2);
1411 + mfi = merge_file_1(o, &one, &a, &b,
1412 + side1 ? side1 : o->branch1, side2 ? side2 : o->branch2);
1413 free(side1);
1414 free(side2);
1415