comparison mercurial/localrepo.py @ 29705:41689e293994

develwarn: use the lock helper in local repo We have a helper function to know if a lock is taken. When checking lock usage we now use it instead of manually accessing the locks.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 05 Aug 2016 13:44:17 +0200
parents 526b027b0130
children b9ee2a1c4e9c
comparison
equal deleted inserted replaced
29703:3ef9aa7ad1fc 29705:41689e293994
1005 return None 1005 return None
1006 1006
1007 def transaction(self, desc, report=None): 1007 def transaction(self, desc, report=None):
1008 if (self.ui.configbool('devel', 'all-warnings') 1008 if (self.ui.configbool('devel', 'all-warnings')
1009 or self.ui.configbool('devel', 'check-locks')): 1009 or self.ui.configbool('devel', 'check-locks')):
1010 l = self._lockref and self._lockref() 1010 if self._currentlock(self._lockref) is None:
1011 if l is None or not l.held:
1012 raise RuntimeError('programming error: transaction requires ' 1011 raise RuntimeError('programming error: transaction requires '
1013 'locking') 1012 'locking')
1014 tr = self.currenttransaction() 1013 tr = self.currenttransaction()
1015 if tr is not None: 1014 if tr is not None:
1016 return tr.nest() 1015 return tr.nest()
1318 to the lock. Use this before modifying the store (e.g. committing or 1317 to the lock. Use this before modifying the store (e.g. committing or
1319 stripping). If you are opening a transaction, get a lock as well.) 1318 stripping). If you are opening a transaction, get a lock as well.)
1320 1319
1321 If both 'lock' and 'wlock' must be acquired, ensure you always acquires 1320 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
1322 'wlock' first to avoid a dead-lock hazard.''' 1321 'wlock' first to avoid a dead-lock hazard.'''
1323 l = self._lockref and self._lockref() 1322 l = self._currentlock(self._lockref)
1324 if l is not None and l.held: 1323 if l is not None:
1325 l.lock() 1324 l.lock()
1326 return l 1325 return l
1327 1326
1328 l = self._lock(self.svfs, "lock", wait, None, 1327 l = self._lock(self.svfs, "lock", wait, None,
1329 self.invalidate, _('repository %s') % self.origroot) 1328 self.invalidate, _('repository %s') % self.origroot)
1350 1349
1351 # We do not need to check for non-waiting lock acquisition. Such 1350 # We do not need to check for non-waiting lock acquisition. Such
1352 # acquisition would not cause dead-lock as they would just fail. 1351 # acquisition would not cause dead-lock as they would just fail.
1353 if wait and (self.ui.configbool('devel', 'all-warnings') 1352 if wait and (self.ui.configbool('devel', 'all-warnings')
1354 or self.ui.configbool('devel', 'check-locks')): 1353 or self.ui.configbool('devel', 'check-locks')):
1355 l = self._lockref and self._lockref() 1354 if self._currentlock(self._lockref) is not None:
1356 if l is not None and l.held:
1357 self.ui.develwarn('"wlock" acquired after "lock"') 1355 self.ui.develwarn('"wlock" acquired after "lock"')
1358 1356
1359 def unlock(): 1357 def unlock():
1360 if self.dirstate.pendingparentchange(): 1358 if self.dirstate.pendingparentchange():
1361 self.dirstate.invalidate() 1359 self.dirstate.invalidate()