Merge with mercurial/tonfa
authorThomas Arendsen Hein <thomas@intevation.de>
Wed, 22 Feb 2006 08:04:46 +0100
changeset 1789 d5248726d22f
parent 1786 ffb584a182d1 (current diff)
parent 1788 750b9cd83965 (diff)
child 1791 1ed9e97d9d6d
Merge with mercurial/tonfa
mercurial/localrepo.py
--- a/doc/hgrc.5.txt	Wed Feb 22 07:51:32 2006 +0100
+++ b/doc/hgrc.5.txt	Wed Feb 22 08:04:46 2006 +0100
@@ -247,6 +247,9 @@
     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
--- a/mercurial/localrepo.py	Wed Feb 22 07:51:32 2006 +0100
+++ b/mercurial/localrepo.py	Wed Feb 22 08:04:46 2006 +0100
@@ -270,7 +270,14 @@
             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
--- a/mercurial/lock.py	Wed Feb 22 07:51:32 2006 +0100
+++ b/mercurial/lock.py	Wed Feb 22 08:04:46 2006 +0100
@@ -16,10 +16,10 @@
     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 @@
         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