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

mbthomas (Mark Thomas) phabricator at mercurial-scm.org
Mon Nov 13 07:18:21 EST 2017


mbthomas updated this revision to Diff 3439.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1342?vs=3342&id=3439

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)
@@ -1219,8 +1216,8 @@
     - `dirfoldmap` is a dict mapping normalized directory names to the
       denormalized form that they appear as in the dirstate.
 
-    Once instantiated, the dirs, filefoldmap and dirfoldmap views must be
-    maintained by the caller.
+    Once instantiated, the filefoldmap and dirfoldmap views must be maintained
+    by the caller.
     '''
 
     def __init__(self, ui, opener, root):
@@ -1282,32 +1279,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