Show More
@@ -40,7 +40,7 b' class lock(object):' | |||||
40 | _host = None |
|
40 | _host = None | |
41 |
|
41 | |||
42 | def __init__(self, vfs, file, timeout=-1, releasefn=None, acquirefn=None, |
|
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 | self.vfs = vfs |
|
44 | self.vfs = vfs | |
45 | self.f = file |
|
45 | self.f = file | |
46 | self.held = 0 |
|
46 | self.held = 0 | |
@@ -48,6 +48,7 b' class lock(object):' | |||||
48 | self.releasefn = releasefn |
|
48 | self.releasefn = releasefn | |
49 | self.acquirefn = acquirefn |
|
49 | self.acquirefn = acquirefn | |
50 | self.desc = desc |
|
50 | self.desc = desc | |
|
51 | self._inheritchecker = inheritchecker | |||
51 | self.parentlock = parentlock |
|
52 | self.parentlock = parentlock | |
52 | self._parentheld = False |
|
53 | self._parentheld = False | |
53 | self._inherited = False |
|
54 | self._inherited = False | |
@@ -186,6 +187,8 b' class lock(object):' | |||||
186 | if self._inherited: |
|
187 | if self._inherited: | |
187 | raise error.LockInheritanceContractViolation( |
|
188 | raise error.LockInheritanceContractViolation( | |
188 | 'inherit cannot be called while lock is already inherited') |
|
189 | 'inherit cannot be called while lock is already inherited') | |
|
190 | if self._inheritchecker is not None: | |||
|
191 | self._inheritchecker() | |||
189 | if self.releasefn: |
|
192 | if self.releasefn: | |
190 | self.releasefn() |
|
193 | self.releasefn() | |
191 | if self._parentheld: |
|
194 | if self._parentheld: |
@@ -8,6 +8,7 b' import types' | |||||
8 | import unittest |
|
8 | import unittest | |
9 |
|
9 | |||
10 | from mercurial import ( |
|
10 | from mercurial import ( | |
|
11 | error, | |||
11 | lock, |
|
12 | lock, | |
12 | scmutil, |
|
13 | scmutil, | |
13 | ) |
|
14 | ) | |
@@ -250,5 +251,21 b' class testlock(unittest.TestCase):' | |||||
250 |
|
251 | |||
251 | parentlock.release() |
|
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 | if __name__ == '__main__': |
|
270 | if __name__ == '__main__': | |
254 | silenttestrunner.main(__name__) |
|
271 | silenttestrunner.main(__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now