Patchwork D11032: amend: adjust the dirstate withing a `parentchange` context

login
register
mail settings
Submitter phabricator
Date July 9, 2021, 11:04 a.m.
Message ID <differential-rev-PHID-DREV-5ben2hee67ebw42xq7nx-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49347/
State Superseded
Headers show

Comments

phabricator - July 9, 2021, 11:04 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The adjustment in the direct consequence of the amend and the associated parent
  change.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2972,29 +2972,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