changeset 47972:5a6c1ef4bcac

dirstate: make dirstatemap.set_untracked deal with added file This merge dropfile in set_untracked. Differential Revision: https://phab.mercurial-scm.org/D11419
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 02 Sep 2021 02:53:47 +0200
parents c0157aca5bf5
children 2e0ff3947b05
files mercurial/dirstate.py mercurial/dirstatemap.py
diffstat 2 files changed, 29 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Thu Sep 02 02:48:56 2021 +0200
+++ b/mercurial/dirstate.py	Thu Sep 02 02:53:47 2021 +0200
@@ -493,17 +493,11 @@
 
         return True the file was previously tracked, False otherwise.
         """
-        entry = self._map.get(filename)
-        if entry is None:
-            return False
-        else:
+        ret = self._map.set_untracked(filename)
+        if ret:
             self._dirty = True
             self._updatedfiles.add(filename)
-            if entry.added:
-                self._map.dropfile(filename)
-            else:
-                self._map.set_untracked(filename)
-            return True
+        return ret
 
     @requires_no_parents_change
     def set_clean(self, filename, parentfiledata=None):
--- a/mercurial/dirstatemap.py	Thu Sep 02 02:48:56 2021 +0200
+++ b/mercurial/dirstatemap.py	Thu Sep 02 02:53:47 2021 +0200
@@ -299,14 +299,22 @@
 
     def set_untracked(self, f):
         """Mark a file as no longer tracked in the dirstate map"""
-        entry = self[f]
-        self._dirs_decr(f, old_entry=entry, remove_variant=True)
-        if entry.from_p2:
-            self.otherparentset.add(f)
-        elif not entry.merged:
-            self.copymap.pop(f, None)
-        entry.set_untracked()
-        self.nonnormalset.add(f)
+        entry = self.get(f)
+        if entry is None:
+            return False
+        else:
+            self._dirs_decr(f, old_entry=entry, remove_variant=not entry.added)
+            if not entry.merged:
+                self.copymap.pop(f, None)
+            if entry.added:
+                self.nonnormalset.discard(f)
+                self._map.pop(f, None)
+            else:
+                self.nonnormalset.add(f)
+                if entry.from_p2:
+                    self.otherparentset.add(f)
+                entry.set_untracked()
+            return True
 
     def dropfile(self, f):
         """
@@ -648,7 +656,16 @@
             #
             # the inner rust dirstate map code need to be adjusted once the API
             # for dirstate/dirstatemap/DirstateItem is a bit more settled
-            self._rustmap.removefile(f, in_merge=True)
+            entry = self.get(f)
+            if entry is None:
+                return False
+            else:
+                if entry.added:
+                    self._rustmap.copymap().pop(f, None)
+                    self._rustmap.dropfile(f)
+                else:
+                    self._rustmap.removefile(f, in_merge=True)
+                return True
 
         def removefile(self, *args, **kwargs):
             return self._rustmap.removefile(*args, **kwargs)