Mercurial > hg
changeset 47608:3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
The adjustment in the direct consequence of the amend and the associated parents
change.
Differential Revision: https://phab.mercurial-scm.org/D11032
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 08 Jul 2021 21:26:21 +0200 |
parents | ff82edadc2e1 |
children | c8d6e23fb14a |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 24 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Thu Jul 08 21:20:37 2021 +0200 +++ b/mercurial/cmdutil.py Thu Jul 08 21:26:21 2021 +0200 @@ -2967,29 +2967,30 @@ newid = repo.commitctx(new) ms.reset() - # Reroute the working copy parent to the new changeset - repo.setparents(newid, repo.nullid) - - # Fixing the dirstate because localrepo.commitctx does not update - # it. This is rather convenient because we did not need to update - # the dirstate for all the files in the new commit which commitctx - # could have done if it updated the dirstate. Now, we can - # selectively update the dirstate only for the amended files. - dirstate = repo.dirstate - - # Update the state of the files which were added and modified in the - # amend to "normal" in the dirstate. We need to use "normallookup" since - # the files may have changed since the command started; using "normal" - # would mark them as clean but with uncommitted contents. - normalfiles = set(wctx.modified() + wctx.added()) & filestoamend - for f in normalfiles: - dirstate.normallookup(f) - - # Update the state of files which were removed in the amend - # to "removed" in the dirstate. - removedfiles = set(wctx.removed()) & filestoamend - for f in removedfiles: - dirstate.drop(f) + with repo.dirstate.parentchange(): + # Reroute the working copy parent to the new changeset + repo.setparents(newid, repo.nullid) + + # Fixing the dirstate because localrepo.commitctx does not update + # it. This is rather convenient because we did not need to update + # the dirstate for all the files in the new commit which commitctx + # could have done if it updated the dirstate. Now, we can + # selectively update the dirstate only for the amended files. + dirstate = repo.dirstate + + # Update the state of the files which were added and modified in the + # amend to "normal" in the dirstate. We need to use "normallookup" since + # the files may have changed since the command started; using "normal" + # would mark them as clean but with uncommitted contents. + normalfiles = set(wctx.modified() + wctx.added()) & filestoamend + for f in normalfiles: + dirstate.normallookup(f) + + # Update the state of files which were removed in the amend + # to "removed" in the dirstate. + removedfiles = set(wctx.removed()) & filestoamend + for f in removedfiles: + dirstate.drop(f) mapping = {old.node(): (newid,)} obsmetadata = None