contrib/lock-checker.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Thu, 22 Jan 2015 00:10:26 +0900
branchstable
changeset 23936 30b016ef4bd8
parent 20244 47d0843647d1
permissions -rw-r--r--
check-code.py: avoid warning against "reverting subrepo ..." lines Before this patch, "reverting subrepo subrepo/path" lines in *.t test files require "(glob)", because such lines are recognized as "reverting path/to/managed/file" by "check-code.py". On the other hand, "(glob)" for such "reverting ..." line is recognized as useless by "runt-tests.py", because subrepo paths shown in such lines are always normalized by "util.pconvert". And this causes "no result code from test" warning. As a preparation for discarding "(glob)" from such lines in subsequent patch, this patch avoids warning against them, by adding negative lookahead assertion "(?!subrepo )" to the regexp.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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