threads / patch / 19973

patchAlways output a trailing space conflicted merge markers.

Subject: [PATCH] Always output a trailing space conflicted merge markers.

## tl;dr

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

replies: 3people: 3as markdown or json

Nelson Elhage· Jun 30, 2009, 00:41 UTC · lore

Some tools, such as emacs' smerge-mode, except that diff3-style merge conflict markers always include a trailing space (and optional description) after the marker, and so fail to correctly detect git's (notably the '|||||||' base marker, for which git never outputs a trailing space).

(See http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=3553 for the emacs issue)

Signed-off-by: Nelson Elhage <nelhage@mit.edu>
---
 xdiff/xmerge.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
Show changes to xdiff/xmerge.c +8 −3
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 1cb65a9..a4baba8 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -148,8 +148,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 			      xdmerge_t *m, char *dest)
 {
 	const int marker_size = 7;
-	int marker1_size = (name1 ? strlen(name1) + 1 : 0);
-	int marker2_size = (name2 ? strlen(name2) + 1 : 0);
+	int marker1_size = (name1 ? strlen(name1) + 1 : 1);
+	int marker2_size = (name2 ? strlen(name2) + 1 : 1);
 	int j;
 
 	/* Before conflicting part */
@@ -165,6 +165,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 			dest[size] = ' ';
 			memcpy(dest + size + 1, name1, marker1_size - 1);
 			size += marker1_size;
+		} else {
+			dest[size++] = ' ';
 		}
 		dest[size++] = '\n';
 	}
@@ -176,10 +178,11 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 	if (style == XDL_MERGE_DIFF3) {
 		/* Shared preimage */
 		if (!dest) {
-			size += marker_size + 1;
+			size += marker_size + 2;
 		} else {
 			for (j = 0; j < marker_size; j++)
 				dest[size++] = '|';
+			dest[size++] = ' ';
 			dest[size++] = '\n';
 		}
 		size += xdl_orig_copy(xe1, m->i0, m->chg0, 1,
@@ -206,6 +209,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 			dest[size] = ' ';
 			memcpy(dest + size + 1, name2, marker2_size - 1);
 			size += marker2_size;
+		} else {
+			dest[size++] = ' ';
 		}
 		dest[size++] = '\n';
 	}
-- 
1.6.3.3
Junio C Hamano· Jun 30, 2009, 22:20 UTC · re: Nelson Elhage · lore

Re: [PATCH] Always output a trailing space conflicted merge markers.

Nelson Elhage <nelhage@MIT.EDU> writes:
Show 13 quoted lines
> Some tools, such as emacs' smerge-mode, except that diff3-style merge
> conflict markers always include a trailing space (and optional
> description) after the marker, and so fail to correctly detect
> git's (notably the '|||||||' base marker, for which git never outputs a
> trailing space).
>
> (See http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=3553
> for the emacs issue)
>
> Signed-off-by: Nelson Elhage <nelhage@mit.edu>
> ---
>  xdiff/xmerge.c |   11 ++++++++---
>  1 files changed, 8 insertions(+), 3 deletions(-)
Thanks, but I think you also need to update the test scripts.

Don't you want some new tests to protect this from getting broken in the future by other people yourself, too?

Junio C Hamano· Jul 1, 2009, 02:01 UTC · re: Junio C Hamano · lore

Re: [PATCH] Always output a trailing space conflicted merge markers.

Junio C Hamano <gitster@pobox.com> writes:
Show 20 quoted lines
> Nelson Elhage <nelhage@MIT.EDU> writes:
>
>> Some tools, such as emacs' smerge-mode, except that diff3-style merge
>> conflict markers always include a trailing space (and optional
>> description) after the marker, and so fail to correctly detect
>> git's (notably the '|||||||' base marker, for which git never outputs a
>> trailing space).
>>
>> (See http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=3553
>> for the emacs issue)
>>
>> Signed-off-by: Nelson Elhage <nelhage@mit.edu>
>> ---
>>  xdiff/xmerge.c |   11 ++++++++---
>>  1 files changed, 8 insertions(+), 3 deletions(-)
>
> Thanks, but I think you also need to update the test scripts.
>
> Don't you want some new tests to protect this from getting broken
> in the future by other people yourself, too?

I actually changed my mind. The plain "diff3" (from GNU diffutils 2.8.1) does not seem to give an trailing space after ||||||| separator. It feels very wrong to change the output format to work around a bug in smerge-mode (which I never use, by the way), if we are not the only offender. With this change, we may be breaking something else that relied on the "diff3" output format that does not have such a trailing space.

I'll drop this patch.
Nanako Shiraishi· Jul 1, 2009, 03:42 UTC · re: Junio C Hamano · lore

Re: [PATCH] Always output a trailing space conflicted merge markers.

Quoting Junio C Hamano <gitster@pobox.com>:
Show 20 quoted lines
> Nelson Elhage <nelhage@MIT.EDU> writes:
>
>> Some tools, such as emacs' smerge-mode, except that diff3-style merge
>> conflict markers always include a trailing space (and optional
>> description) after the marker, and so fail to correctly detect
>> git's (notably the '|||||||' base marker, for which git never outputs a
>> trailing space).
>>
>> (See http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=3553
>> for the emacs issue)
>>
>> Signed-off-by: Nelson Elhage <nelhage@mit.edu>
>> ---
>>  xdiff/xmerge.c |   11 ++++++++---
>>  1 files changed, 8 insertions(+), 3 deletions(-)
>
> Thanks, but I think you also need to update the test scripts.
>
> Don't you want some new tests to protect this from getting broken
> in the future by other people yourself, too?
I don't know what future breakages Nelson wants to protect his code from, but this change breaks the test for union merge in t6026-merge-attr.sh.
It isn't that the test script expects no space after the conflict marker, but with Nelson's patch, the union merge no longer works.
I request this patch to be dropped.
-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

← back to recent threads