Patchwork D11019: dirstate: add a set_untracked method for "hg remove"-like usage

login
register
mail settings
Submitter phabricator
Date July 8, 2021, 7:34 a.m.
Message ID <differential-rev-PHID-DREV-nwrv5k7jrccnh5j5babv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49332/
State Superseded
Headers show

Comments

phabricator - July 8, 2021, 7:34 a.m.
marmoute created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: martinvonz.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is a step further toward clarifying the semantic of various dirstate call.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/largefiles/lfutil.py
  hgext/narrow/narrowdirstate.py
  hgext/sparse.py
  mercurial/dirstate.py

CHANGE DETAILS




To: marmoute, durin42, martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -460,6 +460,27 @@ 
             return True
         return False
 
+    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.
+        """
+        if self._parentwriters > 0:
+            msg = b'calling set_tracked inside a parentchange context'
+            raise error.ProgrammingError(msg)
+        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
+
     def update_file_reference(
         self,
         filename,
diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -257,6 +257,7 @@ 
     editfuncs = [
         b'normal',
         b'set_tracked',
+        b'set_untracked',
         b'add',
         b'normallookup',
         b'copy',
diff --git a/hgext/narrow/narrowdirstate.py b/hgext/narrow/narrowdirstate.py
--- a/hgext/narrow/narrowdirstate.py
+++ b/hgext/narrow/narrowdirstate.py
@@ -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)
 
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -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))