merge-recursive: Have conflict_rename_delete reuse modify/delete code

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 e03acb8bc1f03827210235dd72578b8b26f19c51
1 file changed +30 -16
merge-recursive.c
+30 -16
@@ -1037,24 +1037,38 @@ static void conflict_rename_delete(struct merge_options *o,
1037 const char *rename_branch,
1038 const char *other_branch)
1039 {
1040 - char *dest_name = pair->two->path;
1041 - int df_conflict = 0;
1040 + const struct diff_filespec *orig = pair->one;
1041 + const struct diff_filespec *dest = pair->two;
1042 + const char *path;
1043 + const unsigned char *a_sha = NULL;
1044 + const unsigned char *b_sha = NULL;
1045 + int a_mode = 0;
1046 + int b_mode = 0;
1047 +
1048 + if (rename_branch == o->branch1) {
1049 + a_sha = dest->sha1;
1050 + a_mode = dest->mode;
1051 + } else {
1052 + b_sha = dest->sha1;
1053 + b_mode = dest->mode;
1054 + }
1055
1043 - output(o, 1, "CONFLICT (rename/delete): Rename %s->%s in %s "
1044 - "and deleted in %s",
1045 - pair->one->path, pair->two->path, rename_branch,
1046 - other_branch);
1047 - if (!o->call_depth)
1048 - update_stages(dest_name, NULL,
1049 - rename_branch == o->branch1 ? pair->two : NULL,
1050 - rename_branch == o->branch1 ? NULL : pair->two);
1051 - if (dir_in_way(dest_name, !o->call_depth)) {
1052 - dest_name = unique_path(o, dest_name, rename_branch);
1053 - df_conflict = 1;
1056 + if (o->call_depth) {
1057 + remove_file_from_cache(dest->path);
1058 + path = orig->path;
1059 + } else {
1060 + path = dest->path;
1061 + update_stages(dest->path, NULL,
1062 + rename_branch == o->branch1 ? dest : NULL,
1063 + rename_branch == o->branch1 ? NULL : dest);
1064 }
1055 - update_file(o, 0, pair->two->sha1, pair->two->mode, dest_name);
1056 - if (df_conflict)
1057 - free(dest_name);
1065 +
1066 + handle_change_delete(o,
1067 + path,
1068 + orig->sha1, orig->mode,
1069 + a_sha, a_mode,
1070 + b_sha, b_mode,
1071 + "rename", "renamed");
1072 }
1073
1074 static void conflict_rename_rename_1to2(struct merge_options *o,