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

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 30, 2014, 5:41 p.m.
Message ID <55c81bbb9b76fe941fae.1409420497@gps-mbp.local>
Download mbox | patch
Permalink /patch/5644/
State Superseded
Headers show

Comments

Gregory Szorc - Aug. 30, 2014, 5:41 p.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
Siddharth Agarwal - Aug. 30, 2014, 5:58 p.m.
On Aug 30, 2014 7:42 PM, "Gregory Szorc" <gregory.szorc@gmail.com> wrote:
>
> # 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
>
> 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)

I think this will fail with Markdown files with headers of length 7 -- one
way to mark a header is with equal signs

(This has bitten multiple people at Facebook.)

> +
>  # tell hggettext to extract docstrings from these functions:
>  i18nfunctions = internals.values()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Gregory Szorc - Aug. 31, 2014, 7:58 a.m.
On 8/30/14 7:58 PM, Siddharth Agarwal wrote:
>
> On Aug 30, 2014 7:42 PM, "Gregory Szorc" <gregory.szorc@gmail.com
> <mailto:gregory.szorc@gmail.com>> wrote:
>  >
>  > # HG changeset patch
>  > # User Gregory Szorc <gregory.szorc@gmail.com
> <mailto: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
>  >
>  > 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)
>
> I think this will fail with Markdown files with headers of length 7 --
> one way to mark a header is with equal signs
>
> (This has bitten multiple people at Facebook.)

I addressed this with a new patch in the v2 series.

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()