@@ -78,11 +78,9 @@ from mercurial.i18n import _
from mercurial import (
cmdutil,
commands,
- dirstate,
error,
extensions,
hg,
- match as matchmod,
registrar,
sparse,
util,
@@ -103,23 +101,6 @@ def extsetup(ui):
_setupclone(ui)
_setuplog(ui)
_setupadd(ui)
- _setupdirstate(ui)
-
-def replacefilecache(cls, propname, replacement):
- """Replace a filecache property with a new class. This allows changing the
- cache invalidation condition."""
- origcls = cls
- assert callable(replacement)
- while cls is not object:
- if propname in cls.__dict__:
- orig = cls.__dict__[propname]
- setattr(cls, propname, replacement(orig))
- break
- cls = cls.__bases__[0]
-
- if cls is object:
- raise AttributeError(_("type '%s' has no property '%s'") % (origcls,
- propname))
def _setuplog(ui):
entry = commands.table['^log|history']
@@ -187,42 +168,6 @@ def _setupadd(ui):
extensions.wrapcommand(commands.table, 'add', _add)
-def _setupdirstate(ui):
- """Modify the dirstate to prevent stat'ing excluded files,
- and to prevent modifications to files outside the checkout.
- """
-
- # The atrocity below is needed to wrap dirstate._ignore. It is a cached
- # property, which means normal function wrapping doesn't work.
- class ignorewrapper(object):
- def __init__(self, orig):
- self.orig = orig
- self.origignore = None
- self.func = None
- self.sparsematch = None
-
- def __get__(self, obj, type=None):
- origignore = self.orig.__get__(obj)
-
- sparsematch = obj._sparsematcher
- if sparsematch.always():
- return origignore
-
- if self.sparsematch != sparsematch or self.origignore != origignore:
- self.func = matchmod.unionmatcher([
- origignore, matchmod.negatematcher(sparsematch)])
- self.sparsematch = sparsematch
- self.origignore = origignore
- return self.func
-
- def __set__(self, obj, value):
- return self.orig.__set__(obj, value)
-
- def __delete__(self, obj):
- return self.orig.__delete__(obj)
-
- replacefilecache(dirstate.dirstate, '_ignore', ignorewrapper)
-
@command('^debugsparse', [
('I', 'include', False, _('include files in the sparse checkout')),
('X', 'exclude', False, _('exclude files in the sparse checkout')),
@@ -248,7 +248,7 @@ class dirstate(object):
return self._dirs
@rootcache('.hgignore')
- def _ignore(self):
+ def _hgignorematch(self):
files = self._ignorefiles()
if not files:
return matchmod.never(self._root, '')
@@ -256,6 +256,15 @@ class dirstate(object):
pats = ['include:%s' % f for f in files]
return matchmod.match(self._root, '', [], pats, warn=self._ui.warn)
+ @property
+ def _ignore(self):
+ sparsematch = self._sparsematcher
+ if sparsematch.always():
+ return self._hgignorematch
+
+ return matchmod.unionmatcher([self._hgignorematch,
+ matchmod.negatematcher(sparsematch)])
+
@propertycache
def _slash(self):
return self._ui.configbool('ui', 'slash') and pycompat.ossep != '/'
@@ -516,7 +525,7 @@ class dirstate(object):
for a in ("_map", "_copymap", "_identity",
"_filefoldmap", "_dirfoldmap", "_branch",
- "_pl", "_dirs", "_ignore", "_nonnormalset",
+ "_pl", "_dirs", "_hgignorematcher", "_nonnormalset",
"_otherparentset"):
if a in self.__dict__:
delattr(self, a)