Skip to contentSkip to conversation

merge-recursive: handle D/F conflict case more carefully.

PATCH In review Junio C Hamano 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 merge-recursive: handle D/F conflict case more carefully.

When a path D that originally was blob in the ancestor was modified on our branch while it was removed on the other branch, we keep stages 1 and 2, and leave our version in the working tree. If the other branch created a path D/F, however, that path can cleanly be resolved in the index (after all, the ancestor nor we do not have it and only the other side added), but it cannot be checked out. The issue is the same when the other branch had D and we had renamed it to D/F, or the ancestor had D/F instead of D (so there are four combinations).

Do not stop the merge, but leave both D and D/F paths in the index so that the user can clear things up.

---

* This one is quite iffy, as I suspect it can leave higher stages for intermediate merges in its current form, and I suspect that the caller of this function should be checking for D/F conflicts (there are some provisions in the existing code, but apparently they are not good enough to do the right thing to pass t3030 test which is the next patch).

 merge-recursive.c |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)
merge-recursive.c +26 -3
index aa3d913..857eeee 100644
@@ -580,9 +580,31 @@ static void update_file_flags(const unsigned char *sha,
 
 		if (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {
 			int fd;
-			if (mkdir_p(path, 0777))
-				die("failed to create path %s: %s", path, strerror(errno));
-			unlink(path);
+			int status;
+			const char *msg = "failed to create path '%s'%s";
+
+			status = mkdir_p(path, 0777);
+			if (status) {
+				if (status == -3) {
+					/* something else exists */
+					error(msg, path, ": perhaps a D/F conflict?");
+					update_wd = 0;
+					goto update_index;
+				}
+				die(msg, path, "");
+			}
+			if (unlink(path)) {
+				if (errno == EISDIR) {
+					/* something else exists */
+					error(msg, path, ": perhaps a D/F conflict?");
+					update_wd = 0;
+					goto update_index;
+				}
+				if (errno != ENOENT)
+					die("failed to unlink %s "
+					    "in preparation to update: %s",
+					    path, strerror(errno));
+			}
 			if (mode & 0100)
 				mode = 0777;
 			else
@@ -604,6 +626,7 @@ static void update_file_flags(const unsigned char *sha,
 			die("do not know what to do with %06o %s '%s'",
 			    mode, sha1_to_hex(sha), path);
 	}
+ update_index:
 	if (update_cache)
 		add_cacheinfo(mode, sha, path, 0, update_wd, ADD_CACHE_OK_TO_ADD);
 }
Signature · 1 line
1.5.1.81.gee969
#1 lore raw

Junio C Hamano, Sat, Apr 07, 2007 16:42:55 +0200:

merge-recursive.c static void update_file_flags(const unsigned char *sha, · line 599

Quoted 4 lines
merge-recursive.c +4 -0
+			if (unlink(path)) {
+				if (errno == EISDIR) {
+					/* something else exists */
+					error(msg, path, ": perhaps a D/F conflict?");

isn't this one an F/D conflict?

#2 lore raw
Quoted 7 lines · Alex Riesen

Junio C Hamano, Sat, Apr 07, 2007 16:42:55 +0200:

merge-recursive.c static void update_file_flags(const unsigned char *sha, · line 599

Quoted 4 lines
merge-recursive.c +4 -0
+			if (unlink(path)) {
+				if (errno == EISDIR) {
+					/* something else exists */
+					error(msg, path, ": perhaps a D/F conflict?");

isn't this one an F/D conflict?

Yes, as I said in a separate message, the current D/F detector code in merge-recursive does not catch this case in t3030 test and comes to this codepath to write it out:

From: Junio C Hamano <[email protected]>
Subject: Re: [PATCH 5/5] t3030: merge-recursive backend test.
Date: Sat, 07 Apr 2007 22:17:25 -0700
Message-ID: <[email protected]>

Quoted 4 lines
(quoted diff) +4 -0
+test_expect_success 'merge-recursive d/f conflict result' '
+
+	git ls-files -s >actual &&
+	(

Review

Quoted 10 lines
(quoted diff) +10 -0
+		echo "100644 $o0 0	A"
+		echo "100644 $o0 1	a"
+		echo "100644 $o1 2	a"
+		echo "100644 $o4 0	a/c"
+		echo "100644 $o0 0	b"
+		echo "100644 $o1 0	d/e"
+	) >expected &&
+	git diff -u expected actual
+
+'

The expected result of this test is what I find very iffy. The input trees are:

* Ancestor has a file "a"
* Our tree has a file "a", which was modified from the ancestor's
* The other tree has a file "a/c"

merge-recursive.c::git_merge_trees() calls unpack_trees() using the threeway_merge function and what it gets back are stage 1 and 2 entries for "a", and stage 3 entry for "a/c" (you can see it by running "git-read-tree -m $c0 $c1 $c4" instead). But the output from merge-recursive has "a/c" resolved down to stage 0.

The problem is that process_entry() finds that there is only stage 3 entry for that path and decides to resolve it. I think it should do the D/F check and leave "a/c" in stage 3.

The part you quoted is merely working this problem around.

#3 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Alex Riesen

Junio C Hamano, Sat, Apr 07, 2007 16:42:55 +0200:

Quoted 4 lines
merge-recursive.c +4 -0
+                    if (unlink(path)) {
+                            if (errno == EISDIR) {
+                                    /* something else exists */
+                                    error(msg, path, ": perhaps a D/F conflict?");
Quoted 6 lines
Quoted 1 line

isn't this one an F/D conflict?

Yes, as I said in a separate message, the current D/F detector code in merge-recursive does not catch this case in t3030 test and comes to this codepath to write it out:

I mean, maybe the error could be spelled differently:
": perhaps an F/D conflict?"
Right now we have two exactly the same errors,
as seen on the output. The messages refer to different conflicts, though. It is usually useful to know what is really going on.

#4 lore raw
Quoted 16 lines · Alex Riesen
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Alex Riesen

Junio C Hamano, Sat, Apr 07, 2007 16:42:55 +0200:

Quoted 4 lines
merge-recursive.c +4 -0
+                    if (unlink(path)) {
+                            if (errno == EISDIR) {
+                                    /* something else exists */
+                                    error(msg, path, ": perhaps a D/F conflict?");
Quoted 6 lines
Quoted 1 line

isn't this one an F/D conflict?

Yes, as I said in a separate message, the current D/F detector code in merge-recursive does not catch this case in t3030 test and comes to this codepath to write it out:

Quoted 6 lines

I mean, maybe the error could be spelled differently:
": perhaps an F/D conflict?"
Right now we have two exactly the same errors,
as seen on the output. The messages refer to different conflicts, though. It is usually useful to know what is really going on.

Perhaps, but I think the bigger issue is that existing D/F or F/D conflict detection is simply buggy, and this patch shouldn't be needed if they were working correctly.