Show More
@@ -1210,7 +1210,8 b' class localrepository(object):' | |||||
1210 |
|
1210 | |||
1211 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc): |
|
1211 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc): | |
1212 | try: |
|
1212 | try: | |
1213 |
l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, |
|
1213 | l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, | |
|
1214 | acquirefn=acquirefn, desc=desc) | |||
1214 | except error.LockHeld as inst: |
|
1215 | except error.LockHeld as inst: | |
1215 | if not wait: |
|
1216 | if not wait: | |
1216 | raise |
|
1217 | raise | |
@@ -1219,10 +1220,9 b' class localrepository(object):' | |||||
1219 | # default to 600 seconds timeout |
|
1220 | # default to 600 seconds timeout | |
1220 | l = lockmod.lock(vfs, lockname, |
|
1221 | l = lockmod.lock(vfs, lockname, | |
1221 | int(self.ui.config("ui", "timeout", "600")), |
|
1222 | int(self.ui.config("ui", "timeout", "600")), | |
1222 |
releasefn=releasefn, |
|
1223 | releasefn=releasefn, acquirefn=acquirefn, | |
|
1224 | desc=desc) | |||
1223 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) |
|
1225 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) | |
1224 | if acquirefn: |
|
|||
1225 | acquirefn() |
|
|||
1226 | return l |
|
1226 | return l | |
1227 |
|
1227 | |||
1228 | def _afterlock(self, callback): |
|
1228 | def _afterlock(self, callback): |
@@ -38,16 +38,20 b' class lock(object):' | |||||
38 |
|
38 | |||
39 | _host = None |
|
39 | _host = None | |
40 |
|
40 | |||
41 |
def __init__(self, vfs, file, timeout=-1, releasefn=None, |
|
41 | def __init__(self, vfs, file, timeout=-1, releasefn=None, acquirefn=None, | |
|
42 | desc=None): | |||
42 | self.vfs = vfs |
|
43 | self.vfs = vfs | |
43 | self.f = file |
|
44 | self.f = file | |
44 | self.held = 0 |
|
45 | self.held = 0 | |
45 | self.timeout = timeout |
|
46 | self.timeout = timeout | |
46 | self.releasefn = releasefn |
|
47 | self.releasefn = releasefn | |
|
48 | self.acquirefn = acquirefn | |||
47 | self.desc = desc |
|
49 | self.desc = desc | |
48 | self.postrelease = [] |
|
50 | self.postrelease = [] | |
49 | self.pid = os.getpid() |
|
51 | self.pid = os.getpid() | |
50 | self.delay = self.lock() |
|
52 | self.delay = self.lock() | |
|
53 | if self.acquirefn: | |||
|
54 | self.acquirefn() | |||
51 |
|
55 | |||
52 | def __del__(self): |
|
56 | def __del__(self): | |
53 | if self.held: |
|
57 | if self.held: |
@@ -15,23 +15,38 b" testlockname = 'testlock'" | |||||
15 | class teststate(object): |
|
15 | class teststate(object): | |
16 | def __init__(self, testcase): |
|
16 | def __init__(self, testcase): | |
17 | self._testcase = testcase |
|
17 | self._testcase = testcase | |
|
18 | self._acquirecalled = False | |||
18 | self._releasecalled = False |
|
19 | self._releasecalled = False | |
19 | self._postreleasecalled = False |
|
20 | self._postreleasecalled = False | |
20 | d = tempfile.mkdtemp(dir=os.getcwd()) |
|
21 | d = tempfile.mkdtemp(dir=os.getcwd()) | |
21 | self.vfs = scmutil.vfs(d, audit=False) |
|
22 | self.vfs = scmutil.vfs(d, audit=False) | |
22 |
|
23 | |||
23 | def makelock(self, *args, **kwargs): |
|
24 | def makelock(self, *args, **kwargs): | |
24 |
l = lock.lock(self.vfs, testlockname, releasefn=self.releasefn, |
|
25 | l = lock.lock(self.vfs, testlockname, releasefn=self.releasefn, | |
25 | **kwargs) |
|
26 | acquirefn=self.acquirefn, *args, **kwargs) | |
26 | l.postrelease.append(self.postreleasefn) |
|
27 | l.postrelease.append(self.postreleasefn) | |
27 | return l |
|
28 | return l | |
28 |
|
29 | |||
|
30 | def acquirefn(self): | |||
|
31 | self._acquirecalled = True | |||
|
32 | ||||
29 | def releasefn(self): |
|
33 | def releasefn(self): | |
30 | self._releasecalled = True |
|
34 | self._releasecalled = True | |
31 |
|
35 | |||
32 | def postreleasefn(self): |
|
36 | def postreleasefn(self): | |
33 | self._postreleasecalled = True |
|
37 | self._postreleasecalled = True | |
34 |
|
38 | |||
|
39 | def assertacquirecalled(self, called): | |||
|
40 | self._testcase.assertEqual( | |||
|
41 | self._acquirecalled, called, | |||
|
42 | 'expected acquire to be %s but was actually %s' % ( | |||
|
43 | self._tocalled(called), | |||
|
44 | self._tocalled(self._acquirecalled), | |||
|
45 | )) | |||
|
46 | ||||
|
47 | def resetacquirefn(self): | |||
|
48 | self._acquirecalled = False | |||
|
49 | ||||
35 | def assertreleasecalled(self, called): |
|
50 | def assertreleasecalled(self, called): | |
36 | self._testcase.assertEqual( |
|
51 | self._testcase.assertEqual( | |
37 | self._releasecalled, called, |
|
52 | self._releasecalled, called, | |
@@ -73,6 +88,7 b' class testlock(unittest.TestCase):' | |||||
73 | def testlock(self): |
|
88 | def testlock(self): | |
74 | state = teststate(self) |
|
89 | state = teststate(self) | |
75 | lock = state.makelock() |
|
90 | lock = state.makelock() | |
|
91 | state.assertacquirecalled(True) | |||
76 | lock.release() |
|
92 | lock.release() | |
77 | state.assertreleasecalled(True) |
|
93 | state.assertreleasecalled(True) | |
78 | state.assertpostreleasecalled(True) |
|
94 | state.assertpostreleasecalled(True) | |
@@ -81,7 +97,13 b' class testlock(unittest.TestCase):' | |||||
81 | def testrecursivelock(self): |
|
97 | def testrecursivelock(self): | |
82 | state = teststate(self) |
|
98 | state = teststate(self) | |
83 | lock = state.makelock() |
|
99 | lock = state.makelock() | |
|
100 | state.assertacquirecalled(True) | |||
|
101 | ||||
|
102 | state.resetacquirefn() | |||
84 | lock.lock() |
|
103 | lock.lock() | |
|
104 | # recursive lock should not call acquirefn again | |||
|
105 | state.assertacquirecalled(False) | |||
|
106 | ||||
85 | lock.release() # brings lock refcount down from 2 to 1 |
|
107 | lock.release() # brings lock refcount down from 2 to 1 | |
86 | state.assertreleasecalled(False) |
|
108 | state.assertreleasecalled(False) | |
87 | state.assertpostreleasecalled(False) |
|
109 | state.assertpostreleasecalled(False) | |
@@ -95,6 +117,7 b' class testlock(unittest.TestCase):' | |||||
95 | def testlockfork(self): |
|
117 | def testlockfork(self): | |
96 | state = teststate(self) |
|
118 | state = teststate(self) | |
97 | lock = state.makelock() |
|
119 | lock = state.makelock() | |
|
120 | state.assertacquirecalled(True) | |||
98 | lock.lock() |
|
121 | lock.lock() | |
99 | # fake a fork |
|
122 | # fake a fork | |
100 | lock.pid += 1 |
|
123 | lock.pid += 1 |
General Comments 0
You need to be logged in to leave comments.
Login now