# HG changeset patch # User Pierre-Yves David # Date 1674647486 -3600 # Node ID 2264e775512b29f33f311d83bbcfb03190c47cac # Parent bbe3a65bbd96f300dcd7c0b2cff6cb10c138ebe3 subrepo: use `changing_files` context in subrepository code This is better, not ideal, but better. diff -r bbe3a65bbd96 -r 2264e775512b mercurial/subrepo.py --- 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]