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. Having a dedicated function comes with a couple of benefits: 1. we can move duplicated logic about how to handle the previous state within the dirstate. Since we are sure this is always called in the same situation, we can implement that logic once in the dirstate. 2. having a dedicated method for this case unlock having a dedicated method for the other case and recording more information at that time. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D11013 AFFECTED FILES hgext/largefiles/lfutil.py hgext/narrow/narrowdirstate.py hgext/sparse.py mercurial/dirstate.py CHANGE DETAILS diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -440,6 +440,26 @@ def copies(self): return self._map.copymap + def set_tracked(self, filename): + """a "public" method for generic code to mark a file as tracked + + This function is to be called outside of "update/merge" case. For + example by a command like `hg add X`. + + return True the file was previously untracked, 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: + self._add(filename) + return True + elif not entry.tracked: + self.normallookup(filename) + return True + return False + def update_file_reference( self, filename, diff --git a/hgext/sparse.py b/hgext/sparse.py --- a/hgext/sparse.py +++ b/hgext/sparse.py @@ -256,6 +256,7 @@ # Prevent adding files that are outside the sparse checkout editfuncs = [ b'normal', + b'set_tracked', 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 @@ -38,6 +38,10 @@ return super(narrowdirstate, self).normal(*args, **kwargs) @_editfunc + def set_tracked(self, *args): + return super(narrowdirstate, self).set_tracked(*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 @@ -162,6 +162,9 @@ def __getitem__(self, key): return super(largefilesdirstate, self).__getitem__(unixpath(key)) + def set_tracked(self, f): + return super(largefilesdirstate, self).set_tracked(unixpath(f)) + def normal(self, f): return super(largefilesdirstate, self).normal(unixpath(f)) To: marmoute, durin42, martinvonz, #hg-reviewers Cc: mercurial-patches, mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel