changeset 50255:fa04407bda7a

dirstate: factor the transaction abort logic We will need it in more occasion if the branch is to be written as part of the transaction.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 02 Mar 2023 11:46:51 +0100
parents df76808d5f21
children a6e0b7d4ae9d
files mercurial/dirstate.py
diffstat 1 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Thu Mar 02 14:50:17 2023 +0100
+++ b/mercurial/dirstate.py	Thu Mar 02 11:46:51 2023 +0100
@@ -1009,6 +1009,20 @@
 
         self._dirty = True
 
+    def _setup_tr_abort(self, tr):
+        """make sure we invalidate the current change on abort"""
+        if tr is None:
+            return
+
+        def on_abort(tr):
+            self._attached_to_a_transaction = False
+            self.invalidate()
+
+        tr.addabort(
+            b'dirstate-invalidate%s' % self._tr_key_suffix,
+            on_abort,
+        )
+
     def write(self, tr):
         if not self._dirty:
             return
@@ -1019,17 +1033,7 @@
         write_key = self._use_tracked_hint and self._dirty_tracked_set
         if tr:
 
-            def on_abort(tr):
-                self._attached_to_a_transaction = False
-                self.invalidate()
-
-            # make sure we invalidate the current change on abort
-            if tr is not None:
-                tr.addabort(
-                    b'dirstate-invalidate%s' % self._tr_key_suffix,
-                    on_abort,
-                )
-
+            self._setup_tr_abort(tr)
             self._attached_to_a_transaction = True
 
             def on_success(f):