match: expose some data and functionality to other modules
authorKostia Balytskyi <ikostia@fb.com>
Wed, 02 Aug 2017 15:48:57 -0700
changeset 39081 2be0bf1869506ad478113b29185d165bc37983dd
parent 39080 7dcb517122f916600e9fc838f532f13d9451bbd8
child 39082 e1c56486d1aaa0f60566d0733d111c0606c3db91
push id559
push usergszorc@mozilla.com
push dateThu, 10 Aug 2017 07:07:12 +0000
match: expose some data and functionality to other modules This patch makes sure that other modules can check whether patterns are CWD-relative.
mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -13,16 +13,21 @@ import re
 
 from .i18n import _
 from . import (
     error,
     pathutil,
     util,
 )
 
+allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
+                   'listfile', 'listfile0', 'set', 'include', 'subinclude',
+                   'rootfilesin')
+cwdrelativepatternkinds = ('relpath', 'glob')
+
 propertycache = util.propertycache
 
 def _rematcher(regex):
     '''compile the regexp with the best available regexp engine and return a
     matcher function'''
     m = util.re.compile(regex)
     try:
         # slightly faster, provided by facebook's re2 bindings
@@ -185,17 +190,17 @@ def badmatch(match, badfn):
     m.bad = badfn
     return m
 
 def _donormalize(patterns, default, root, cwd, auditor, warn):
     '''Convert 'kind:pat' from the patterns list to tuples with kind and
     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)
         elif kind in ('listfile', 'listfile0'):
             try:
                 files = util.readfile(pat)
                 if kind == 'listfile0':
                     files = files.split('\0')
@@ -686,19 +691,17 @@ def patkind(pattern, default=None):
     '''If pattern is 'kind:pat' with a known kind, return kind.'''
     return _patsplit(pattern, default)[0]
 
 def _patsplit(pattern, default):
     """Split a string into the optional pattern kind prefix and the actual
     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
 
 def _globre(pat):
     r'''Convert an extended glob string to a regexp string.
 
     >>> print _globre(r'?')
     .