strip: use a `changing_parents` context for --keep update
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 19 Feb 2023 02:50:46 +0100
changeset 50161 62158471d038
parent 50160 0ca8dc8a135f
child 50162 dae8dda6f582
strip: use a `changing_parents` context for --keep update These are now properly scoped. note: it would be neat to reuse this in `hg rollback`.
mercurial/strip.py
--- a/mercurial/strip.py	Sun Feb 19 02:47:28 2023 +0100
+++ b/mercurial/strip.py	Sun Feb 19 02:50:46 2023 +0100
@@ -241,31 +241,32 @@
 
         revs = sorted(rootnodes)
         if update and opts.get(b'keep'):
-            urev = _findupdatetarget(repo, revs)
-            uctx = repo[urev]
+            with repo.dirstate.changing_parents(repo):
+                urev = _findupdatetarget(repo, revs)
+                uctx = repo[urev]
 
-            # only reset the dirstate for files that would actually change
-            # between the working context and uctx
-            descendantrevs = repo.revs(b"only(., %d)", uctx.rev())
-            changedfiles = []
-            for rev in descendantrevs:
-                # blindly reset the files, regardless of what actually changed
-                changedfiles.extend(repo[rev].files())
+                # only reset the dirstate for files that would actually change
+                # between the working context and uctx
+                descendantrevs = repo.revs(b"only(., %d)", uctx.rev())
+                changedfiles = []
+                for rev in descendantrevs:
+                    # blindly reset the files, regardless of what actually changed
+                    changedfiles.extend(repo[rev].files())
 
-            # reset files that only changed in the dirstate too
-            dirstate = repo.dirstate
-            dirchanges = [
-                f for f in dirstate if not dirstate.get_entry(f).maybe_clean
-            ]
-            changedfiles.extend(dirchanges)
+                # reset files that only changed in the dirstate too
+                dirstate = repo.dirstate
+                dirchanges = [
+                    f for f in dirstate if not dirstate.get_entry(f).maybe_clean
+                ]
+                changedfiles.extend(dirchanges)
 
-            repo.dirstate.rebuild(urev, uctx.manifest(), changedfiles)
-            repo.dirstate.write(repo.currenttransaction())
+                repo.dirstate.rebuild(urev, uctx.manifest(), changedfiles)
+                repo.dirstate.write(repo.currenttransaction())
 
-            # clear resolve state
-            mergestatemod.mergestate.clean(repo)
+                # clear resolve state
+                mergestatemod.mergestate.clean(repo)
 
-            update = False
+                update = False
 
         strip(
             ui,