merge-recursive: do not check working copy when creating a virtual merge base

There were a few cases in merge-recursive that could result in a check for the presence of files in the working copy while trying to create a virtual merge base. These were rare and innocuous, but somewhat illogical. The two cases were: * When there was naming conflicts (e.g. a D/F conflict) and we had to pick a new unique name for a file. Since the new name is somewhat arbitrary, it didn't matter that we consulted the working copy to avoid picking a filename it has, but since the virtual merge base is never checked out, it's a waste of time and slightly odd to do so. * When two different files get renamed to the same name (on opposite sides of the merge), we needed to delete the original filenames from the cache and possibly also the working directory. The caller's check for determining whether to delete from the working directory was a call to would_lose_untracked(). It turns out this didn't matter because remove_file() had logic to avoid modifying the working directory when creating a virtual merge base, but there is no reason for the caller to check the working directory in such circumstances. It's a waste of time, if not also a bit weird. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 9, 2016 at 23:13 UTC 8e1b62f174bb53f5fb7cf027f9c426d0c6864003
1 file changed +3 -3
merge-recursive.c
+3 -3
@@ -622,7 +622,7 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
622 base_len = newpath.len;
623 while (string_list_has_string(&o->current_file_set, newpath.buf) ||
624 string_list_has_string(&o->current_directory_set, newpath.buf) ||
625 - file_exists(newpath.buf)) {
625 + (!o->call_depth && file_exists(newpath.buf))) {
626 strbuf_setlen(&newpath, base_len);
627 strbuf_addf(&newpath, "_%d", suffix++);
628 }
@@ -1234,8 +1234,8 @@ static void conflict_rename_rename_2to1(struct merge_options *o,
1234 a->path, c1->path, ci->branch1,
1235 b->path, c2->path, ci->branch2);
1236
1237 - remove_file(o, 1, a->path, would_lose_untracked(a->path));
1238 - remove_file(o, 1, b->path, would_lose_untracked(b->path));
1237 + remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));
1238 + remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));
1239
1240 mfi_c1 = merge_file_special_markers(o, a, c1, &ci->ren1_other,
1241 o->branch1, c1->path,