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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
 xdiff/xmerge.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]