devel: also warn about transaction started without a lock
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 10 Mar 2015 21:03:45 -0700
changeset 24388 026f8af88e49
parent 24387 32e16e9cf2cf
child 24389 93d3e1a8bfb0
devel: also warn about transaction started without a lock Nobody should start a transaction on an unlocked repository. If developer warnings are enabled this will be reported. This use the same config as bad locking order since this is closely related.
mercurial/localrepo.py
tests/test-devel-warnings.t
--- a/mercurial/localrepo.py	Tue Mar 10 21:25:11 2015 -0700
+++ b/mercurial/localrepo.py	Tue Mar 10 21:03:45 2015 -0700
@@ -919,6 +919,15 @@
         return None
 
     def transaction(self, desc, report=None):
+        if (self.ui.configbool('devel', 'all')
+                or self.ui.configbool('devel', 'check-locks')):
+            l = self._lockref and self._lockref()
+            if l is None or not l.held:
+                msg = 'transaction with no lock\n'
+                if self.ui.tracebackflag:
+                    util.debugstacktrace(msg, 1)
+                else:
+                    self.ui.write_err(msg)
         tr = self.currenttransaction()
         if tr is not None:
             return tr.nest()
--- a/tests/test-devel-warnings.t	Tue Mar 10 21:25:11 2015 -0700
+++ b/tests/test-devel-warnings.t	Tue Mar 10 21:03:45 2015 -0700
@@ -10,6 +10,7 @@
   > 
   > @command('buggylocking', [], '')
   > def buggylocking(ui, repo):
+  >     tr = repo.transaction('buggy')
   >     lo = repo.lock()
   >     wl = repo.wlock()
   > EOF
@@ -24,6 +25,7 @@
   $ hg init lock-checker
   $ cd lock-checker
   $ hg buggylocking
+  transaction with no lock
   "lock" taken before "wlock"
   $ cat << EOF >> $HGRCPATH
   > [devel]
@@ -31,8 +33,22 @@
   > check-locks=1
   > EOF
   $ hg buggylocking
+  transaction with no lock
   "lock" taken before "wlock"
   $ hg buggylocking --traceback
+  transaction with no lock
+   at:
+   */hg:* in <module> (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 <lambda> (glob)
+   */mercurial/util.py:* in check (glob)
+   $TESTTMP/buggylocking.py:* in buggylocking (glob)
   "lock" taken before "wlock"
    at:
    */hg:* in <module> (glob)