Patchwork D11391: filemerge: be more strict when detecting conflict markers, add `|` markers

login
register
mail settings
Submitter phabricator
Date Sept. 7, 2021, 7:13 p.m.
Message ID <differential-rev-PHID-DREV-hmpveclxt2tp7kyqmhem-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49707/
State Superseded
Headers show

Comments

phabricator - Sept. 7, 2021, 7:13 p.m.
spectral created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I received a user complaint about detecting a line that contained 78 `=`
  followed by `*/` as a conflict marker. We'll never generate that, we generate 7
  identical characters and either the end of the line, or a space. Let's be
  explicit about detecting exactly what we produce to reduce the chances of a
  false positive.
  
  While we're here, add `|||||||` as a detected conflict marker (generated with
  the `keep-merge3` style conflicts).

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11391

AFFECTED FILES
  mercurial/filemerge.py

CHANGE DETAILS




To: spectral, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -1212,9 +1212,13 @@ 
 
 
 def hasconflictmarkers(data):
+    # Detect lines starting with a string of 7 identical characters from the
+    # subset Mercurial uses for conflict markers, followed by either the end of
+    # line or a space and some text. Note that using [<>=+|-]{7} would detect
+    # `<><><><><` as a conflict marker, which we don't want.
     return bool(
         re.search(
-            br"^(<<<<<<<.*|=======.*|------- .*|\+\+\+\+\+\+\+ .*|>>>>>>>.*)$",
+            br"^([<>=+|-])\1{6}( .*)$",
             data,
             re.MULTILINE,
         )