wlock: only issue devel warning when actually acquiring the lock
Before this change, any call to 'wlock' after we acquired a 'lock' was issuing a
warning. This is wrong as the 'wlock' have been properly acquired before the
'lock' in a previous call.
We move the warning code to only issue such warnings when we are acquiring the
'wlock' -after- acquiring 'lock'. This is the expected behavior of this warning
from the start.
--- a/mercurial/localrepo.py Sat Apr 11 17:30:45 2015 -0400
+++ b/mercurial/localrepo.py Sun Apr 12 10:01:48 2015 -0400
@@ -1204,6 +1204,11 @@
'''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.'''
+ l = self._wlockref and self._wlockref()
+ if l is not None and l.held:
+ l.lock()
+ return l
+
if (self.ui.configbool('devel', 'all')
or self.ui.configbool('devel', 'check-locks')):
l = self._lockref and self._lockref()
@@ -1213,10 +1218,6 @@
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()
- return l
def unlock():
if self.dirstate.pendingparentchange():
--- a/tests/test-devel-warnings.t Sat Apr 11 17:30:45 2015 -0400
+++ b/tests/test-devel-warnings.t Sun Apr 12 10:01:48 2015 -0400
@@ -15,6 +15,22 @@
> wl = repo.wlock()
> wl.release()
> lo.release()
+ >
+ > @command('properlocking', [], '')
+ > def properlocking(ui, repo):
+ > """check that reentrance is fine"""
+ > wl = repo.wlock()
+ > lo = repo.lock()
+ > tr = repo.transaction('proper')
+ > tr2 = repo.transaction('proper')
+ > lo2 = repo.lock()
+ > wl2 = repo.wlock()
+ > wl2.release()
+ > lo2.release()
+ > tr2.close()
+ > tr.close()
+ > lo.release()
+ > wl.release()
> EOF
$ cat << EOF >> $HGRCPATH
@@ -64,4 +80,5 @@
*/mercurial/dispatch.py:* in <lambda> (glob)
*/mercurial/util.py:* in check (glob)
$TESTTMP/buggylocking.py:* in buggylocking (glob)
+ $ hg properlocking
$ cd ..