filemerge: be more strict when detecting conflict markers, add `|` markers stable
authorKyle Lippincott <spectral@google.com>
Tue, 07 Sep 2021 11:50:12 -0700
branchstable
changeset 47939 053dd53a0b59
parent 47888 7538453ec322
child 47940 cc33deae66a1
child 47942 9beea3a023ac
filemerge: be more strict when detecting conflict markers, add `|` markers 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). Differential Revision: https://phab.mercurial-scm.org/D11391
mercurial/filemerge.py
--- a/mercurial/filemerge.py	Mon Aug 30 23:40:43 2021 +0530
+++ b/mercurial/filemerge.py	Tue Sep 07 11:50:12 2021 -0700
@@ -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,
         )