diff mercurial/commands.py @ 2016:ff5c9a92f556

fix backtrace printed when cannot get lock. change lock error handling code so exceptions have useful info and exception handling in one place. add test case for when cannot get lock.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Tue, 28 Mar 2006 09:01:07 -0800
parents 4c70b10f0418
children 00925397236c
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Mar 26 22:54:05 2006 +0200
+++ b/mercurial/commands.py	Tue Mar 28 09:01:07 2006 -0800
@@ -1244,12 +1244,8 @@
     should properly record copied files, this information is not yet
     fully used by merge, nor fully reported by log.
     """
-    try:
-        wlock = repo.wlock(0)
-        errs, copied = docopy(ui, repo, pats, opts, wlock)
-    except lock.LockHeld, inst:
-        ui.warn(_("repository lock held by %s\n") % inst.args[0])
-        errs = 1
+    wlock = repo.wlock(0)
+    errs, copied = docopy(ui, repo, pats, opts, wlock)
     return errs
 
 def debugancestor(ui, index, rev1, rev2):
@@ -2256,18 +2252,14 @@
     should properly record rename files, this information is not yet
     fully used by merge, nor fully reported by log.
     """
-    try:
-        wlock = repo.wlock(0)
-        errs, copied = docopy(ui, repo, pats, opts, wlock)
-        names = []
-        for abs, rel, exact in copied:
-            if ui.verbose or not exact:
-                ui.status(_('removing %s\n') % rel)
-            names.append(abs)
-        repo.remove(names, True, wlock)
-    except lock.LockHeld, inst:
-        ui.warn(_("repository lock held by %s\n") % inst.args[0])
-        errs = 1
+    wlock = repo.wlock(0)
+    errs, copied = docopy(ui, repo, pats, opts, wlock)
+    names = []
+    for abs, rel, exact in copied:
+        if ui.verbose or not exact:
+            ui.status(_('removing %s\n') % rel)
+        names.append(abs)
+    repo.remove(names, True, wlock)
     return errs
 
 def revert(ui, repo, *pats, **opts):
@@ -3252,6 +3244,15 @@
         sys.exit(1)
     except hg.RepoError, inst:
         u.warn(_("abort: "), inst, "!\n")
+    except lock.LockHeld, inst:
+        if inst.errno == errno.ETIMEDOUT:
+            reason = _('timed out waiting for lock held by %s') % inst.locker
+        else:
+            reason = _('lock held by %s') % inst.locker
+        u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
+    except lock.LockUnavailable, inst:
+        u.warn(_("abort: could not lock %s: %s\n") %
+               (inst.desc or inst.filename, inst.strerror))
     except revlog.RevlogError, inst:
         u.warn(_("abort: "), inst, "!\n")
     except SignalInterrupt: