D11129: dirstate-map: factor out the change to _dirs and _alldirs on adding

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Mon Jul 19 10:40:17 UTC 2021


marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -144,6 +144,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,
@@ -188,12 +197,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)



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


More information about the Mercurial-devel mailing list