changeset 50025:d50d45cd5a5f

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 13 Feb 2023 21:51:45 +0100
parents 0dc2fb4b4b11
children 3550e4a88ccd
files mercurial/dirstate.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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):