changeset 48134:bbd924a36a6e

dirstatemap: move a multiple simple functions in the common class These are small and simple, lets factor them out. Differential Revision: https://phab.mercurial-scm.org/D11567
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 02 Oct 2021 12:01:50 +0200
parents 5fc2dfb073d6
children 771c90807a2b
files mercurial/dirstatemap.py
diffstat 1 files changed, 24 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstatemap.py	Fri Oct 01 17:10:24 2021 +0200
+++ b/mercurial/dirstatemap.py	Sat Oct 02 12:01:50 2021 +0200
@@ -41,6 +41,11 @@
     class, with and without Rust extensions enabled.
     """
 
+    # please pytype
+
+    _map = None
+    copymap = None
+
     def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
         self._use_dirstate_v2 = use_dirstate_v2
         self._nodeconstants = nodeconstants
@@ -55,6 +60,25 @@
         # for consistent view between _pl() and _read() invocations
         self._pendingmode = None
 
+    def preload(self):
+        """Loads the underlying data, if it's not already loaded"""
+        self._map
+
+    def get(self, key, default=None):
+        return self._map.get(key, default)
+
+    def __len__(self):
+        return len(self._map)
+
+    def __iter__(self):
+        return iter(self._map)
+
+    def __contains__(self, key):
+        return key in self._map
+
+    def __getitem__(self, item):
+        return self._map[item]
+
 
 class dirstatemap(_dirstatemapcommon):
     """Map encapsulating the dirstate's contents.
@@ -135,28 +159,9 @@
         for (filename, item) in self.items():
             yield (filename, item.state, item.mode, item.size, item.mtime)
 
-    def __len__(self):
-        return len(self._map)
-
-    def __iter__(self):
-        return iter(self._map)
-
-    def get(self, key, default=None):
-        return self._map.get(key, default)
-
-    def __contains__(self, key):
-        return key in self._map
-
-    def __getitem__(self, key):
-        return self._map[key]
-
     def keys(self):
         return self._map.keys()
 
-    def preload(self):
-        """Loads the underlying data, if it's not already loaded"""
-        self._map
-
     def _dirs_incr(self, filename, old_entry=None):
         """incremente the dirstate counter if applicable"""
         if (
@@ -629,9 +634,6 @@
         def removefile(self, *args, **kwargs):
             return self._map.removefile(*args, **kwargs)
 
-        def get(self, *args, **kwargs):
-            return self._map.get(*args, **kwargs)
-
         @property
         def copymap(self):
             return self._map.copymap()
@@ -646,9 +648,6 @@
             """
             return self._map.debug_iter(all)
 
-        def preload(self):
-            self._map
-
         def clear(self):
             self._map.clear()
             self.setparents(
@@ -664,18 +663,6 @@
         def keys(self):
             return iter(self._map)
 
-        def __contains__(self, key):
-            return key in self._map
-
-        def __getitem__(self, item):
-            return self._map[item]
-
-        def __len__(self):
-            return len(self._map)
-
-        def __iter__(self):
-            return iter(self._map)
-
         # forward for python2,3 compat
         iteritems = items