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

login
register
mail settings
Submitter phabricator
Date July 19, 2021, 10:40 a.m.
Message ID <differential-rev-PHID-DREV-bzofl3fzajqx5ehehvqt-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49442/
State Superseded
Headers show

Comments

phabricator - July 19, 2021, 10:40 a.m.
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




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
@@ -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)