merge-recursive: Create function for merging with branchname:file markers
We want to be able to reuse the code to do a three-way file content merge and have the conflict markers use both branchname and filename. Split it out into a separate function. 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
dac4741554e7672e69d1bc6b4f912cd16ad83b38
1 file changed
+33
-9
merge-recursive.c
+33
-9
@@ -942,6 +942,36 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
942
return result;
943
}
944
945
+static struct merge_file_info
946
+merge_file_special_markers(struct merge_options *o,
947
+ const struct diff_filespec *one,
948
+ const struct diff_filespec *a,
949
+ const struct diff_filespec *b,
950
+ const char *branch1,
951
+ const char *filename1,
952
+ const char *branch2,
953
+ const char *filename2)
954
+{
955
+ char *side1 = NULL;
956
+ char *side2 = NULL;
957
+ struct merge_file_info mfi;
958
+
959
+ if (filename1) {
960
+ side1 = xmalloc(strlen(branch1) + strlen(filename1) + 2);
961
+ sprintf(side1, "%s:%s", branch1, filename1);
962
+ }
963
+ if (filename2) {
964
+ side2 = xmalloc(strlen(branch2) + strlen(filename2) + 2);
965
+ sprintf(side2, "%s:%s", branch2, filename2);
966
+ }
967
+
968
+ mfi = merge_file_1(o, one, a, b,
969
+ side1 ? side1 : branch1, side2 ? side2 : branch2);
970
+ free(side1);
971
+ free(side2);
972
+ return mfi;
973
+}
974
+
975
static struct merge_file_info merge_file(struct merge_options *o,
976
const char *path,
977
const unsigned char *o_sha, int o_mode,
@@ -1415,7 +1445,6 @@ static int merge_content(struct merge_options *o,
1445
struct rename_conflict_info *rename_conflict_info)
1446
{
1447
const char *reason = "content";
1418
- char *side1 = NULL, *side2 = NULL;
1448
const char *path1 = NULL, *path2 = NULL;
1449
struct merge_file_info mfi;
1450
struct diff_filespec one, a, b;
@@ -1445,18 +1474,13 @@ static int merge_content(struct merge_options *o,
1474
path2 = (rename_conflict_info->pair2 ||
1475
o->branch2 == rename_conflict_info->branch1) ?
1476
pair1->two->path : pair1->one->path;
1448
- side1 = xmalloc(strlen(o->branch1) + strlen(path1) + 2);
1449
- side2 = xmalloc(strlen(o->branch2) + strlen(path2) + 2);
1450
- sprintf(side1, "%s:%s", o->branch1, path1);
1451
- sprintf(side2, "%s:%s", o->branch2, path2);
1477
1478
if (dir_in_way(path, !o->call_depth))
1479
df_conflict_remains = 1;
1480
}
1456
- mfi = merge_file_1(o, &one, &a, &b,
1457
- side1 ? side1 : o->branch1, side2 ? side2 : o->branch2);
1458
- free(side1);
1459
- free(side2);
1481
+ mfi = merge_file_special_markers(o, &one, &a, &b,
1482
+ o->branch1, path1,
1483
+ o->branch2, path2);
1484
1485
if (mfi.clean && !df_conflict_remains &&
1486
sha_eq(mfi.sha, a_sha) && mfi.mode == a_mode) {