changeset 47599:cce51119bfe6

dirstate: add a `set_untracked` method for "hg remove"-like usage This is a step further toward clarifying the semantic of various dirstate call. See the justification for adding `set_tracked` for details. Differential Revision: https://phab.mercurial-scm.org/D11019
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 08 Jul 2021 00:54:40 +0200
parents 305356a7ec99
children f636dfe83554
files hgext/largefiles/lfutil.py hgext/narrow/narrowdirstate.py hgext/sparse.py mercurial/dirstate.py
diffstat 4 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/lfutil.py	Thu Jul 08 04:32:31 2021 +0200
+++ b/hgext/largefiles/lfutil.py	Thu Jul 08 00:54:40 2021 +0200
@@ -165,6 +165,9 @@
     def set_tracked(self, f):
         return super(largefilesdirstate, self).set_tracked(unixpath(f))
 
+    def set_untracked(self, f):
+        return super(largefilesdirstate, self).set_untracked(unixpath(f))
+
     def normal(self, f):
         return super(largefilesdirstate, self).normal(unixpath(f))
 
--- a/hgext/narrow/narrowdirstate.py	Thu Jul 08 04:32:31 2021 +0200
+++ b/hgext/narrow/narrowdirstate.py	Thu Jul 08 00:54:40 2021 +0200
@@ -42,6 +42,10 @@
             return super(narrowdirstate, self).set_tracked(*args)
 
         @_editfunc
+        def set_untracked(self, *args):
+            return super(narrowdirstate, self).set_untracked(*args)
+
+        @_editfunc
         def add(self, *args):
             return super(narrowdirstate, self).add(*args)
 
--- a/hgext/sparse.py	Thu Jul 08 04:32:31 2021 +0200
+++ b/hgext/sparse.py	Thu Jul 08 00:54:40 2021 +0200
@@ -257,6 +257,7 @@
     editfuncs = [
         b'normal',
         b'set_tracked',
+        b'set_untracked',
         b'add',
         b'normallookup',
         b'copy',
--- a/mercurial/dirstate.py	Thu Jul 08 04:32:31 2021 +0200
+++ b/mercurial/dirstate.py	Thu Jul 08 00:54:40 2021 +0200
@@ -480,6 +480,25 @@
             return True
         return False
 
+    @requires_no_parents_change
+    def set_untracked(self, filename):
+        """a "public" method for generic code to mark a file as untracked
+
+        This function is to be called outside of "update/merge" case. For
+        example by a command like `hg remove X`.
+
+        return True the file was previously tracked, False otherwise.
+        """
+        entry = self._map.get(filename)
+        if entry is None:
+            return False
+        elif entry.added:
+            self._drop(filename)
+            return True
+        else:
+            self._remove(filename)
+            return True
+
     @requires_parents_change
     def update_file_reference(
         self,