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

login
register
mail settings
Submitter phabricator
Date Nov. 17, 2017, 10:29 p.m.
Message ID <bd7670aa19d58b353eb6f9080252bde1@localhost.localdomain>
Download mbox | patch
Permalink /patch/25627/
State Not Applicable
Headers show

Comments

phabricator - Nov. 17, 2017, 10:29 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG7e93c8c71502: dirstate: move management of the dirstate dirs into the dirstatemap (authored by mbthomas, committed by ).

REPOSITORY
  rHG Mercurial

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

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS




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

Patch

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)
@@ -1217,8 +1214,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):
@@ -1280,31 +1277,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 = self._map.pop(f, None) is not None
+        if exists:
+            if oldstate != "r" and "dirs" in self.__dict__:
+                self.dirs.delpath(f)
         self.nonnormalset.discard(f)
         return exists