comparison mercurial/dirstate.py @ 22404:12bc7f06fc41

dirstate: add begin/endparentchange to dirstate It's possible for the dirstate to become incoherent (issue4353) if there is an exception in the middle of the dirstate parent and entries being written (like if the user ctrl+c's). This change adds begin/endparentchange which a future patch will require to be set before changing the dirstate parent. This will allow us to prevent writing the dirstate in the event of an exception while changing the parent.
author Durham Goode <durham@fb.com>
date Fri, 05 Sep 2014 11:34:29 -0700
parents 977a0b9af5ac
children d259322a394b
comparison
equal deleted inserted replaced
22403:41e9d58ec56f 22404:12bc7f06fc41
42 self._dirty = False 42 self._dirty = False
43 self._dirtypl = False 43 self._dirtypl = False
44 self._lastnormaltime = 0 44 self._lastnormaltime = 0
45 self._ui = ui 45 self._ui = ui
46 self._filecache = {} 46 self._filecache = {}
47 self._parentwriters = 0
48
49 def beginparentchange(self):
50 '''Marks the beginning of a set of changes that involve changing
51 the dirstate parents. If there is an exception during this time,
52 the dirstate will not be written when the wlock is released. This
53 prevents writing an incoherent dirstate where the parent doesn't
54 match the contents.
55 '''
56 self._parentwriters += 1
57
58 def endparentchange(self):
59 '''Marks the end of a set of changes that involve changing the
60 dirstate parents. Once all parent changes have been marked done,
61 the wlock will be free to write the dirstate on release.
62 '''
63 if self._parentwriters > 0:
64 self._parentwriters -= 1
65
66 def pendingparentchange(self):
67 '''Returns true if the dirstate is in the middle of a set of changes
68 that modify the dirstate parent.
69 '''
70 return self._parentwriters > 0
47 71
48 @propertycache 72 @propertycache
49 def _map(self): 73 def _map(self):
50 '''Return the dirstate contents as a map from filename to 74 '''Return the dirstate contents as a map from filename to
51 (state, mode, size, time).''' 75 (state, mode, size, time).'''
298 "_ignore"): 322 "_ignore"):
299 if a in self.__dict__: 323 if a in self.__dict__:
300 delattr(self, a) 324 delattr(self, a)
301 self._lastnormaltime = 0 325 self._lastnormaltime = 0
302 self._dirty = False 326 self._dirty = False
327 self._parentwriters = 0
303 328
304 def copy(self, source, dest): 329 def copy(self, source, dest):
305 """Mark dest as a copy of source. Unmark dest if source is None.""" 330 """Mark dest as a copy of source. Unmark dest if source is None."""
306 if source == dest: 331 if source == dest:
307 return 332 return