# HG changeset patch # User Thomas Arendsen Hein # Date 1140591886 -3600 # Node ID d5248726d22fc6f166ae69756d774f5d92f71ac3 # Parent ffb584a182d1a60c53509f2494a31d3ef7e01b94# Parent 750b9cd8396511d40767cd5e40e4467b3253e043 Merge with mercurial/tonfa diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -247,6 +247,9 @@ ui:: remote command to use for clone/push/pull operations. Default is 'hg'. ssh;; command to use for SSH connections. Default is 'ssh'. + timeout;; + The timeout used when a lock is held (in seconds), a negative value + means no timeout. Default is 600. username;; The committer of a changeset created when running "commit". Typically a person's name and email address, e.g. "Fred Widget diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -270,7 +270,14 @@ class localrepository(object): if not wait: raise inst self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0]) - l = lock.lock(self.join(lockname), wait, releasefn) + try: + # default to 600 seconds timeout + l = lock.lock(self.join(lockname), + int(self.ui.config("ui", "timeout") or 600), + releasefn) + except lock.LockHeld, inst: + raise util.Abort(_("timeout while waiting for " + "lock held by %s") % inst.args[0]) if acquirefn: acquirefn() return l diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -16,10 +16,10 @@ class LockUnavailable(LockException): pass class lock(object): - def __init__(self, file, wait=1, releasefn=None): + def __init__(self, file, timeout=-1, releasefn=None): self.f = file self.held = 0 - self.wait = wait + self.timeout = timeout self.releasefn = releasefn self.lock() @@ -27,13 +27,16 @@ class lock(object): self.release() def lock(self): + timeout = self.timeout while 1: try: self.trylock() return 1 except LockHeld, inst: - if self.wait: + if timeout != 0: time.sleep(1) + if timeout > 0: + timeout -= 1 continue raise inst