dirstate: invalidate the dirstate change on transaction failure
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 13 Feb 2023 21:51:45 +0100
changeset 50081 d50d45cd5a5f
parent 50080 0dc2fb4b4b11
child 50082 3550e4a88ccd
dirstate: invalidate the dirstate change on transaction failure If the change context lives inside a transaction, the change are not flushed to disk on exit as this is delegated to the transaction. As a result we should also delegate the part that do cleanup on failure. The issue was caught by tests with other change, but it seems useful to fix this as soon as possible.
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):