diff -r 0dc2fb4b4b11 -r d50d45cd5a5f mercurial/dirstate.py --- a/mercurial/dirstate.py Thu Jan 26 17:16:24 2023 +0100 +++ b/mercurial/dirstate.py Mon Feb 13 21:51:45 2023 +0100 @@ -204,7 +204,11 @@ # Exception catching (and the associated `invalidate` # calling) might have been called by a nested context # instead of the top level one. - self.write(repo.currenttransaction()) + tr = repo.currenttransaction() + if tr is not None: + abort_cb = lambda tr: self.invalidate() + tr.addabort(b'dirstate', abort_cb) + self.write(tr) @contextlib.contextmanager def changing_parents(self, repo):