[PATCH 1 of 3] localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich
mads at kiilerich.com
Wed Feb 5 19:19:56 CST 2014
# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1391648109 -3600
# Thu Feb 06 01:55:09 2014 +0100
# Node ID ec0a56b03d3aa27ce484693c559cdffd80468758
# Parent aa51392da50763f3e7b9ec40acc3a97682488b66
localrepo: give a sigh of relief when getting lock after waiting for it
A message like this was sometimes shown when pushing:
remote: waiting for lock on repository foo held by 'mercurial:20858'
That could scare users, making them wonder whether the push actually succeeded.
To mitigate that fear, issue an additional "warning" such as:
got lock after 2 seconds
The return value from lock.lock.lock() was unused - instead we return the
delay.
This also adds the first test coverage for waiting for locks.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1005,6 +1005,7 @@ class localrepository(object):
l = lockmod.lock(vfs, lockname,
int(self.ui.config("ui", "timeout", "600")),
releasefn, desc=desc)
+ self.ui.warn(_("got lock after %s seconds\n") % l.delay)
if acquirefn:
acquirefn()
return l
diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -38,7 +38,7 @@ class lock(object):
self.desc = desc
self.postrelease = []
self.pid = os.getpid()
- self.lock()
+ self.delay = self.lock()
def __del__(self):
if self.held:
@@ -57,7 +57,7 @@ class lock(object):
while True:
try:
self.trylock()
- return 1
+ return self.timeout - timeout
except error.LockHeld, inst:
if timeout != 0:
time.sleep(1)
diff --git a/tests/test-lock-badness.t b/tests/test-lock-badness.t
--- a/tests/test-lock-badness.t
+++ b/tests/test-lock-badness.t
@@ -1,4 +1,7 @@
-#if unix-permissions no-root
+#if unix-permissions no-root no-windows
+
+Prepare
+
$ hg init a
$ echo a > a/a
$ hg -R a ci -A -m a
@@ -8,10 +11,25 @@
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+One process waiting for another
+
+ $ cat > hooks.py << EOF
+ > import time
+ > def sleepone(**x): time.sleep(1)
+ > def sleephalf(**x): time.sleep(0.5)
+ > EOF
$ echo b > b/b
- $ hg -R b ci -A -m b
+ $ hg -R b ci -A -m b --config hooks.precommit="python:`pwd`/hooks.py:sleepone" > stdout &
+ $ hg -R b up -q --config hooks.pre-update="python:`pwd`/hooks.py:sleephalf"
+ waiting for lock on working directory of b held by '*:*' (glob)
+ got lock after 1 seconds
+ warning: ignoring unknown working parent d2ae7f538514!
+ $ wait
+ $ cat stdout
adding b
+Pushing to a local read-only repo that can't be locked
+
$ chmod 100 a/.hg/store
$ hg -R b push a
More information about the Mercurial-devel
mailing list