changeset 49960:c166b212bdee

dirstate: pass the repo to the `changeparent` method If we want the context to be responsible for writing (and we want it), we need to have access to a localrepository object. So we now requires a localrepository object as an argument to this context manager.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 25 Jan 2023 18:46:20 +0100
parents 376395868b7b
children 7a8bfc05b691
files hgext/absorb.py hgext/fix.py hgext/git/dirstate.py hgext/keyword.py hgext/largefiles/lfcommands.py hgext/largefiles/lfutil.py hgext/largefiles/overrides.py hgext/mq.py hgext/narrow/narrowcommands.py hgext/split.py hgext/uncommit.py hgext/win32text.py mercurial/cmdutil.py mercurial/commands.py mercurial/context.py mercurial/dirstate.py mercurial/interfaces/dirstate.py mercurial/merge.py mercurial/shelve.py mercurial/sparse.py tests/test-narrow-expanddirstate.t tests/test-rebuildstate.t
diffstat 22 files changed, 45 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/absorb.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/absorb.py	Wed Jan 25 18:46:20 2023 +0100
@@ -881,7 +881,7 @@
 
             dirstate._fsmonitorstate.invalidate = noop
         try:
-            with dirstate.parentchange():
+            with dirstate.parentchange(self.repo):
                 dirstate.rebuild(ctx.node(), ctx.manifest(), self.paths)
         finally:
             restore()
--- a/hgext/fix.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/fix.py	Wed Jan 25 18:46:20 2023 +0100
@@ -776,7 +776,7 @@
     newp1 = replacements.get(oldp1, oldp1)
     if newp1 != oldp1:
         assert repo.dirstate.p2() == nullid
-        with repo.dirstate.parentchange():
+        with repo.dirstate.parentchange(repo):
             scmutil.movedirstate(repo, repo[newp1])
 
 
--- a/hgext/git/dirstate.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/git/dirstate.py	Wed Jan 25 18:46:20 2023 +0100
@@ -384,7 +384,7 @@
         pass
 
     @contextlib.contextmanager
-    def parentchange(self):
+    def parentchange(self, repo):
         # TODO: track this maybe?
         yield
 
--- a/hgext/keyword.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/keyword.py	Wed Jan 25 18:46:20 2023 +0100
@@ -696,7 +696,7 @@
     kwt = getattr(repo, '_keywordkwt', None)
     if kwt is None:
         return orig(ui, repo, old, extra, pats, opts)
-    with repo.wlock(), repo.dirstate.parentchange():
+    with repo.wlock(), repo.dirstate.parentchange(repo):
         kwt.postcommit = True
         newid = orig(ui, repo, old, extra, pats, opts)
         if newid != old.node():
@@ -762,7 +762,7 @@
         if ctx != recctx:
             modified, added = _preselect(wstatus, recctx.files())
             kwt.restrict = False
-            with repo.dirstate.parentchange():
+            with repo.dirstate.parentchange(repo):
                 kwt.overwrite(recctx, modified, False, True)
                 kwt.overwrite(recctx, added, False, True, True)
             kwt.restrict = True
--- a/hgext/largefiles/lfcommands.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/largefiles/lfcommands.py	Wed Jan 25 18:46:20 2023 +0100
@@ -517,7 +517,7 @@
             filelist = set(filelist)
             lfiles = [f for f in lfiles if f in filelist]
 
-        with lfdirstate.parentchange():
+        with lfdirstate.parentchange(repo):
             update = {}
             dropped = set()
             updated, removed = 0, 0
@@ -580,7 +580,7 @@
             statuswriter(_(b'getting changed largefiles\n'))
             cachelfiles(ui, repo, None, lfiles)
 
-        with lfdirstate.parentchange():
+        with lfdirstate.parentchange(repo):
             for lfile in lfiles:
                 update1 = 0
 
--- a/hgext/largefiles/lfutil.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/largefiles/lfutil.py	Wed Jan 25 18:46:20 2023 +0100
@@ -231,7 +231,7 @@
         if len(standins) > 0:
             vfs.makedirs(lfstoredir)
 
-        with lfdirstate.parentchange():
+        with lfdirstate.parentchange(repo):
             for standin in standins:
                 lfile = splitstandin(standin)
                 lfdirstate.update_file(
@@ -581,7 +581,7 @@
     repo = ctx.repo()
 
     lfdirstate = openlfdirstate(repo.ui, repo)
-    with lfdirstate.parentchange():
+    with lfdirstate.parentchange(repo):
         orig(node)
 
         # ATTENTION: "ctx.files()" may differ from "repo[node].files()"
--- a/hgext/largefiles/overrides.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/largefiles/overrides.py	Wed Jan 25 18:46:20 2023 +0100
@@ -660,7 +660,7 @@
 def mergerecordupdates(orig, repo, actions, branchmerge, getfiledata):
     if MERGE_ACTION_LARGEFILE_MARK_REMOVED in actions:
         lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
-        with lfdirstate.parentchange():
+        with lfdirstate.parentchange(repo):
             for lfile, args, msg in actions[
                 MERGE_ACTION_LARGEFILE_MARK_REMOVED
             ]:
@@ -1800,7 +1800,7 @@
             raise error.ProgrammingError(
                 b'largefiles is not compatible with in-memory merge'
             )
-        with lfdirstate.parentchange():
+        with lfdirstate.parentchange(repo):
             result = orig(repo, node, branchmerge, force, *args, **kwargs)
 
             newstandins = lfutil.getstandinsstate(repo)
--- a/hgext/mq.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/mq.py	Wed Jan 25 18:46:20 2023 +0100
@@ -1082,7 +1082,7 @@
 
             if merge and files:
                 # Mark as removed/merged and update dirstate parent info
-                with repo.dirstate.parentchange():
+                with repo.dirstate.parentchange(repo):
                     for f in files:
                         repo.dirstate.update_file_p1(f, p1_tracked=True)
                     p1 = repo.dirstate.p1()
@@ -1830,7 +1830,7 @@
                 if keepchanges and tobackup:
                     raise error.Abort(_(b"local changes found, qrefresh first"))
                 self.backup(repo, tobackup)
-                with repo.dirstate.parentchange():
+                with repo.dirstate.parentchange(repo):
                     for f in a:
                         repo.wvfs.unlinkpath(f, ignoremissing=True)
                         repo.dirstate.update_file(
@@ -1988,7 +1988,7 @@
 
             bmlist = repo[top].bookmarks()
 
-            with repo.dirstate.parentchange():
+            with repo.dirstate.parentchange(repo):
                 # XXX do we actually need the dirstateguard
                 dsguard = None
                 try:
--- a/hgext/narrow/narrowcommands.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/narrow/narrowcommands.py	Wed Jan 25 18:46:20 2023 +0100
@@ -320,7 +320,7 @@
                 repo.store.markremoved(f)
 
             ui.status(_(b'deleting unwanted files from working copy\n'))
-            with repo.dirstate.parentchange():
+            with repo.dirstate.parentchange(repo):
                 narrowspec.updateworkingcopy(repo, assumeclean=True)
                 narrowspec.copytoworkingcopy(repo)
 
@@ -380,7 +380,7 @@
         if ellipsesremote:
             ds = repo.dirstate
             p1, p2 = ds.p1(), ds.p2()
-            with ds.parentchange():
+            with ds.parentchange(repo):
                 ds.setparents(repo.nullid, repo.nullid)
         if isoldellipses:
             with wrappedextraprepare:
@@ -419,10 +419,10 @@
                 bundle2.processbundle(repo, bundle, op=op, remote=remote)
 
         if ellipsesremote:
-            with ds.parentchange():
+            with ds.parentchange(repo):
                 ds.setparents(p1, p2)
 
-        with repo.transaction(b'widening'), repo.dirstate.parentchange():
+        with repo.transaction(b'widening'), repo.dirstate.parentchange(repo):
             repo.setnewnarrowpats()
             narrowspec.updateworkingcopy(repo)
             narrowspec.copytoworkingcopy(repo)
@@ -591,7 +591,7 @@
     if update_working_copy:
         with repo.wlock(), repo.lock(), repo.transaction(
             b'narrow-wc'
-        ), repo.dirstate.parentchange():
+        ), repo.dirstate.parentchange(repo):
             narrowspec.updateworkingcopy(repo)
             narrowspec.copytoworkingcopy(repo)
         return 0
--- a/hgext/split.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/split.py	Wed Jan 25 18:46:20 2023 +0100
@@ -134,7 +134,7 @@
     # Set working parent to ctx.p1(), and keep working copy as ctx's content
     if ctx.node() != repo.dirstate.p1():
         hg.clean(repo, ctx.node(), show_stats=False)
-    with repo.dirstate.parentchange():
+    with repo.dirstate.parentchange(repo):
         scmutil.movedirstate(repo, ctx.p1())
 
     # Any modified, added, removed, deleted result means split is incomplete
--- a/hgext/uncommit.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/uncommit.py	Wed Jan 25 18:46:20 2023 +0100
@@ -236,7 +236,7 @@
                 # Fully removed the old commit
                 mapping[old.node()] = ()
 
-            with repo.dirstate.parentchange():
+            with repo.dirstate.parentchange(repo):
                 scmutil.movedirstate(repo, repo[newid], match)
 
             scmutil.cleanupnodes(repo, mapping, b'uncommit', fixphase=True)
@@ -317,7 +317,7 @@
         newpredctx = repo[newprednode]
         dirstate = repo.dirstate
 
-        with dirstate.parentchange():
+        with dirstate.parentchange(repo):
             scmutil.movedirstate(repo, newpredctx)
 
         mapping = {curctx.node(): (newprednode,)}
--- a/hgext/win32text.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/hgext/win32text.py	Wed Jan 25 18:46:20 2023 +0100
@@ -216,7 +216,7 @@
 def wrap_revert(orig, repo, ctx, names, uipathfn, actions, *args, **kwargs):
     # reset dirstate cache for file we touch
     ds = repo.dirstate
-    with ds.parentchange():
+    with ds.parentchange(repo):
         for filename in actions[b'revert'][0]:
             entry = ds.get_entry(filename)
             if entry is not None:
--- a/mercurial/cmdutil.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/cmdutil.py	Wed Jan 25 18:46:20 2023 +0100
@@ -638,7 +638,7 @@
                         # already called within a `pendingchange`, However we
                         # are taking a shortcut here in order to be able to
                         # quickly deprecated the older API.
-                        with dirstate.parentchange():
+                        with dirstate.parentchange(repo):
                             dirstate.update_file(
                                 realname,
                                 p1_tracked=True,
@@ -1532,7 +1532,7 @@
                 new_node = mem_ctx.commit()
 
                 if repo.dirstate.p1() == ctx.node():
-                    with repo.dirstate.parentchange():
+                    with repo.dirstate.parentchange(repo):
                         scmutil.movedirstate(repo, repo[new_node])
                 replacements = {ctx.node(): [new_node]}
                 scmutil.cleanupnodes(
@@ -1625,7 +1625,7 @@
             new_node = mem_ctx.commit()
 
             if repo.dirstate.p1() == ctx.node():
-                with repo.dirstate.parentchange():
+                with repo.dirstate.parentchange(repo):
                     scmutil.movedirstate(repo, repo[new_node])
             replacements = {ctx.node(): [new_node]}
             scmutil.cleanupnodes(repo, replacements, b'copy', fixphase=True)
@@ -3024,7 +3024,7 @@
         newid = repo.commitctx(new)
         ms.reset()
 
-        with repo.dirstate.parentchange():
+        with repo.dirstate.parentchange(repo):
             # Reroute the working copy parent to the new changeset
             repo.setparents(newid, repo.nullid)
 
--- a/mercurial/commands.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/commands.py	Wed Jan 25 18:46:20 2023 +0100
@@ -6264,7 +6264,7 @@
         #
         # All this should eventually happens, but in the mean time, we use this
         # context manager slightly out of the context it should be.
-        with repo.dirstate.parentchange():
+        with repo.dirstate.parentchange(repo):
             mergestatemod.recordupdates(repo, ms.actions(), branchmerge, None)
 
         if not didwork and pats:
--- a/mercurial/context.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/context.py	Wed Jan 25 18:46:20 2023 +0100
@@ -1595,7 +1595,7 @@
         if p2node is None:
             p2node = self._repo.nodeconstants.nullid
         dirstate = self._repo.dirstate
-        with dirstate.parentchange():
+        with dirstate.parentchange(self._repo):
             copies = dirstate.setparents(p1node, p2node)
             pctx = self._repo[p1node]
             if copies:
@@ -2050,7 +2050,7 @@
         return sorted(f for f in ds.matches(match) if ds.get_entry(f).tracked)
 
     def markcommitted(self, node):
-        with self._repo.dirstate.parentchange():
+        with self._repo.dirstate.parentchange(self._repo):
             for f in self.modified() + self.added():
                 self._repo.dirstate.update_file(
                     f, p1_tracked=True, wc_tracked=True
--- a/mercurial/dirstate.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/dirstate.py	Wed Jan 25 18:46:20 2023 +0100
@@ -151,7 +151,7 @@
         self._pl
 
     @contextlib.contextmanager
-    def parentchange(self):
+    def parentchange(self, repo):
         """Context manager for handling dirstate parents.
 
         If an exception occurs in the scope of the context manager,
@@ -523,7 +523,7 @@
         rewriting operation.
 
         It should not be called during a merge (p2 != nullid) and only within
-        a `with dirstate.parentchange():` context.
+        a `with dirstate.parentchange(repo):` context.
         """
         if self.in_merge:
             msg = b'update_file_reference should not be called when merging'
--- a/mercurial/interfaces/dirstate.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/interfaces/dirstate.py	Wed Jan 25 18:46:20 2023 +0100
@@ -35,7 +35,7 @@
     _checkexec = interfaceutil.Attribute("""Callable for checking exec bits.""")
 
     @contextlib.contextmanager
-    def parentchange():
+    def parentchange(repo):
         """Context manager for handling dirstate parents.
 
         If an exception occurs in the scope of the context manager,
--- a/mercurial/merge.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/merge.py	Wed Jan 25 18:46:20 2023 +0100
@@ -2155,7 +2155,7 @@
             assert len(getfiledata) == (
                 mresult.len((mergestatemod.ACTION_GET,)) if wantfiledata else 0
             )
-            with repo.dirstate.parentchange():
+            with repo.dirstate.parentchange(repo):
                 ### Filter Filedata
                 #
                 # We gathered "cache" information for the clean file while
@@ -2377,7 +2377,7 @@
         # fix up dirstate for copies and renames
         copies.graftcopies(wctx, ctx, base)
     else:
-        with repo.dirstate.parentchange():
+        with repo.dirstate.parentchange(repo):
             repo.setparents(pctx.node(), pother)
             repo.dirstate.write(repo.currenttransaction())
             # fix up dirstate for copies and renames
--- a/mercurial/shelve.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/shelve.py	Wed Jan 25 18:46:20 2023 +0100
@@ -637,7 +637,7 @@
 
         ui.status(_(b'shelved as %s\n') % name)
         if opts[b'keep']:
-            with repo.dirstate.parentchange():
+            with repo.dirstate.parentchange(repo):
                 scmutil.movedirstate(repo, parent, match)
         else:
             hg.update(repo, parent.node())
@@ -862,14 +862,14 @@
         shelvectx = repo[state.parents[1]]
         pendingctx = state.pendingctx
 
-        with repo.dirstate.parentchange():
+        with repo.dirstate.parentchange(repo):
             repo.setparents(state.pendingctx.node(), repo.nullid)
             repo.dirstate.write(repo.currenttransaction())
 
         targetphase = _target_phase(repo)
         overrides = {(b'phases', b'new-commit'): targetphase}
         with repo.ui.configoverride(overrides, b'unshelve'):
-            with repo.dirstate.parentchange():
+            with repo.dirstate.parentchange(repo):
                 repo.setparents(state.parents[0], repo.nullid)
                 newnode, ispartialunshelve = _createunshelvectx(
                     ui, repo, shelvectx, basename, interactive, opts
@@ -1068,7 +1068,7 @@
             )
             raise error.ConflictResolutionRequired(b'unshelve')
 
-        with repo.dirstate.parentchange():
+        with repo.dirstate.parentchange(repo):
             repo.setparents(tmpwctx.node(), repo.nullid)
             newnode, ispartialunshelve = _createunshelvectx(
                 ui, repo, shelvectx, basename, interactive, opts
--- a/mercurial/sparse.py	Tue Dec 13 10:00:04 2022 +0100
+++ b/mercurial/sparse.py	Wed Jan 25 18:46:20 2023 +0100
@@ -451,7 +451,7 @@
                     message,
                 )
 
-        with repo.dirstate.parentchange():
+        with repo.dirstate.parentchange(repo):
             mergemod.applyupdates(
                 repo,
                 tmresult,
@@ -655,7 +655,7 @@
     The remaining sparse config only has profiles, if defined. The working
     directory is refreshed, as needed.
     """
-    with repo.wlock(), repo.dirstate.parentchange():
+    with repo.wlock(), repo.dirstate.parentchange(repo):
         raw = repo.vfs.tryread(b'sparse')
         includes, excludes, profiles = parseconfig(repo.ui, raw, b'sparse')
 
@@ -671,7 +671,7 @@
     The updated sparse config is written out and the working directory
     is refreshed, as needed.
     """
-    with repo.wlock(), repo.dirstate.parentchange():
+    with repo.wlock(), repo.dirstate.parentchange(repo):
         # read current configuration
         raw = repo.vfs.tryread(b'sparse')
         includes, excludes, profiles = parseconfig(repo.ui, raw, b'sparse')
@@ -730,7 +730,7 @@
 
     The new config is written out and a working directory refresh is performed.
     """
-    with repo.wlock(), repo.lock(), repo.dirstate.parentchange():
+    with repo.wlock(), repo.lock(), repo.dirstate.parentchange(repo):
         raw = repo.vfs.tryread(b'sparse')
         oldinclude, oldexclude, oldprofiles = parseconfig(
             repo.ui, raw, b'sparse'
--- a/tests/test-narrow-expanddirstate.t	Tue Dec 13 10:00:04 2022 +0100
+++ b/tests/test-narrow-expanddirstate.t	Wed Jan 25 18:46:20 2023 +0100
@@ -74,7 +74,7 @@
   >   narrowspec.copytoworkingcopy(repo)
   >   newmatcher = narrowspec.match(repo.root, includes, excludes)
   >   added = matchmod.differencematcher(newmatcher, currentmatcher)
-  >   with repo.dirstate.parentchange():
+  >   with repo.dirstate.parentchange(repo):
   >       for f in repo[b'.'].manifest().walk(added):
   >           repo.dirstate.update_file(
   >               f,
--- a/tests/test-rebuildstate.t	Tue Dec 13 10:00:04 2022 +0100
+++ b/tests/test-rebuildstate.t	Wed Jan 25 18:46:20 2023 +0100
@@ -17,7 +17,7 @@
   >   try:
   >     for file in pats:
   >       if opts.get('normal_lookup'):
-  >         with repo.dirstate.parentchange():
+  >         with repo.dirstate.parentchange(repo):
   >             repo.dirstate.update_file(
   >                 file,
   >                 p1_tracked=True,