annotate contrib/lock-checker.py @ 22125:7fce964be27d

hg-test-mode: make exit code highlight work again
author Matt Mackall <mpm@selenic.com>
date Tue, 12 Aug 2014 12:53:23 -0500
parents 47d0843647d1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17669
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
1 """Extension to verify locks are obtained in the required places.
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
2
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 This works by wrapping functions that should be surrounded by a lock
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 and asserting the lock is held. Missing locks are called out with a
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 traceback printed to stderr.
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 This currently only checks store locks, not working copy locks.
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8 """
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 import os
20244
47d0843647d1 util: introduce util.debugstacktrace for showing a stack trace without crashing
Mads Kiilerich <madski@unity3d.com>
parents: 17738
diff changeset
10 from mercurial import util
17669
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 def _checklock(repo):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 l = repo._lockref and repo._lockref()
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 if l is None or not l.held:
20244
47d0843647d1 util: introduce util.debugstacktrace for showing a stack trace without crashing
Mads Kiilerich <madski@unity3d.com>
parents: 17738
diff changeset
15 util.debugstacktrace('missing lock', skip=1)
17669
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 def reposetup(ui, repo):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18 orig = repo.__class__
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 class lockcheckrepo(repo.__class__):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 def _writejournal(self, *args, **kwargs):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21 _checklock(self)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 return orig._writejournal(self, *args, **kwargs)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24 def transaction(self, *args, **kwargs):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
25 _checklock(self)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
26 return orig.transaction(self, *args, **kwargs)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
27
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
28 # TODO(durin42): kiilerix had a commented-out lock check in
17738
b8424c92ba2b spelling: fix minor spell checker issues
Mads Kiilerich <mads@kiilerich.com>
parents: 17669
diff changeset
29 # _writebranchcache and _writerequirements
17669
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
30
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
31 def _tag(self, *args, **kwargs):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
32 _checklock(self)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
33 return orig._tag(self, *args, **kwargs)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
34
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
35 def write(self, *args, **kwargs):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
36 assert os.path.lexists(self._join('.hg/wlock'))
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
37 return orig.write(self, *args, **kwargs)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
38
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
39 repo.__class__ = lockcheckrepo