# HG changeset patch # User Pierre-Yves David # Date 2021-07-07 22:54:40 # Node ID cce51119bfe64a5ad8c0367d5196bf448f8f5577 # Parent 305356a7ec99502dfbbf5c4c2277f84f08dac972 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 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 @@ class largefilesdirstate(dirstate.dirsta 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)) 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 @@ def wrapdirstate(repo, dirstate): 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/sparse.py b/hgext/sparse.py --- a/hgext/sparse.py +++ b/hgext/sparse.py @@ -257,6 +257,7 @@ def _setupdirstate(ui): editfuncs = [ b'normal', b'set_tracked', + b'set_untracked', b'add', b'normallookup', b'copy', diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -480,6 +480,25 @@ class dirstate(object): 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,