Show More
@@ -0,0 +1,48 b'' | |||
|
1 | """Extension to verify locks are obtained in the required places. | |
|
2 | ||
|
3 | This works by wrapping functions that should be surrounded by a lock | |
|
4 | and asserting the lock is held. Missing locks are called out with a | |
|
5 | traceback printed to stderr. | |
|
6 | ||
|
7 | This currently only checks store locks, not working copy locks. | |
|
8 | """ | |
|
9 | import os | |
|
10 | import traceback | |
|
11 | ||
|
12 | def _warnstack(ui, msg, skip=1): | |
|
13 | '''issue warning with the message and the current stack, skipping the | |
|
14 | skip last entries''' | |
|
15 | ui.warn('%s at:\n' % msg) | |
|
16 | entries = traceback.extract_stack()[:-skip] | |
|
17 | fnmax = max(len(entry[0]) for entry in entries) | |
|
18 | for fn, ln, func, _text in entries: | |
|
19 | ui.warn(' %*s:%-4s in %s\n' % (fnmax, fn, ln, func)) | |
|
20 | ||
|
21 | def _checklock(repo): | |
|
22 | l = repo._lockref and repo._lockref() | |
|
23 | if l is None or not l.held: | |
|
24 | _warnstack(repo.ui, 'missing lock', skip=2) | |
|
25 | ||
|
26 | def reposetup(ui, repo): | |
|
27 | orig = repo.__class__ | |
|
28 | class lockcheckrepo(repo.__class__): | |
|
29 | def _writejournal(self, *args, **kwargs): | |
|
30 | _checklock(self) | |
|
31 | return orig._writejournal(self, *args, **kwargs) | |
|
32 | ||
|
33 | def transaction(self, *args, **kwargs): | |
|
34 | _checklock(self) | |
|
35 | return orig.transaction(self, *args, **kwargs) | |
|
36 | ||
|
37 | # TODO(durin42): kiilerix had a commented-out lock check in | |
|
38 | # writebranchcache and _writerequirements | |
|
39 | ||
|
40 | def _tag(self, *args, **kwargs): | |
|
41 | _checklock(self) | |
|
42 | return orig._tag(self, *args, **kwargs) | |
|
43 | ||
|
44 | def write(self, *args, **kwargs): | |
|
45 | assert os.path.lexists(self._join('.hg/wlock')) | |
|
46 | return orig.write(self, *args, **kwargs) | |
|
47 | ||
|
48 | repo.__class__ = lockcheckrepo |
General Comments 0
You need to be logged in to leave comments.
Login now