Patchwork [1,of,3,v2] filemerge: extract conflict marker searching into its own function

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 31, 2014, 7:56 a.m.
Message ID <55c81bbb9b76fe941fae.1409471772@gps-mbp.local>
Download mbox | patch
Permalink /patch/5647/
State Accepted
Headers show

Comments

Gregory Szorc - Aug. 31, 2014, 7:56 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1409418673 -7200
#      Sat Aug 30 19:11:13 2014 +0200
# Node ID 55c81bbb9b76fe941faea87e77b0a5c95d4425f2
# Parent  188b8aa2120b03eead618ba150319074f4e3b42b
filemerge: extract conflict marker searching into its own function
Mads Kiilerich - Aug. 31, 2014, 1:28 p.m.
On 08/31/2014 09:56 AM, Gregory Szorc wrote:
> +        if haveconflictmarkers(fcd):
...
> +def hasconflictmarkers(fctx):

This inconsistency is primarily a bug in the definition of the English 
language, but it also highlights the need for test coverage of this.

/Mads
Matt Mackall - Sept. 1, 2014, 9:16 p.m.
On Sun, 2014-08-31 at 09:56 +0200, Gregory Szorc wrote:

> +        if haveconflictmarkers(fcd):
>  
> +def hasconflictmarkers(fctx):

I question whether this was tested, but I like the idea.
Pierre-Yves David - Sept. 2, 2014, 7:11 p.m.
On 09/01/2014 11:16 PM, Matt Mackall wrote:
> On Sun, 2014-08-31 at 09:56 +0200, Gregory Szorc wrote:
>
>> +        if haveconflictmarkers(fcd):
>>
>> +def hasconflictmarkers(fctx):
>
> I question whether this was tested, but I like the idea.

He might have piped his patch through an mq filter to tests your skills.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -433,10 +433,9 @@  def filemerge(repo, mynode, orig, fcd, f
         return r
 
     if not r and (_toolbool(ui, tool, "checkconflicts") or
                   'conflicts' in _toollist(ui, tool, "check")):
-        if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(),
-                     re.MULTILINE):
+        if haveconflictmarkers(fcd):
             r = 1
 
     checked = False
     if 'prompt' in _toollist(ui, tool, "check"):
@@ -465,6 +464,11 @@  def filemerge(repo, mynode, orig, fcd, f
     util.unlink(b)
     util.unlink(c)
     return r
 
+def hasconflictmarkers(fctx):
+    """Whether data from a filecontext has conflict markers."""
+    return re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fctx.data(),
+                     re.MULTILINE)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = internals.values()