mercurial/match.py
author Patrick Mezard <pmezard@gmail.com>
Wed, 18 Jun 2008 22:52:25 +0200
changeset 6707 02bad34230a2
parent 6604 98b6e6f0e49b
child 6834 cbdfd08eabc9
permissions -rw-r--r--
localrepo: hide commit() file selection behind workingctx
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6576
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
import util
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
6604
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
     3
class _match(object):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
     4
    def __init__(self, root, cwd, files, mf, ap):
6576
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
        self._root = root
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
        self._cwd = cwd
6604
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
     7
        self._files = files
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
     8
        self._fmap = dict.fromkeys(files)
6576
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     9
        self._matchfn = mf
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    10
        self._anypats = ap
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
    def __call__(self, fn):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
        return self._matchfn(fn)
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
    def __iter__(self):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
        for f in self._files:
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
            yield f
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
    def bad(self, f, msg):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
        return True
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
    def dir(self, f):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    19
        pass
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
    def missing(self, f):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    21
        pass
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    22
    def exact(self, f):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
        return f in self._fmap
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    24
    def rel(self, f):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    25
        return util.pathto(self._root, self._cwd, f)
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    26
    def files(self):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    27
        return self._files
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    28
    def anypats(self):
69f3e9ac7c56 walk: introduce match objects
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    29
        return self._anypats
6596
7fe4610cf920 match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents: 6578
diff changeset
    30
6604
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    31
class always(_match):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    32
    def __init__(self, root, cwd):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    33
        _match.__init__(self, root, cwd, [], lambda f: True, False)
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    34
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    35
class never(_match):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    36
    def __init__(self, root, cwd):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    37
        _match.__init__(self, root, cwd, [], lambda f: False, False)
6596
7fe4610cf920 match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents: 6578
diff changeset
    38
6604
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    39
class exact(_match):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    40
    def __init__(self, root, cwd, files):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    41
        _match.__init__(self, root, cwd, files, lambda f: f in files, False)
6596
7fe4610cf920 match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents: 6578
diff changeset
    42
6604
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    43
class match(_match):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    44
    def __init__(self, root, cwd, patterns, include, exclude, default):
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    45
        f, mf, ap = util.matcher(root, cwd, patterns, include, exclude,
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    46
                                 None, default)
98b6e6f0e49b match: cleanup match classes a bit
Matt Mackall <mpm@selenic.com>
parents: 6596
diff changeset
    47
        _match.__init__(self, root, cwd, f, mf, ap)