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