localrepo: give a sigh of relief when getting lock after waiting for it
authorMads Kiilerich <madski@unity3d.com>
Thu, 06 Feb 2014 01:55:09 +0100
changeset 20380 c697b70f295f
parent 20379 b75a04502ced
child 20381 fff0a71f8177
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.
mercurial/localrepo.py
mercurial/lock.py
tests/test-lock-badness.t
--- a/mercurial/localrepo.py	Wed Jan 22 15:43:21 2014 -0600
+++ b/mercurial/localrepo.py	Thu Feb 06 01:55:09 2014 +0100
@@ -1005,6 +1005,7 @@
             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
--- a/mercurial/lock.py	Wed Jan 22 15:43:21 2014 -0600
+++ b/mercurial/lock.py	Thu Feb 06 01:55:09 2014 +0100
@@ -38,7 +38,7 @@
         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 @@
         while True:
             try:
                 self.trylock()
-                return 1
+                return self.timeout - timeout
             except error.LockHeld, inst:
                 if timeout != 0:
                     time.sleep(1)
--- a/tests/test-lock-badness.t	Wed Jan 22 15:43:21 2014 -0600
+++ b/tests/test-lock-badness.t	Thu Feb 06 01:55:09 2014 +0100
@@ -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