merge-recursive: Small cleanups for conflict_rename_rename_1to2

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 a99b7f2256ebd2d1db59c578f3da003e36f259c4
1 file changed +27 -33
merge-recursive.c
+27 -33
@@ -964,58 +964,55 @@ static void conflict_rename_delete(struct merge_options *o,
964 }
965
966 static void conflict_rename_rename_1to2(struct merge_options *o,
967 - struct diff_filepair *pair1,
968 - const char *branch1,
969 - struct diff_filepair *pair2,
970 - const char *branch2)
967 + struct rename_conflict_info *ci)
968 {
969 /* One file was renamed in both branches, but to different names. */
970 + struct diff_filespec *one = ci->pair1->one;
971 + struct diff_filespec *a = ci->pair1->two;
972 + struct diff_filespec *b = ci->pair2->two;
973 + const char *dst_name_a = a->path;
974 + const char *dst_name_b = b->path;
975 char *del[2];
976 int delp = 0;
975 - const char *src = pair1->one->path;
976 - const char *ren1_dst = pair1->two->path;
977 - const char *ren2_dst = pair2->two->path;
978 - const char *dst_name1 = ren1_dst;
979 - const char *dst_name2 = ren2_dst;
977
978 output(o, 1, "CONFLICT (rename/rename): "
979 "Rename \"%s\"->\"%s\" in branch \"%s\" "
980 "rename \"%s\"->\"%s\" in \"%s\"%s",
984 - src, pair1->two->path, branch1,
985 - src, pair2->two->path, branch2,
981 + one->path, a->path, ci->branch1,
982 + one->path, b->path, ci->branch2,
983 o->call_depth ? " (left unresolved)" : "");
987 - if (dir_in_way(ren1_dst, !o->call_depth)) {
988 - dst_name1 = del[delp++] = unique_path(o, ren1_dst, branch1);
984 + if (dir_in_way(a->path, !o->call_depth)) {
985 + dst_name_a = del[delp++] = unique_path(o, a->path, ci->branch1);
986 output(o, 1, "%s is a directory in %s adding as %s instead",
990 - ren1_dst, branch2, dst_name1);
987 + a->path, ci->branch2, dst_name_a);
988 }
992 - if (dir_in_way(ren2_dst, !o->call_depth)) {
993 - dst_name2 = del[delp++] = unique_path(o, ren2_dst, branch2);
989 + if (dir_in_way(b->path, !o->call_depth)) {
990 + dst_name_b = del[delp++] = unique_path(o, b->path, ci->branch2);
991 output(o, 1, "%s is a directory in %s adding as %s instead",
995 - ren2_dst, branch1, dst_name2);
992 + b->path, ci->branch1, dst_name_b);
993 }
994 if (o->call_depth) {
995 struct merge_file_info mfi;
999 - mfi = merge_file(o, src,
1000 - pair1->one->sha1, pair1->one->mode,
1001 - pair1->two->sha1, pair1->two->mode,
1002 - pair2->two->sha1, pair2->two->mode,
1003 - branch1, branch2);
996 + mfi = merge_file(o, one->path,
997 + one->sha1, one->mode,
998 + a->sha1, a->mode,
999 + b->sha1, b->mode,
1000 + ci->branch1, ci->branch2);
1001 /*
1002 * FIXME: For rename/add-source conflicts (if we could detect
1003 * such), this is wrong. We should instead find a unique
1004 * pathname and then either rename the add-source file to that
1005 * unique path, or use that unique path instead of src here.
1006 */
1010 - update_file(o, 0, mfi.sha, mfi.mode, src);
1011 - remove_file_from_cache(ren1_dst);
1012 - remove_file_from_cache(ren2_dst);
1007 + update_file(o, 0, mfi.sha, mfi.mode, one->path);
1008 + remove_file_from_cache(a->path);
1009 + remove_file_from_cache(b->path);
1010 } else {
1014 - update_stages(ren1_dst, NULL, pair1->two, NULL);
1015 - update_stages(ren2_dst, NULL, NULL, pair2->two);
1011 + update_stages(a->path, NULL, a, NULL);
1012 + update_stages(b->path, NULL, NULL, b);
1013
1017 - update_file(o, 0, pair1->two->sha1, pair1->two->mode, dst_name1);
1018 - update_file(o, 0, pair2->two->sha1, pair2->two->mode, dst_name2);
1014 + update_file(o, 0, a->sha1, a->mode, dst_name_a);
1015 + update_file(o, 0, b->sha1, b->mode, dst_name_b);
1016 }
1017 while (delp--)
1018 free(del[delp]);
@@ -1503,10 +1500,7 @@ static int process_entry(struct merge_options *o,
1500 break;
1501 case RENAME_ONE_FILE_TO_TWO:
1502 clean_merge = 0;
1506 - conflict_rename_rename_1to2(o, conflict_info->pair1,
1507 - conflict_info->branch1,
1508 - conflict_info->pair2,
1509 - conflict_info->branch2);
1503 + conflict_rename_rename_1to2(o, conflict_info);
1504 break;
1505 default:
1506 entry->processed = 0;