# HG changeset patch # User Pierre-Yves David # Date 2015-01-16 10:51:10 # Node ID d6ac30f4edefcf205bf27a3ddf37626922fa8018 # Parent 885a573fa619cceca33663ce3b02d988c45bcf38 devel: move the lock-checking code into core If the developer warnings are enabled, bad locking order will be reported without the need for the contrib extension. diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1189,6 +1189,15 @@ class localrepository(object): '''Lock the non-store parts of the repository (everything under .hg except .hg/store) and return a weak reference to the lock. Use this before modifying files in .hg.''' + if (self.ui.configbool('devel', 'all') + or self.ui.configbool('devel', 'check-locks')): + l = self._lockref and self._lockref() + if l is not None and l.held: + msg = '"lock" taken before "wlock"\n' + if self.ui.tracebackflag: + util.debugstacktrace(msg, 1) + else: + self.ui.write_err(msg) l = self._wlockref and self._wlockref() if l is not None and l.held: l.lock() diff --git a/tests/test-devel-warnings.t b/tests/test-devel-warnings.t new file mode 100644 --- /dev/null +++ b/tests/test-devel-warnings.t @@ -0,0 +1,49 @@ + + $ cat << EOF > buggylocking.py + > """A small extension that acquire locks in the wrong order + > """ + > + > from mercurial import cmdutil + > + > cmdtable = {} + > command = cmdutil.command(cmdtable) + > + > @command('buggylocking', [], '') + > def buggylocking(ui, repo): + > lo = repo.lock() + > wl = repo.wlock() + > EOF + + $ cat << EOF >> $HGRCPATH + > [extensions] + > buggylocking=$TESTTMP/buggylocking.py + > [devel] + > all=1 + > EOF + + $ hg init lock-checker + $ cd lock-checker + $ hg buggylocking + "lock" taken before "wlock" + $ cat << EOF >> $HGRCPATH + > [devel] + > all=0 + > check-locks=1 + > EOF + $ hg buggylocking + "lock" taken before "wlock" + $ hg buggylocking --traceback + "lock" taken before "wlock" + at: + */hg:* in (glob) + */mercurial/dispatch.py:* in run (glob) + */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _runcatch (glob) + */mercurial/dispatch.py:* in _dispatch (glob) + */mercurial/dispatch.py:* in runcommand (glob) + */mercurial/dispatch.py:* in _runcommand (glob) + */mercurial/dispatch.py:* in checkargs (glob) + */mercurial/dispatch.py:* in (glob) + */mercurial/util.py:* in check (glob) + $TESTTMP/buggylocking.py:* in buggylocking (glob) + $ cd ..