Patchwork [09,of,11,V2] filemerge: use only the first line of the generated conflict marker for safety

login
register
mail settings
Submitter Katsunori FUJIWARA
Date July 5, 2014, 6 p.m.
Message ID <23280cda5ee6b9ee8840.1404583208@feefifofum>
Download mbox | patch
Permalink /patch/5116/
State Accepted
Commit 755bf1bbe0a90b6357b121139bb480ed695b12d2
Headers show

Comments

Katsunori FUJIWARA - July 5, 2014, 6 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1404583001 -32400
#      Sun Jul 06 02:56:41 2014 +0900
# Node ID 23280cda5ee6b9ee8840d8f487e36d29efb7c95c
# Parent  880eee6596c6d8ecb320ae0a33a8eae94a076dfa
filemerge: use only the first line of the generated conflict marker for safety

Before this patch, with careless configuration (missing '|firstline'
filtering for '{desc}' keyword, for example), '[ui]
mergemarkertemplate' can make conflict markers multiple lines.

For ordinary users, advantage of allowing '[ui] mergemarkertemplate'
to generate multiple lines for customizing seems to be less than
advantage of disallowing it for safety.

This patch uses only the first line of the conflict marker generated
from '[ui] mergemarkertemplate' configuration for safety.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -287,6 +287,9 @@ 
     label = ('%s:' % label).ljust(pad + 1)
     mark = '%s %s' % (label, templater.stringify(templateresult))
 
+    if mark:
+        mark = mark.splitlines()[0] # split for safety
+
     # The <<< marks add 8 to the length, and '...' adds three, so max
     # length of the actual marker is 69.
     maxlength = 80 - 8 - 3
diff --git a/tests/test-conflict.t b/tests/test-conflict.t
--- a/tests/test-conflict.t
+++ b/tests/test-conflict.t
@@ -52,6 +52,26 @@ 
   something
   >>>>>>> other: test 1
 
+Verify line splitting of custom conflict marker which causes multiple lines
+
+  $ hg up -q --clean .
+  $ cat >> .hg/hgrc <<EOF
+  > [ui]
+  > mergemarkertemplate={author} {rev}\nfoo\nbar\nbaz
+  > EOF
+
+  $ hg -q merge 1
+  warning: conflicts during merge.
+  merging a incomplete! (edit conflicts, then use 'hg resolve --mark')
+  [1]
+
+  $ cat a
+  <<<<<<< local: test 2
+  something else
+  =======
+  something
+  >>>>>>> other: test 1
+
 Verify basic conflict markers
 
   $ hg up -q --clean .