# HG changeset patch # User Pierre-Yves David # Date 2014-08-02 01:57:53 # Node ID afead12e724bb9d22ae80da148f4a892817f670a # Parent fb8065de47b064ff49b694f075e26ff937388962 revert: triage "deleted" files into more appropriate categories Status can return file as "deleted". This is only a special case related to working directory state: file is recorded as tracked but no file exists on disk. This will never be a state obtainable from manifest comparisons. "Deleted" files have another working directory status shadowed by the lack of file. They will -alway- be touched by revert. The "lack of file" can be seen as a modification. The file will never match the same "content" as in the revert target. From there we have two options: 1. The file exists in the target and can be seen as "modified". 2. The file does not exist in the target and can be seen as "added". So now we just dispatch elements from delete into appropriate categories. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2380,7 +2380,16 @@ def revert(ui, repo, ctx, parents, *pats modified = set(changes[0]) added = set(changes[1]) removed = set(changes[2]) - deleted = set(changes[3]) + _deleted = set(changes[3]) + + # split between files known in target manifest and the others + smf = set(mf) + + # determine the exact nature of the deleted changesets + _deletedadded = _deleted - smf + _deletedmodified = _deleted - _deletedadded + added |= _deletedadded + modified |= _deletedmodified # We need to account for the state of file in the dirstate # @@ -2397,6 +2406,8 @@ def revert(ui, repo, ctx, parents, *pats dsmodified = set(changes[0]) dsadded = set(changes[1]) dsremoved = set(changes[2]) + dsadded |= _deletedadded + dsmodified |= _deletedmodified # if f is a rename, update `names` to also revert the source cwd = repo.getcwd() @@ -2413,17 +2424,12 @@ def revert(ui, repo, ctx, parents, *pats return _('forgetting %s\n') return _('removing %s\n') - # split between files known in target manifest and the others - smf = set(mf) - missingmodified = dsmodified - smf dsmodified -= missingmodified missingadded = dsadded - smf dsadded -= missingadded missingremoved = dsremoved - smf dsremoved -= missingremoved - missingdeleted = deleted - smf - deleted -= missingdeleted # action to be actually performed by revert # (, message>) tuple @@ -2443,8 +2449,6 @@ def revert(ui, repo, ctx, parents, *pats (missingadded, (actions['remove'], False)), (dsremoved, (actions['undelete'], True)), (missingremoved, (None, False)), - (deleted, (actions['revert'], False)), - (missingdeleted, (actions['remove'], False)), ) for abs, (rel, exact) in sorted(names.items()):