contrib/lock-checker.py
author Mads Kiilerich <madski@unity3d.com>
Thu, 03 Oct 2013 18:01:21 +0200
changeset 19892 77872b002e73
parent 17738 b8424c92ba2b
child 20244 47d0843647d1
permissions -rw-r--r--
convert: update source shamap when using filemap, just as when not using filemap The reverse mapping was introduced in 2147a734dcf9 to make roundtrip conversions possible ... but it did not work when using filemap. Roundtrips with filemaps will of course only work flawlessly if inverse mappings are used. Especially, if a lossy convert mapping is used in one direction, then only linear lines of development can be converted in the other direction. With this constraint convert will do the right thing by assuming that excluded files haven't been changed.) A test case with general coverage of hg-hg roundtrips with filemap is added. (There a cases where adding records of converted revisions to the shamap in the source repository doesn't work - especially when converting the same repo to several other repos and back. It would arguably be better if convert only updated the shamaps in the target repo but read shamaps from both the source and and target repo ... but that is a different story. Making the stuff we have work consistently is step forward no matter what.)
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
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    10
import traceback
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 _warnstack(ui, msg, skip=1):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    13
    '''issue warning with the message and the current stack, skipping the
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    14
    skip last entries'''
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    15
    ui.warn('%s at:\n' % msg)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    16
    entries = traceback.extract_stack()[:-skip]
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    17
    fnmax = max(len(entry[0]) for entry in entries)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    18
    for fn, ln, func, _text in entries:
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    19
        ui.warn(' %*s:%-4s in %s\n' % (fnmax, fn, ln, func))
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    20
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    21
def _checklock(repo):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    22
    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
    23
    if l is None or not l.held:
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    24
        _warnstack(repo.ui, 'missing lock', skip=2)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    25
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    26
def reposetup(ui, repo):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    27
    orig = repo.__class__
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    28
    class lockcheckrepo(repo.__class__):
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    29
        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
    30
            _checklock(self)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    31
            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
    32
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    33
        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
    34
            _checklock(self)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    35
            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
    36
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    37
        # 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
    38
        # _writebranchcache and _writerequirements
17669
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    39
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    40
        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
    41
            _checklock(self)
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    42
            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
    43
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    44
        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
    45
            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
    46
            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
    47
405b5f8fdad7 lock-checker: new contrib extension based on work done by Mads
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    48
    repo.__class__ = lockcheckrepo