--- 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):