Patchwork D11567: dirstatemap: move a multiple simple functions in the common class

login
register
mail settings
Submitter phabricator
Date Oct. 2, 2021, 3:04 p.m.
Message ID <differential-rev-PHID-DREV-p3btt55c3cdes6knu5rw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49890/
State Superseded
Headers show

Comments

phabricator - Oct. 2, 2021, 3:04 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  These are small and simple, lets factor them out.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -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