Mercurial > hg
annotate contrib/lock-checker.py @ 23603:d74eb8d477d5
memctx: calculate manifest more efficiently
Before this patch, "memctx._manifest" updates all entries in the
(parent) manifest. But this is inefficiency, because almost all files
may be clean in that context.
On the other hand, just updating entries for changed "files" specified
at construction causes unexpected abortion, when there is at least one
newly removed file (see issue4470 for detail).
To calculate manifest more efficiently, this patch replaces
"pman.iteritems()" for the loop by "self._status.modified" to avoid
updating entries for clean or removed files
Examination of removal is also omitted, because removed files aren't
treated in this loop (= "self[f]" returns not None always).
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 19 Dec 2014 00:11:56 +0900 |
parents | 47d0843647d1 |
children |
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 |