Patchwork [2,of,3,v4,sparse-ext] match: expose some data and functionality to other modules

login
register
mail settings
Submitter Kostia Balytskyi
Date Aug. 4, 2017, 12:45 p.m.
Message ID <c0136292871d85675ccb.1501850758@devvm1416.lla2.facebook.com>
Download mbox | patch
Permalink /patch/22665/
State Accepted
Headers show

Comments

Kostia Balytskyi - Aug. 4, 2017, 12:45 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1501714137 25200
#      Wed Aug 02 15:48:57 2017 -0700
# Node ID c0136292871d85675ccb9f386f4ae1913da4eb53
# Parent  d24d6711aa2a5397d52f46ccffa64c2a638c088b
match: expose some data and functionality to other modules

This patch makes sure that other modules can check whether patterns
are CWD-relative.
Augie Fackler - Aug. 4, 2017, 9:22 p.m.
On Fri, Aug 04, 2017 at 05:45:58AM -0700, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia@fb.com>
> # Date 1501714137 25200
> #      Wed Aug 02 15:48:57 2017 -0700
> # Node ID c0136292871d85675ccb9f386f4ae1913da4eb53
> # Parent  d24d6711aa2a5397d52f46ccffa64c2a638c088b
> match: expose some data and functionality to other modules

I've taken patches 1 and 2. Reflecting on 3 now.

>
> This patch makes sure that other modules can check whether patterns
> are CWD-relative.
>
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -18,6 +18,11 @@ from . import (
>      util,
>  )
>
> +allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
> +                   'listfile', 'listfile0', 'set', 'include', 'subinclude',
> +                   'rootfilesin')
> +cwdrelativepatternkinds = ('relpath', 'glob')
> +
>  propertycache = util.propertycache
>
>  def _rematcher(regex):
> @@ -190,7 +195,7 @@ def _donormalize(patterns, default, root
>      normalized and rooted patterns and with listfiles expanded.'''
>      kindpats = []
>      for kind, pat in [_patsplit(p, default) for p in patterns]:
> -        if kind in ('glob', 'relpath'):
> +        if kind in cwdrelativepatternkinds:
>              pat = pathutil.canonpath(root, cwd, pat, auditor)
>          elif kind in ('relglob', 'path', 'rootfilesin'):
>              pat = util.normpath(pat)
> @@ -691,9 +696,7 @@ def _patsplit(pattern, default):
>      pattern."""
>      if ':' in pattern:
>          kind, pat = pattern.split(':', 1)
> -        if kind in ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
> -                    'listfile', 'listfile0', 'set', 'include', 'subinclude',
> -                    'rootfilesin'):
> +        if kind in allpatternkinds:
>              return kind, pat
>      return default, pattern
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -18,6 +18,11 @@  from . import (
     util,
 )
 
+allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
+                   'listfile', 'listfile0', 'set', 'include', 'subinclude',
+                   'rootfilesin')
+cwdrelativepatternkinds = ('relpath', 'glob')
+
 propertycache = util.propertycache
 
 def _rematcher(regex):
@@ -190,7 +195,7 @@  def _donormalize(patterns, default, root
     normalized and rooted patterns and with listfiles expanded.'''
     kindpats = []
     for kind, pat in [_patsplit(p, default) for p in patterns]:
-        if kind in ('glob', 'relpath'):
+        if kind in cwdrelativepatternkinds:
             pat = pathutil.canonpath(root, cwd, pat, auditor)
         elif kind in ('relglob', 'path', 'rootfilesin'):
             pat = util.normpath(pat)
@@ -691,9 +696,7 @@  def _patsplit(pattern, default):
     pattern."""
     if ':' in pattern:
         kind, pat = pattern.split(':', 1)
-        if kind in ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
-                    'listfile', 'listfile0', 'set', 'include', 'subinclude',
-                    'rootfilesin'):
+        if kind in allpatternkinds:
             return kind, pat
     return default, pattern