dirstate-map: factor out the change to _dirs and _alldirs on adding
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 15 Jul 2021 01:58:31 +0200
changeset 47687 e59bd6723f2f
parent 47686 e43128ee436f
child 47688 b37ab6b5c438
dirstate-map: factor out the change to _dirs and _alldirs on adding This logic is complicated enough to deserves its own function. So it now does. This will make it easier to reuse that logic in later changeset. Differential Revision: https://phab.mercurial-scm.org/D11129
mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py	Wed Jul 14 22:06:13 2021 +0200
+++ b/mercurial/dirstatemap.py	Thu Jul 15 01:58:31 2021 +0200
@@ -146,6 +146,15 @@
         """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 (
+            old_entry is None or old_entry.removed
+        ) and "_dirs" in self.__dict__:
+            self._dirs.addpath(filename)
+        if old_entry is None and "_alldirs" in self.__dict__:
+            self._alldirs.addpath(filename)
+
     def addfile(
         self,
         f,
@@ -190,12 +199,7 @@
         assert size is not None
         assert mtime is not None
         old_entry = self.get(f)
-        if (
-            old_entry is None or old_entry.removed
-        ) and "_dirs" in self.__dict__:
-            self._dirs.addpath(f)
-        if old_entry is None and "_alldirs" in self.__dict__:
-            self._alldirs.addpath(f)
+        self._dirs_incr(f, old_entry)
         e = self._map[f] = DirstateItem(state, mode, size, mtime)
         if e.dm_nonnormal:
             self.nonnormalset.add(f)