changeset 50024:5b0beaf45491

dirstate: write dirstate on successful exit of changing_parents context This is the first step toward having more sensible and predicatable write patterns for the dirstate. Having better write/rollback patterns will greatly reduce and clarify the needs to backup the dirstate.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 13 Dec 2022 12:10:37 +0100
parents 7a8bfc05b691
children 23b70ce09e55
files mercurial/dirstate.py
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Wed Jan 25 19:12:31 2023 +0100
+++ b/mercurial/dirstate.py	Tue Dec 13 12:10:37 2022 +0100
@@ -178,7 +178,18 @@
                 # manager
                 if self._parentwriters <= 0:
                     assert self._parentwriters == 0
-                    self._invalidated_context = False
+                    if self._invalidated_context:
+                        self._invalidated_context = False
+                    else:
+                        # When an exception occured, `_invalidated_context`
+                        # would have been set to True by the `invalidate`
+                        # call earlier.
+                        #
+                        # We don't have more straightforward code, because the
+                        # 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())
 
     # here to help migration to the new code
     def parentchange(self):