D59: sparse: override dirstate.walk() instead of dirstate._ignore

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Jul 17 18:29:58 UTC 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG258298f4712b: sparse: override dirstate.walk() instead of dirstate._ignore (authored by martinvonz).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D59?vs=77&id=206

REVISION DETAIL
  https://phab.mercurial-scm.org/D59

AFFECTED FILES
  hgext/sparse.py
  tests/test-sparse.t

CHANGE DETAILS

diff --git a/tests/test-sparse.t b/tests/test-sparse.t
--- a/tests/test-sparse.t
+++ b/tests/test-sparse.t
@@ -144,10 +144,15 @@
   M show
 
   $ hg up -qC .
+TODO: add an option to purge to also purge files outside the sparse config?
   $ hg purge --all --config extensions.purge=
   $ ls
+  hide
+  hide3
   show
   show2
+For now, manually remove the files
+  $ rm hide hide3
 
 Verify rebase temporarily includes excluded files
 
diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -192,36 +192,11 @@
     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)
+    def walk(orig, self, match, subrepos, unknown, ignored, full=True):
+        match = matchmod.intersectmatchers(match, self._sparsematcher)
+        return orig(self, match, subrepos, unknown, ignored, full)
 
-            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)
+    extensions.wrapfunction(dirstate.dirstate, 'walk', walk)
 
     # dirstate.rebuild should not add non-matching files
     def _rebuild(orig, self, parent, allfiles, changedfiles=None):



EMAIL PREFERENCES
  https://phab.mercurial-scm.org/settings/panel/emailpreferences/

To: martinvonz, #hg, durham
Cc: durham, dsp, mercurial-devel


More information about the Mercurial-devel mailing list