threads / patch / 19956

patchRemove filename from conflict markers

Subject: [PATCH] Remove filename from conflict markers

## tl;dr

8 messages between Jun 28, 2009 and Jul 1, 2009. Diffs are folded; open one to read it.

replies: 7people: 3as markdown or json

Martin Renold· Jun 28, 2009, 15:45 UTC · lore

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

Signed-off-by: Martin Renold <martinxyz@gmx.ch>
---
 merge-recursive.c             |    9 +++++++--
 t/t3404-rebase-interactive.sh |    4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)
Show changes to 2 files +9 −4

merge-recursive.c, t/t3404-rebase-interactive.sh

diff --git a/merge-recursive.c b/merge-recursive.c
index c703445..53cad96 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -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);
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index c32ff66..a973628 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -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' '
-- 
1.6.3.1
Junio C Hamano· Jun 30, 2009, 22:16 UTC · re: Martin Renold · lore

Re: [PATCH] Remove filename from conflict markers

Martin Renold <martinxyz@gmx.ch> writes:
Show 7 quoted lines
> Put filenames into the conflict markers only when they are different.
> Otherwise they are redundant information clutter.
>
> Signed-off-by: Martin Renold <martinxyz@gmx.ch>
> ---
>  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.

Show 42 quoted lines
>  2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/merge-recursive.c b/merge-recursive.c
> index c703445..53cad96 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -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);
> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
> index c32ff66..a973628 100755
> --- a/t/t3404-rebase-interactive.sh
> +++ b/t/t3404-rebase-interactive.sh
> @@ -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' '
> -- 
> 1.6.3.1
Nanako Shiraishi· Jul 1, 2009, 03:33 UTC · re: Junio C Hamano · lore

Re: [PATCH] Remove filename from conflict markers

Quoting Junio C Hamano <gitster@pobox.com>:
Show 14 quoted lines
> Martin Renold <martinxyz@gmx.ch> writes:
>
>> Put filenames into the conflict markers only when they are different.
>> Otherwise they are redundant information clutter.
>>
>> Signed-off-by: Martin Renold <martinxyz@gmx.ch>
>> ---
>>  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.
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(-)
Show changes to t/t6024-recursive-merge.sh +4 −4
diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh
index 129fa30..a9c4a02 100755
--- a/t/t6024-recursive-merge.sh
+++ b/t/t6024-recursive-merge.sh
@@ -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
 '
-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
Martin Renold· Jul 1, 2009, 07:56 UTC · re: Nanako Shiraishi · lore

Re: [PATCH] Remove filename from conflict markers

On Wed, Jul 01, 2009 at 12:33:10PM +0900, Nanako Shiraishi wrote:
> 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.

> -     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:
Show changes to t/t6024-recursive-merge.sh +5 −5
diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh
index 129fa30..0c6b1ea 100755
--- a/t/t6024-recursive-merge.sh
+++ b/t/t6024-recursive-merge.sh
@@ -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
Junio C Hamano· Jul 1, 2009, 08:36 UTC · re: Martin Renold · lore

Re: [PATCH] Remove filename from conflict markers

Martin Renold <martinxyz@gmx.ch> writes:
Show 9 quoted lines
>  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?
Show 9 quoted lines
> @@ -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.

Martin Renold· Jul 1, 2009, 16:16 UTC · re: Junio C Hamano · lore

Re: [PATCH] Remove filename from conflict markers

On Wed, Jul 01, 2009 at 01:36:03AM -0700, Junio C Hamano wrote:
Show 13 quoted lines
> Martin Renold <martinxyz@gmx.ch> writes:
> >  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?

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

Show 6 quoted 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.

>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.

> 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

Martin Renold· Jul 1, 2009, 20:18 UTC · re: Martin Renold · lore

[PATCH/v2] Remove filename from conflict markers

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.
Signed-off-by: Martin Renold <martinxyz@gmx.ch>
---

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(-)
Show changes to 4 files +17 −13

ll-merge.c, merge-recursive.c, t/t3404-rebase-interactive.sh, t/t6024-recursive-merge.sh

diff --git a/ll-merge.c b/ll-merge.c
index 9168958..a2c13c4 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -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);
diff --git a/merge-recursive.c b/merge-recursive.c
index c703445..53cad96 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -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);
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index c32ff66..a973628 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -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' '
diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh
index 129fa30..b3fbf65 100755
--- a/t/t6024-recursive-merge.sh
+++ b/t/t6024-recursive-merge.sh
@@ -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' '
-- 
1.6.3.1
Junio C Hamano· Jul 1, 2009, 20:57 UTC · re: Martin Renold · lore

Re: [PATCH/v2] Remove filename from conflict markers

Martin Renold <martinxyz@gmx.ch> writes:
> 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.
> -	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.

← back to recent threads