comparison mercurial/dirstate.py @ 50122:72b4d9284411

dirstate: track that changes are pending in a transaction Nothing is currently broken because if this, but this make the `_invalidated_context` attribute more accurate. Being more accurate here will help us later, when dealing with `status` call.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 20 Feb 2023 16:31:36 +0100
parents 15531d101313
children 4e95341c89aa
comparison
equal deleted inserted replaced
50121:15531d101313 50122:72b4d9284411
172 # the change currently underway 172 # the change currently underway
173 self._change_type = None 173 self._change_type = None
174 # True if the current dirstate changing operations have been 174 # True if the current dirstate changing operations have been
175 # invalidated (used to make sure all nested contexts have been exited) 175 # invalidated (used to make sure all nested contexts have been exited)
176 self._invalidated_context = False 176 self._invalidated_context = False
177 self._attached_to_a_transaction = False
177 self._filename = b'dirstate' 178 self._filename = b'dirstate'
178 self._filename_th = b'dirstate-tracked-hint' 179 self._filename_th = b'dirstate-tracked-hint'
179 self._pendingfilename = b'%s.pending' % self._filename 180 self._pendingfilename = b'%s.pending' % self._filename
180 self._plchangecallbacks = {} 181 self._plchangecallbacks = {}
181 self._origpl = None 182 self._origpl = None
554 for a in ("_map", "_branch", "_ignore"): 555 for a in ("_map", "_branch", "_ignore"):
555 if a in self.__dict__: 556 if a in self.__dict__:
556 delattr(self, a) 557 delattr(self, a)
557 self._dirty = False 558 self._dirty = False
558 self._dirty_tracked_set = False 559 self._dirty_tracked_set = False
559 self._invalidated_context = self._changing_level > 0 560 self._invalidated_context = (
561 self._changing_level > 0 or self._attached_to_a_transaction
562 )
560 self._origpl = None 563 self._origpl = None
561 564
562 @requires_changing_any 565 @requires_changing_any
563 def copy(self, source, dest): 566 def copy(self, source, dest):
564 """Mark dest as a copy of source. Unmark dest if source is None.""" 567 """Mark dest as a copy of source. Unmark dest if source is None."""
939 # XXX move before the dirty check once `unlock` stop calling `write` 942 # XXX move before the dirty check once `unlock` stop calling `write`
940 assert not self._invalidated_context 943 assert not self._invalidated_context
941 944
942 write_key = self._use_tracked_hint and self._dirty_tracked_set 945 write_key = self._use_tracked_hint and self._dirty_tracked_set
943 if tr: 946 if tr:
947
948 def on_abort(tr):
949 self._attached_to_a_transaction = False
950 self.invalidate()
951
944 # make sure we invalidate the current change on abort 952 # make sure we invalidate the current change on abort
945 if tr is not None: 953 if tr is not None:
946 tr.addabort( 954 tr.addabort(b'dirstate-invalidate', on_abort)
947 b'dirstate-invalidate', 955
948 lambda tr: self.invalidate(), 956 self._attached_to_a_transaction = True
949 ) 957
958 def on_success(f):
959 self._attached_to_a_transaction = False
960 self._writedirstate(tr, f),
961
950 # delay writing in-memory changes out 962 # delay writing in-memory changes out
951 tr.addfilegenerator( 963 tr.addfilegenerator(
952 b'dirstate-1-main', 964 b'dirstate-1-main',
953 (self._filename,), 965 (self._filename,),
954 lambda f: self._writedirstate(tr, f), 966 on_success,
955 location=b'plain', 967 location=b'plain',
956 post_finalize=True, 968 post_finalize=True,
957 ) 969 )
958 if write_key: 970 if write_key:
959 tr.addfilegenerator( 971 tr.addfilegenerator(