diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -8,7 +8,7 @@ from node import hex, nullid, nullrev, short from i18n import _ import os, sys, bisect, stat -import mdiff, bdiff, util, templater, templatefilters, patch, errno +import mdiff, bdiff, util, templater, templatefilters, patch, errno, match revrangesep = ':' @@ -224,21 +224,18 @@ def make_file(repo, pat, node=None, mode) def matchpats(repo, pats=[], opts={}, globbed=False, default='relpath'): - pats = pats or [] if not globbed and default == 'relpath': pats = util.expand_glob(pats or []) - return util.matcher(repo.root, repo.getcwd(), pats, opts.get('include'), - opts.get('exclude'), None, default) + m = match.match(repo.root, repo.getcwd(), pats, opts.get('include'), + opts.get('exclude'), default) + return m.files(), m, m.anypats() def walk(repo, pats=[], opts={}, node=None, badmatch=None, globbed=False, default='relpath'): - files, matchfn, anypats = matchpats(repo, pats, opts, globbed=globbed, - default=default) - exact = dict.fromkeys(files) - cwd = repo.getcwd() - for src, fn in repo.walk(node=node, files=files, match=matchfn, + dummy, m, dummy = matchpats(repo, pats, opts, globbed, default) + for src, fn in repo.walk(node=node, files=m.files(), match=m, badmatch=badmatch): - yield src, fn, repo.pathto(fn, cwd), fn in exact + yield src, fn, m.rel(fn), m.exact(fn) def findrenames(repo, added=None, removed=None, threshold=0.5): '''find renamed files -- yields (before, after, score) tuples''' diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -786,7 +786,7 @@ class localrepository(repo.repository): update_dirstate = True if (not force and p2 != nullid and - (files or match != util.always)): + (match.files() or match.anypats())): raise util.Abort(_('cannot partially commit a merge ' '(do not specify files or patterns)')) else: diff --git a/mercurial/match.py b/mercurial/match.py new file mode 100644 --- /dev/null +++ b/mercurial/match.py @@ -0,0 +1,37 @@ +import util + +class match(object): + def __init__(self, root, cwd, patterns, include, exclude, default): + self._patterns = patterns + self._root = root + self._cwd = cwd + self._include = include + self._exclude = exclude + f, mf, ap = util.matcher(self._root, self._cwd, self._patterns, + self._include, self._exclude, self.src(), + default) + self._files = f + self._fmap = dict.fromkeys(f) + self._matchfn = mf + self._anypats = ap + def src(self): + return None + def __call__(self, fn): + return self._matchfn(fn) + def __iter__(self): + for f in self._files: + yield f + def bad(self, f, msg): + return True + def dir(self, f): + pass + def missing(self, f): + pass + def exact(self, f): + return f in self._fmap + def rel(self, f): + return util.pathto(self._root, self._cwd, f) + def files(self): + return self._files + def anypats(self): + return self._anypats