changeset 50145:72ef6c4888da

dirstate: start tracking that we are within a `running_status` context
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 21 Feb 2023 22:32:04 +0100
parents c6df5349183b
children 8ba5028de859
files mercurial/dirstate.py
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Mon Feb 20 15:28:08 2023 +0100
+++ b/mercurial/dirstate.py	Tue Feb 21 22:32:04 2023 +0100
@@ -175,6 +175,8 @@
         self._changing_level = 0
         # the change currently underway
         self._change_type = None
+        # number of open _running_status context
+        self._running_status = 0
         # True if the current dirstate changing operations have been
         # invalidated (used to make sure all nested contexts have been exited)
         self._invalidated_context = False
@@ -233,7 +235,16 @@
         E1: elif lock was acquired → write the changes
         E2: else → discard the changes
         """
-        yield
+        self._running_status += 1
+        try:
+            yield
+        except Exception:
+            self.invalidate()
+            raise
+        finally:
+            self._running_status -= 1
+            if self._invalidated_context:
+                self.invalidate()
 
     @contextlib.contextmanager
     @check_invalidated
@@ -598,8 +609,10 @@
                 delattr(self, a)
         self._dirty = False
         self._dirty_tracked_set = False
-        self._invalidated_context = (
-            self._changing_level > 0 or self._attached_to_a_transaction
+        self._invalidated_context = bool(
+            self._changing_level > 0
+            or self._attached_to_a_transaction
+            or self._running_status
         )
         self._origpl = None