Mercurial > hg
comparison mercurial/dirstate.py @ 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 |
comparison
equal
deleted
inserted
replaced
50254:df76808d5f21 | 50255:fa04407bda7a |
---|---|
1007 for f in to_drop: | 1007 for f in to_drop: |
1008 self._map.reset_state(f) | 1008 self._map.reset_state(f) |
1009 | 1009 |
1010 self._dirty = True | 1010 self._dirty = True |
1011 | 1011 |
1012 def _setup_tr_abort(self, tr): | |
1013 """make sure we invalidate the current change on abort""" | |
1014 if tr is None: | |
1015 return | |
1016 | |
1017 def on_abort(tr): | |
1018 self._attached_to_a_transaction = False | |
1019 self.invalidate() | |
1020 | |
1021 tr.addabort( | |
1022 b'dirstate-invalidate%s' % self._tr_key_suffix, | |
1023 on_abort, | |
1024 ) | |
1025 | |
1012 def write(self, tr): | 1026 def write(self, tr): |
1013 if not self._dirty: | 1027 if not self._dirty: |
1014 return | 1028 return |
1015 # make sure we don't request a write of invalidated content | 1029 # make sure we don't request a write of invalidated content |
1016 # XXX move before the dirty check once `unlock` stop calling `write` | 1030 # XXX move before the dirty check once `unlock` stop calling `write` |
1017 assert not self._invalidated_context | 1031 assert not self._invalidated_context |
1018 | 1032 |
1019 write_key = self._use_tracked_hint and self._dirty_tracked_set | 1033 write_key = self._use_tracked_hint and self._dirty_tracked_set |
1020 if tr: | 1034 if tr: |
1021 | 1035 |
1022 def on_abort(tr): | 1036 self._setup_tr_abort(tr) |
1023 self._attached_to_a_transaction = False | |
1024 self.invalidate() | |
1025 | |
1026 # make sure we invalidate the current change on abort | |
1027 if tr is not None: | |
1028 tr.addabort( | |
1029 b'dirstate-invalidate%s' % self._tr_key_suffix, | |
1030 on_abort, | |
1031 ) | |
1032 | |
1033 self._attached_to_a_transaction = True | 1037 self._attached_to_a_transaction = True |
1034 | 1038 |
1035 def on_success(f): | 1039 def on_success(f): |
1036 self._attached_to_a_transaction = False | 1040 self._attached_to_a_transaction = False |
1037 self._writedirstate(tr, f), | 1041 self._writedirstate(tr, f), |