mercurial/subrepo.py
changeset 50046 2264e775512b
parent 50045 bbe3a65bbd96
child 50928 d718eddf01d9
--- a/mercurial/subrepo.py	Sat Feb 04 12:14:19 2023 +0100
+++ b/mercurial/subrepo.py	Wed Jan 25 12:51:26 2023 +0100
@@ -569,15 +569,20 @@
 
     @annotatesubrepoerror
     def add(self, ui, match, prefix, uipathfn, explicitonly, **opts):
-        return cmdutil.add(
-            ui,
-            self._repo,
-            match,
-            prefix,
-            uipathfn,
-            explicitonly,
-            **opts,
-        )
+        # XXX Ideally, we could let the caller take the `changing_files`
+        # context.  However this is not an abstraction that make sense for
+        # other repository types, and leaking that details purely related to
+        # dirstate seems unfortunate. So for now the context will be used here.
+        with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo):
+            return cmdutil.add(
+                ui,
+                self._repo,
+                match,
+                prefix,
+                uipathfn,
+                explicitonly,
+                **opts,
+            )
 
     @annotatesubrepoerror
     def addremove(self, m, prefix, uipathfn, opts):
@@ -586,7 +591,18 @@
         # be used to process sibling subrepos however.
         opts = copy.copy(opts)
         opts[b'subrepos'] = True
-        return scmutil.addremove(self._repo, m, prefix, uipathfn, opts)
+        # XXX Ideally, we could let the caller take the `changing_files`
+        # context.  However this is not an abstraction that make sense for
+        # other repository types, and leaking that details purely related to
+        # dirstate seems unfortunate. So for now the context will be used here.
+        with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo):
+            return scmutil.addremove(
+                self._repo,
+                m,
+                prefix,
+                uipathfn,
+                opts,
+            )
 
     @annotatesubrepoerror
     def cat(self, match, fm, fntemplate, prefix, **opts):
@@ -952,16 +968,21 @@
 
     @annotatesubrepoerror
     def forget(self, match, prefix, uipathfn, dryrun, interactive):
-        return cmdutil.forget(
-            self.ui,
-            self._repo,
-            match,
-            prefix,
-            uipathfn,
-            True,
-            dryrun=dryrun,
-            interactive=interactive,
-        )
+        # XXX Ideally, we could let the caller take the `changing_files`
+        # context.  However this is not an abstraction that make sense for
+        # other repository types, and leaking that details purely related to
+        # dirstate seems unfortunate. So for now the context will be used here.
+        with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo):
+            return cmdutil.forget(
+                self.ui,
+                self._repo,
+                match,
+                prefix,
+                uipathfn,
+                True,
+                dryrun=dryrun,
+                interactive=interactive,
+            )
 
     @annotatesubrepoerror
     def removefiles(
@@ -975,17 +996,22 @@
         dryrun,
         warnings,
     ):
-        return cmdutil.remove(
-            self.ui,
-            self._repo,
-            matcher,
-            prefix,
-            uipathfn,
-            after,
-            force,
-            subrepos,
-            dryrun,
-        )
+        # XXX Ideally, we could let the caller take the `changing_files`
+        # context.  However this is not an abstraction that make sense for
+        # other repository types, and leaking that details purely related to
+        # dirstate seems unfortunate. So for now the context will be used here.
+        with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo):
+            return cmdutil.remove(
+                self.ui,
+                self._repo,
+                matcher,
+                prefix,
+                uipathfn,
+                after,
+                force,
+                subrepos,
+                dryrun,
+            )
 
     @annotatesubrepoerror
     def revert(self, substate, *pats, **opts):
@@ -1015,7 +1041,12 @@
             pats = [b'set:modified()']
         else:
             pats = []
-        cmdutil.revert(self.ui, self._repo, ctx, *pats, **opts)
+        # XXX Ideally, we could let the caller take the `changing_files`
+        # context.  However this is not an abstraction that make sense for
+        # other repository types, and leaking that details purely related to
+        # dirstate seems unfortunate. So for now the context will be used here.
+        with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo):
+            cmdutil.revert(self.ui, self._repo, ctx, *pats, **opts)
 
     def shortid(self, revid):
         return revid[:12]