##// END OF EJS Templates
lock: add a way to prevent locks from being inherited...
Siddharth Agarwal -
r26498:e8564e04 default
parent child Browse files
Show More
@@ -40,7 +40,7 b' class lock(object):'
40 40 _host = None
41 41
42 42 def __init__(self, vfs, file, timeout=-1, releasefn=None, acquirefn=None,
43 desc=None, parentlock=None):
43 desc=None, inheritchecker=None, parentlock=None):
44 44 self.vfs = vfs
45 45 self.f = file
46 46 self.held = 0
@@ -48,6 +48,7 b' class lock(object):'
48 48 self.releasefn = releasefn
49 49 self.acquirefn = acquirefn
50 50 self.desc = desc
51 self._inheritchecker = inheritchecker
51 52 self.parentlock = parentlock
52 53 self._parentheld = False
53 54 self._inherited = False
@@ -186,6 +187,8 b' class lock(object):'
186 187 if self._inherited:
187 188 raise error.LockInheritanceContractViolation(
188 189 'inherit cannot be called while lock is already inherited')
190 if self._inheritchecker is not None:
191 self._inheritchecker()
189 192 if self.releasefn:
190 193 self.releasefn()
191 194 if self._parentheld:
@@ -8,6 +8,7 b' import types'
8 8 import unittest
9 9
10 10 from mercurial import (
11 error,
11 12 lock,
12 13 scmutil,
13 14 )
@@ -250,5 +251,21 b' class testlock(unittest.TestCase):'
250 251
251 252 parentlock.release()
252 253
254 def testinheritcheck(self):
255 d = tempfile.mkdtemp(dir=os.getcwd())
256 state = teststate(self, d)
257 def check():
258 raise error.LockInheritanceContractViolation('check failed')
259 lock = state.makelock(inheritchecker=check)
260 state.assertacquirecalled(True)
261
262 def tryinherit():
263 with lock.inherit() as lockname:
264 pass
265
266 self.assertRaises(error.LockInheritanceContractViolation, tryinherit)
267
268 lock.release()
269
253 270 if __name__ == '__main__':
254 271 silenttestrunner.main(__name__)
General Comments 0
You need to be logged in to leave comments. Login now