sapling/mercurial/match.py

48 lines
1.4 KiB
Python
Raw Normal View History

2008-05-12 20:37:07 +04:00
import util
2008-05-12 20:37:08 +04:00
class _match(object):
def __init__(self, root, cwd, files, mf, ap):
2008-05-12 20:37:07 +04:00
self._root = root
self._cwd = cwd
2008-05-12 20:37:08 +04:00
self._files = files
self._fmap = dict.fromkeys(files)
self.matchfn = mf
2008-05-12 20:37:07 +04:00
self._anypats = ap
def __call__(self, fn):
return self.matchfn(fn)
2008-05-12 20:37:07 +04:00
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
2008-05-12 20:37:08 +04:00
class always(_match):
def __init__(self, root, cwd):
_match.__init__(self, root, cwd, [], lambda f: True, False)
class never(_match):
def __init__(self, root, cwd):
_match.__init__(self, root, cwd, [], lambda f: False, False)
2008-05-12 20:37:08 +04:00
class exact(_match):
def __init__(self, root, cwd, files):
_match.__init__(self, root, cwd, files, lambda f: f in files, False)
2008-05-12 20:37:08 +04:00
class match(_match):
def __init__(self, root, cwd, patterns, include, exclude, default):
f, mf, ap = util.matcher(root, cwd, patterns, include, exclude,
None, default)
_match.__init__(self, root, cwd, f, mf, ap)