Skip to contentSkip to conversation

Remove filename from conflict markers

PATCH In review Martin Renold 3 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove filename from conflict markers

Put filenames into the conflict markers only when they are different. Otherwise they are redundant information clutter.

---
 merge-recursive.c             |    9 +++++++--
 t/t3404-rebase-interactive.sh |    4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)
merge-recursive.c +7 -2
index c703445..53cad96 100644
@@ -622,8 +622,13 @@ static int merge_3way(struct merge_options *o,
 	char *name1, *name2;
 	int merge_status;
 
-	name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
-	name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
+	if (strcmp(a->path, b->path)) {
+		name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
+		name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
+	} else {
+		name1 = xstrdup(mkpath("%s", branch1));
+		name2 = xstrdup(mkpath("%s", branch2));
+	}
 
 	fill_mm(one->sha1, &orig);
 	fill_mm(a->sha1, &src1);
t/t3404-rebase-interactive.sh +2 -2
index c32ff66..a973628 100755
@@ -119,11 +119,11 @@ index e69de29..00750ed 100644
 EOF
 
 cat > expect2 << EOF
-<<<<<<< HEAD:file1
+<<<<<<< HEAD
 2
 =======
 3
->>>>>>> b7ca976... G:file1
+>>>>>>> b7ca976... G
 EOF
 
 test_expect_success 'stop on conflicting pick' '
Signature · 1 line
1.6.3.1
#1 lore raw
Quoted 7 lines · Martin Renold

Put filenames into the conflict markers only when they are different. Otherwise they are redundant information clutter.

---
 merge-recursive.c             |    9 +++++++--
 t/t3404-rebase-interactive.sh |    4 ++--

The change seems to break more tests than just 3404.

I also wondered briefly if it will break people's existing scripts; I suspect it will not likely to be a huge problem.

Quoted 42 lines
 2 files changed, 9 insertions(+), 4 deletions(-)
merge-recursive.c +7 -2
index c703445..53cad96 100644
@@ -622,8 +622,13 @@ static int merge_3way(struct merge_options *o,
 	char *name1, *name2;
 	int merge_status;
 
-	name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
-	name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
+	if (strcmp(a->path, b->path)) {
+		name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
+		name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
+	} else {
+		name1 = xstrdup(mkpath("%s", branch1));
+		name2 = xstrdup(mkpath("%s", branch2));
+	}
 
 	fill_mm(one->sha1, &orig);
 	fill_mm(a->sha1, &src1);
t/t3404-rebase-interactive.sh +2 -2
index c32ff66..a973628 100755
@@ -119,11 +119,11 @@ index e69de29..00750ed 100644
 EOF
 
 cat > expect2 << EOF
-<<<<<<< HEAD:file1
+<<<<<<< HEAD
 2
 =======
 3
->>>>>>> b7ca976... G:file1
+>>>>>>> b7ca976... G
 EOF
 
 test_expect_success 'stop on conflicting pick' '
Signature · 1 line
1.6.3.1
#2 lore raw

Quoting Junio C Hamano <[email protected]>:

Quoted 10 lines
Quoted 7 lines · Martin Renold

Put filenames into the conflict markers only when they are different. Otherwise they are redundant information clutter.

---
 merge-recursive.c             |    9 +++++++--
 t/t3404-rebase-interactive.sh |    4 ++--
Quoted 4 lines

The change seems to break more tests than just 3404.

I also wondered briefly if it will break people's existing scripts; I suspect it will not likely to be a huge problem.

I needed to apply the attached patch to make the tests pass. The last part clearly shows that this change introduces a usability regression. In the error message the user can no longer see which file was problematic.

I request Martin's patch to be dropped.

 t/t6024-recursive-merge.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
t/t6024-recursive-merge.sh +4 -4
index 129fa30..a9c4a02 100755
@@ -65,18 +65,18 @@ test_expect_success "combined merge conflicts" "
 "
 
 cat > expect << EOF
-<<<<<<< HEAD:a1
+<<<<<<< HEAD
 F
 =======
 G
->>>>>>> G:a1
+>>>>>>> G
 EOF
 
 test_expect_success "result contains a conflict" "test_cmp expect a1"
 
 git ls-files --stage > out
 cat > expect << EOF
-100644 da056ce14a2241509897fa68bb2b3b6e6194ef9e 1	a1
+100644 439cc46de773d8a83c77799b7cc9191c128bfcff 1	a1
 100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2	a1
 100644 fd7923529855d0b274795ae3349c5e0438333979 3	a1
 EOF
@@ -93,7 +93,7 @@ test_expect_success 'refuse to merge binary files' '
 	git add binary-file &&
 	git commit -m binary2 &&
 	test_must_fail git merge F > merge.out 2> merge.err &&
-	grep "Cannot merge binary files: HEAD:binary-file vs. F:binary-file" \
+	grep "Cannot merge binary files: HEAD vs. F" \
 		merge.err
 '
 
Signature · 2 lines
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
#3 lore raw
Quoted 3 lines · Nanako Shiraishi

The last part clearly shows that this change introduces a usability regression. In the error message the user can no longer see which file was problematic.

Not true. The filename is still printed two times in the case of "git merge", and four times with "git rebase". The user still sees the required information, there are just fewer repetitions.

The previous warning was a bit nicer for copy-paste, allthough I don't see why it should print things so differently compared to textual conflicts.

Review

Quoted 3 lines
(quoted diff) +1 -1
-     grep "Cannot merge binary files: HEAD:binary-file vs. F:binary-file" \
+     grep "Cannot merge binary files: HEAD vs. F" \
              merge.err

We could als fix that test by expecting the filename on stdout:

t/t6024-recursive-merge.sh +5 -5
index 129fa30..0c6b1ea 100755
@@ -65,18 +65,18 @@ test_expect_success "combined merge conflicts" "
 "
 
 cat > expect << EOF
-<<<<<<< HEAD:a1
+<<<<<<< HEAD
 F
 =======
 G
->>>>>>> G:a1
+>>>>>>> G
 EOF
 
 test_expect_success "result contains a conflict" "test_cmp expect a1"
 
 git ls-files --stage > out
 cat > expect << EOF
-100644 da056ce14a2241509897fa68bb2b3b6e6194ef9e 1      a1
+100644 439cc46de773d8a83c77799b7cc9191c128bfcff 1      a1
 100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2      a1
 100644 fd7923529855d0b274795ae3349c5e0438333979 3      a1
 EOF
@@ -93,8 +93,8 @@ test_expect_success 'refuse to merge binary files' '
        git add binary-file &&
        git commit -m binary2 &&
        test_must_fail git merge F > merge.out 2> merge.err &&
-       grep "Cannot merge binary files: HEAD:binary-file vs. F:binary-file" \
-               merge.err
+       grep "Cannot merge binary files: HEAD vs. F" merge.err
+       grep "Merge conflict in binary-file" merge.out
 '
 
 test_expect_success 'mark rename/delete as unmerged' '

bye,
Martin

#4 lore raw
Quoted 9 lines · Martin Renold

test_expect_success "result contains a conflict" "test_cmp expect a1"

git ls-files --stage > out
cat > expect << EOF

-100644 da056ce14a2241509897fa68bb2b3b6e6194ef9e 1      a1
+100644 439cc46de773d8a83c77799b7cc9191c128bfcff 1      a1
 100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2      a1
 100644 fd7923529855d0b274795ae3349c5e0438333979 3      a1

EOF

I think Nana's patch also had this, but what is this hunk about? IOW, why does stage #1 (common ancestor's version) even change?

Is this a virtual ancestor in a criss-cross recursive merge?

t/t6024-recursive-merge.sh test_expect_success 'refuse to merge binary files' ' · line 98

Quoted 9 lines
t/t6024-recursive-merge.sh +2 -2
@@ -93,8 +93,8 @@ test_expect_success 'refuse to merge binary files' '
        git add binary-file &&
        git commit -m binary2 &&
        test_must_fail git merge F > merge.out 2> merge.err &&
-       grep "Cannot merge binary files: HEAD:binary-file vs. F:binary-file" \
-               merge.err
+       grep "Cannot merge binary files: HEAD vs. F" merge.err
+       grep "Merge conflict in binary-file" merge.out
 '

At the end of the first "grep" && is missing. But more importantly, would this new output format really as informative as you claim, even when the file that cannot be automerged due to its binaryness is not named "binary-file" but simply say "X"? The merge.err output shows that there were some file that failed to merge due to being binary, and merge.out output owuld show that "X" had conflict. Would it be just as easy for the end user to connect these two as it used to be?

I for now am assuming no mechanical end user is parsing this output to figure out what to do, but that assumption might even be wrong.

#5 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Martin Renold

git ls-files --stage > out
cat > expect << EOF

-100644 da056ce14a2241509897fa68bb2b3b6e6194ef9e 1      a1
+100644 439cc46de773d8a83c77799b7cc9191c128bfcff 1      a1
 100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2      a1
 100644 fd7923529855d0b274795ae3349c5e0438333979 3      a1

EOF

Quoted 4 lines

I think Nana's patch also had this, but what is this hunk about? IOW, why does stage #1 (common ancestor's version) even change?

Is this a virtual ancestor in a criss-cross recursive merge?

The file contains conflict markers, which is why it changes. I don't understand why it has them. The merge looks pretty complex.

Quoted 6 lines

But more importantly, would this new output format really as informative as you claim, even when the file that cannot be automerged due to its binaryness is not named "binary-file" but simply say "X"? The merge.err output shows that there were some file that failed to merge due to being binary, and merge.out output owuld show that "X" had conflict. Would it be just as easy for the end user to connect these two as it used to be?

You are right. With both binary and textual conflicts at the same time, the user can not connect the two events, except by already knowing which files are binary.

I think ideally the different pieces of information (the filename, the fact that it has a merge conflict, and that it is binary) should be printed only once and together. But this goes beyond what I want to do right now.

Quoted 1 line

From an implementation point of view, the variables name1 and name2 seem to

be arbitrary, possibly user-defined conflict markers. I think it is wrong to print them in ll_xdl_merge() as if they were filenames. I will try to make a new patch that also addresses this issue.

Quoted 2 lines

I for now am assuming no mechanical end user is parsing this output to figure out what to do, but that assumption might even be wrong.

In the rebase scenario, the mechanical end user has like 5 different places where he could pick the filename from. If I was writing a script I would not expect such an output to remain stable.

bye,
Martin

#6 lore raw

Put filenames into the conflict markers only when they are different. Otherwise they are redundant information clutter.

Print the filename explicitely when warning about a binary conflict.

---

Thanks for your feedback. Here is the second attempt. It turned out that the required function arguments were already there, just unused.

 ll-merge.c                    |    8 ++++----
 merge-recursive.c             |    9 +++++++--
 t/t3404-rebase-interactive.sh |    4 ++--
 t/t6024-recursive-merge.sh    |    9 ++++-----
 4 files changed, 17 insertions(+), 13 deletions(-)
ll-merge.c +4 -4
index 9168958..a2c13c4 100644
@@ -55,7 +55,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
 
 static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
 			mmbuffer_t *result,
-			const char *path_unused,
+			const char *path,
 			mmfile_t *orig,
 			mmfile_t *src1, const char *name1,
 			mmfile_t *src2, const char *name2,
@@ -67,10 +67,10 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
 	if (buffer_is_binary(orig->ptr, orig->size) ||
 	    buffer_is_binary(src1->ptr, src1->size) ||
 	    buffer_is_binary(src2->ptr, src2->size)) {
-		warning("Cannot merge binary files: %s vs. %s\n",
-			name1, name2);
+		warning("Cannot merge binary files: %s (%s vs. %s)\n",
+			path, name1, name2);
 		return ll_binary_merge(drv_unused, result,
-				       path_unused,
+				       path,
 				       orig, src1, name1,
 				       src2, name2,
 				       virtual_ancestor);
merge-recursive.c +7 -2
index c703445..53cad96 100644
@@ -622,8 +622,13 @@ static int merge_3way(struct merge_options *o,
 	char *name1, *name2;
 	int merge_status;
 
-	name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
-	name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
+	if (strcmp(a->path, b->path)) {
+		name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
+		name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
+	} else {
+		name1 = xstrdup(mkpath("%s", branch1));
+		name2 = xstrdup(mkpath("%s", branch2));
+	}
 
 	fill_mm(one->sha1, &orig);
 	fill_mm(a->sha1, &src1);
t/t3404-rebase-interactive.sh +2 -2
index c32ff66..a973628 100755
@@ -119,11 +119,11 @@ index e69de29..00750ed 100644
 EOF
 
 cat > expect2 << EOF
-<<<<<<< HEAD:file1
+<<<<<<< HEAD
 2
 =======
 3
->>>>>>> b7ca976... G:file1
+>>>>>>> b7ca976... G
 EOF
 
 test_expect_success 'stop on conflicting pick' '
t/t6024-recursive-merge.sh +4 -5
index 129fa30..b3fbf65 100755
@@ -65,18 +65,18 @@ test_expect_success "combined merge conflicts" "
 "
 
 cat > expect << EOF
-<<<<<<< HEAD:a1
+<<<<<<< HEAD
 F
 =======
 G
->>>>>>> G:a1
+>>>>>>> G
 EOF
 
 test_expect_success "result contains a conflict" "test_cmp expect a1"
 
 git ls-files --stage > out
 cat > expect << EOF
-100644 da056ce14a2241509897fa68bb2b3b6e6194ef9e 1	a1
+100644 439cc46de773d8a83c77799b7cc9191c128bfcff 1	a1
 100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2	a1
 100644 fd7923529855d0b274795ae3349c5e0438333979 3	a1
 EOF
@@ -93,8 +93,7 @@ test_expect_success 'refuse to merge binary files' '
 	git add binary-file &&
 	git commit -m binary2 &&
 	test_must_fail git merge F > merge.out 2> merge.err &&
-	grep "Cannot merge binary files: HEAD:binary-file vs. F:binary-file" \
-		merge.err
+	grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge.err
 '
 
 test_expect_success 'mark rename/delete as unmerged' '
Signature · 1 line
1.6.3.1
#7 lore raw
Quoted 4 lines · Martin Renold

Put filenames into the conflict markers only when they are different. Otherwise they are redundant information clutter.

Print the filename explicitely when warning about a binary conflict.

I think we are getting closer.

t/t6024-recursive-merge.sh test_expect_success 'refuse to merge binary files' ' · line 96

Quoted 3 lines
t/t6024-recursive-merge.sh +1 -2
-	grep "Cannot merge binary files: HEAD:binary-file vs. F:binary-file" \
-		merge.err
+	grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge.err

In the original code, if you are not in "merge renamed" situation, you would see something like this.

"Cannot merge binary files: HEAD:porn.jpg vs F:porn.jpg"

And the patch changes it to

"Cannot merge binary files: porn.jpg (HEAD vs F)"

which is an improvement. I have to wonder, if it even necessary to say HEAD vs F when no rename is involved, though. Probably it is, as this is about binary files, and the user may need to extract the contents with something like "git cat-file blob HEAD:porn.jpg >tmp1.jpg".

When you are indeed in "merge renamed" situation, it gets a bit more interesting. The original said

"Cannot merge binary files: HEAD:porn.jpg vs F:porn112.jpg"

which makes it clear that what is merged with what, but did not say where the resulting merge will go. The updated output would say something like this

"Cannot merge binary files: porn.jpg (HEAD:porn.jpg vs F:porn112.jpg)"

which adds information and is probably better.

So overall, I like what the change does, but I'd probably wait for a few more days just in case there are objections from different corners, primarily because I am somewhat concerned that this change might affect users of mergetool (which I do not use myself) in some negative way.