diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -1302,7 +1302,7 @@ def debuglocks(ui, repo, **opts): repo.svfs.unlink('lock') if opts.get(r'force_wlock'): repo.vfs.unlink('wlock') - if opts.get(r'force_lock') or opts.get(r'force_lock'): + if opts.get(r'force_lock') or opts.get(r'force_wlock'): return 0 now = time.time() diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t --- a/tests/test-debugcommands.t +++ b/tests/test-debugcommands.t @@ -145,6 +145,122 @@ Test max chain len 7 6 -1 ??? ??? ??? ??? ??? 0 ??? ???? ? 1 2 (glob) 8 7 -1 ??? ??? ??? ??? ??? 0 ??? ???? ? 1 3 (glob) +Test debuglocks command: + + $ hg debuglocks + lock: free + wlock: free + +* Test setting the lock + +waitlock will wait for file to be created. If it isn't in a reasonable +amount of time, displays error message and returns 1 + $ waitlock() { + > start=`date +%s` + > timeout=1 + > while [ \( ! -f $1 \) -a \( ! -L $1 \) ]; do + > now=`date +%s` + > if [ "`expr $now - $start`" -gt $timeout ]; then + > echo "timeout: $1 was not created in $timeout seconds" + > return 1 + > fi + > sleep 0.1 + > done + > } +dolock [wlock] [lock] will set the locks until interrupted + $ dolock() { + > declare -A options + > options=([${1:-nolock}]=1 [${2:-nowlock}]=1) + > python < from mercurial import hg, ui as uimod + > import os + > import time + > + > repo = hg.repository(uimod.ui.load(), path='.') + > `[ -n "${options["wlock"]}" ] && echo "with repo.wlock(False):" || echo "if True:"` + > `[ -n "${options["lock"]}" ] && echo "with repo.lock(False):" || echo "if True:"` + > while not os.path.exists('.hg/unlock'): + > time.sleep(0.1) + > os.unlink('.hg/unlock') + > EOF + > } + + $ dolock lock & + $ waitlock .hg/store/lock + + $ hg debuglocks + lock: user *, process * (*s) (glob) + wlock: free + [1] + $ touch .hg/unlock + $ wait + +* Test setting the wlock + + $ dolock wlock & + $ waitlock .hg/wlock + + $ hg debuglocks + lock: free + wlock: user *, process * (*s) (glob) + [1] + $ touch .hg/unlock + $ wait + +* Test setting both locks + + $ dolock wlock lock & + $ waitlock .hg/wlock && waitlock .hg/store/lock + + $ hg debuglocks + lock: user *, process * (*s) (glob) + wlock: user *, process * (*s) (glob) + [2] + $ touch .hg/unlock + $ wait + + $ hg debuglocks + lock: free + wlock: free + +* Test forcing the lock + + $ dolock lock & + $ waitlock .hg/store/lock + + $ hg debuglocks + lock: user *, process * (*s) (glob) + wlock: free + [1] + + $ hg debuglocks -L + + $ hg debuglocks + lock: free + wlock: free + + $ touch .hg/unlock + $ wait + +* Test forcing the wlock + + $ dolock wlock & + $ waitlock .hg/wlock + + $ hg debuglocks + lock: free + wlock: user *, process * (*s) (glob) + [1] + + $ hg debuglocks -W + + $ hg debuglocks + lock: free + wlock: free + + $ touch .hg/unlock + $ wait + Test WdirUnsupported exception $ hg debugdata -c ffffffffffffffffffffffffffffffffffffffff