# HG changeset patch # User Matt Mackall # Date 2009-05-24 07:56:14 # Node ID 4fa1618bf49513ca2e4c31280c3320d96e371636 # Parent fea40a677d43ce7c543fea28488e582ab79b68e3 match: refactor patkind add patkind(pat) to match change external users change util.patkind to _patsplit diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -447,7 +447,7 @@ def copy(ui, repo, pats, opts, rename=Fa # 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 @@ def copy(ui, repo, pats, opts, rename=Fa 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): diff --git a/mercurial/match.py b/mercurial/match.py --- a/mercurial/match.py +++ b/mercurial/match.py @@ -53,3 +53,7 @@ class match(_match): 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] + diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -207,12 +207,12 @@ Abort = error.Abort 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 @@ def matcher(canonroot, cwd='', names=[], 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 @@ if os.name == 'nt': '''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: