contrib/lock-checker.py
branchstable
changeset 24803 e89f909edffa
parent 24753 612ed41ae359
parent 24802 2ee10789d66b
child 24804 2fe9fd88db0b
equal deleted inserted replaced
24753:612ed41ae359 24803:e89f909edffa
     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 from mercurial import util
       
    11 
       
    12 def _checklock(repo):
       
    13     l = repo._lockref and repo._lockref()
       
    14     if l is None or not l.held:
       
    15         util.debugstacktrace('missing lock', skip=1)
       
    16 
       
    17 def reposetup(ui, repo):
       
    18     orig = repo.__class__
       
    19     class lockcheckrepo(repo.__class__):
       
    20         def _writejournal(self, *args, **kwargs):
       
    21             _checklock(self)
       
    22             return orig._writejournal(self, *args, **kwargs)
       
    23 
       
    24         def transaction(self, *args, **kwargs):
       
    25             _checklock(self)
       
    26             return orig.transaction(self, *args, **kwargs)
       
    27 
       
    28         # TODO(durin42): kiilerix had a commented-out lock check in
       
    29         # _writebranchcache and _writerequirements
       
    30 
       
    31         def _tag(self, *args, **kwargs):
       
    32             _checklock(self)
       
    33             return orig._tag(self, *args, **kwargs)
       
    34 
       
    35         def write(self, *args, **kwargs):
       
    36             assert os.path.lexists(self._join('.hg/wlock'))
       
    37             return orig.write(self, *args, **kwargs)
       
    38 
       
    39     repo.__class__ = lockcheckrepo