D1342: dirstate: move management of the dirstate dirs into the dirstatemap

mbthomas (Mark Thomas) phabricator at mercurial-scm.org
Wed Nov 8 17:31:17 UTC 2017


mbthomas created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The dirstate dirs object is owned by the map, so move management of that object
  there.  A future implementation of the dirstate will manage the dirs object
  differently.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -387,9 +387,6 @@
         return self._map.copymap
 
     def _droppath(self, f):
-        if self[f] not in "?r" and "dirs" in self._map.__dict__:
-            self._map.dirs.delpath(f)
-
         if "filefoldmap" in self._map.__dict__:
             normed = util.normcase(f)
             if normed in self._map.filefoldmap:
@@ -411,11 +408,9 @@
                 if entry is not None and entry[0] != 'r':
                     raise error.Abort(
                         _('file %r in dirstate clashes with %r') % (d, f))
-        if oldstate in "?r" and "dirs" in self._map.__dict__:
-            self._map.dirs.addpath(f)
         self._dirty = True
         self._updatedfiles.add(f)
-        self._map.addfile(f, state, mode, size, mtime)
+        self._map.addfile(f, oldstate, state, mode, size, mtime)
 
     def normal(self, f):
         '''Mark a file normal and clean.'''
@@ -476,6 +471,7 @@
         '''Mark a file removed.'''
         self._dirty = True
         self._droppath(f)
+        oldstate = self[f]
         size = 0
         if self._pl[1] != nullid:
             entry = self._map.get(f)
@@ -486,7 +482,7 @@
                 elif entry[0] == 'n' and entry[2] == -2: # other parent
                     size = -2
                     self._map.otherparentset.add(f)
-        self._map.removefile(f, size)
+        self._map.removefile(f, oldstate, size)
         if size == 0:
             self._map.copymap.pop(f, None)
 
@@ -498,7 +494,8 @@
 
     def drop(self, f):
         '''Drop a file from the dirstate'''
-        if self._map.dropfile(f):
+        oldstate = self[f]
+        if self._map.dropfile(f, oldstate):
             self._dirty = True
             self._droppath(f)
             self._map.copymap.pop(f, None)
@@ -1241,32 +1238,38 @@
         """Loads the underlying data, if it's not already loaded"""
         self._map
 
-    def addfile(self, f, state, mode, size, mtime):
+    def addfile(self, f, oldstate, state, mode, size, mtime):
         """Add a tracked file to the dirstate."""
+        if oldstate in "?r" and "dirs" in self.__dict__:
+            self.dirs.addpath(f)
         self._map[f] = dirstatetuple(state, mode, size, mtime)
         if state != 'n' or mtime == -1:
             self.nonnormalset.add(f)
         if size == -2:
             self.otherparentset.add(f)
 
-    def removefile(self, f, size):
+    def removefile(self, f, oldstate, size):
         """
         Mark a file as removed in the dirstate.
 
         The `size` parameter is used to store sentinel values that indicate
         the file's previous state.  In the future, we should refactor this
         to be more explicit about what that state is.
         """
+        if oldstate not in "?r" and "dirs" in self.__dict__:
+            self.dirs.delpath(f)
         self._map[f] = dirstatetuple('r', 0, size, 0)
         self.nonnormalset.add(f)
 
-    def dropfile(self, f):
+    def dropfile(self, f, oldstate):
         """
         Remove a file from the dirstate.  Returns True if the file was
         previously recorded.
         """
         exists = f in self._map
         if exists:
+            if oldstate != "r" and "dirs" in self.__dict__:
+                self.dirs.delpath(f)
             del self._map[f]
         self.nonnormalset.discard(f)
         return exists



To: mbthomas, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list