Mercurial > hg-stable
changeset 8568:4fa1618bf495
match: refactor patkind
add patkind(pat) to match
change external users
change util.patkind to _patsplit
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 24 May 2009 02:56:14 -0500 |
parents | fea40a677d43 |
children | 4fadac101818 |
files | mercurial/cmdutil.py mercurial/match.py mercurial/util.py |
diffstat | 3 files changed, 11 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sun May 24 02:56:14 2009 -0500 +++ b/mercurial/cmdutil.py Sun May 24 02:56:14 2009 -0500 @@ -447,7 +447,7 @@ # srcs: list of (hgsep, hgsep, ossep, bool) # return: function that takes hgsep and returns ossep def targetpathafterfn(pat, dest, srcs): - if util.patkind(pat, None)[0]: + if _match.patkind(pat): # a mercurial pattern res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) @@ -495,7 +495,7 @@ dest = pats.pop() destdirexists = os.path.isdir(dest) and not os.path.islink(dest) if not destdirexists: - if len(pats) > 1 or util.patkind(pats[0], None)[0]: + if len(pats) > 1 or _match.patkind(pats[0]): raise util.Abort(_('with multiple sources, destination must be an ' 'existing directory')) if util.endswithsep(dest):
--- a/mercurial/match.py Sun May 24 02:56:14 2009 -0500 +++ b/mercurial/match.py Sun May 24 02:56:14 2009 -0500 @@ -53,3 +53,7 @@ f, mf, ap = util.matcher(root, cwd, patterns, include, exclude, default) _match.__init__(self, root, cwd, f, mf, ap) + +def patkind(pat): + return util._patsplit(pat, None)[0] +
--- a/mercurial/util.py Sun May 24 02:56:14 2009 -0500 +++ b/mercurial/util.py Sun May 24 02:56:14 2009 -0500 @@ -207,12 +207,12 @@ def always(fn): return True def never(fn): return False -def patkind(name, default): +def _patsplit(pat, default): """Split a string into an optional pattern kind prefix and the actual pattern.""" for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': - if name.startswith(prefix + ':'): return name.split(':', 1) - return default, name + if pat.startswith(prefix + ':'): return pat.split(':', 1) + return default, pat def globre(pat, head='^', tail='$'): "convert a glob pattern into a regexp" @@ -436,7 +436,7 @@ pats = [] roots = [] anypats = False - for kind, name in [patkind(p, default) for p in names]: + for kind, name in [_patsplit(p, default) for p in names]: if kind in ('glob', 'relpath'): name = canonpath(canonroot, cwd, name) elif kind in ('relglob', 'path'): @@ -739,7 +739,7 @@ '''On Windows, expand the implicit globs in a list of patterns''' ret = [] for p in pats: - kind, name = patkind(p, None) + kind, name = _patsplit(p, None) if kind is None: globbed = glob.glob(name) if globbed: