dirstate: move the _dirfoldmap to dirstatemap
authorDurham Goode <durham@fb.com>
Thu, 05 Oct 2017 11:34:41 -0700
changeset 34678 e8a89ed7ce96
parent 34677 014bd2a555c8
child 34679 143337bcec9b
dirstate: move the _dirfoldmap to dirstatemap Now that dirstatemap is the source of truth for the list of directories, let's move _dirfoldmap on to it. This pattern of moving cached variables onto the dirstate map makes it easier to invalidate them, as seen by how the cache invalidation functions are slowly shrinking to just be recreating the dirstatemap instance. Differential Revision: https://phab.mercurial-scm.org/D983
contrib/perf.py
mercurial/dirstate.py
--- a/contrib/perf.py	Thu Oct 05 11:34:41 2017 -0700
+++ b/contrib/perf.py	Thu Oct 05 11:34:41 2017 -0700
@@ -560,8 +560,8 @@
     dirstate = repo.dirstate
     'a' in dirstate
     def d():
-        dirstate._dirfoldmap.get('a')
-        del dirstate._dirfoldmap
+        dirstate._map.dirfoldmap.get('a')
+        del dirstate._map.dirfoldmap
         del dirstate._map.dirs
     timer(d)
     fm.end()
--- a/mercurial/dirstate.py	Thu Oct 05 11:34:41 2017 -0700
+++ b/mercurial/dirstate.py	Thu Oct 05 11:34:41 2017 -0700
@@ -132,14 +132,6 @@
         self._read()
         return self._map
 
-    @propertycache
-    def _dirfoldmap(self):
-        f = {}
-        normcase = util.normcase
-        for name in self._map.dirs:
-            f[normcase(name)] = name
-        return f
-
     @property
     def _sparsematcher(self):
         """The matcher for the sparse checkout.
@@ -372,8 +364,7 @@
         rereads the dirstate. Use localrepo.invalidatedirstate() if you want to
         check whether the dirstate has changed before rereading it.'''
 
-        for a in ("_map", "_dirfoldmap", "_branch",
-                  "_ignore"):
+        for a in ("_map", "_branch", "_ignore"):
             if a in self.__dict__:
                 delattr(self, a)
         self._lastnormaltime = 0
@@ -568,7 +559,7 @@
         normed = util.normcase(path)
         folded = self._map.filefoldmap.get(normed, None)
         if folded is None:
-            folded = self._dirfoldmap.get(normed, None)
+            folded = self._map.dirfoldmap.get(normed, None)
         if folded is None:
             if isknown:
                 folded = path
@@ -576,7 +567,7 @@
                 # store discovered result in dirfoldmap so that future
                 # normalizefile calls don't start matching directories
                 folded = self._discoverpath(path, normed, ignoremissing, exists,
-                                            self._dirfoldmap)
+                                            self._map.dirfoldmap)
         return folded
 
     def normalize(self, path, isknown=False, ignoremissing=False):
@@ -875,7 +866,7 @@
                 if len(paths) > 1:
                     for path in paths:
                         folded = self._discoverpath(path, norm, True, None,
-                                                    self._dirfoldmap)
+                                                    self._map.dirfoldmap)
                         if path != folded:
                             results[path] = None
 
@@ -1396,3 +1387,10 @@
         self.read()
         return self.identity
 
+    @propertycache
+    def dirfoldmap(self):
+        f = {}
+        normcase = util.normcase
+        for name in self.dirs:
+            f[normcase(name)] = name
+        return f