# HG changeset patch # User Matt Mackall # Date 2009-01-12 17:09:14 # Node ID 7197812e8d446b06b7fff752370bc311ec49eab4 # Parent ae7a614a6a57421f515b62ce64ce6beb5d3c7b71 error: move lock errors rename LockException to LockError diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -63,13 +63,13 @@ def _runcatch(ui, args): commands.help_(ui, 'shortlist') except error.RepoError, inst: ui.warn(_("abort: %s!\n") % inst) - except lock.LockHeld, inst: + except error.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 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) - except lock.LockUnavailable, inst: + except error.LockUnavailable, inst: ui.warn(_("abort: could not lock %s: %s\n") % (inst.desc or inst.filename, inst.strerror)) except error.RevlogError, inst: diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -33,3 +33,16 @@ class RepoError(Exception): class CapabilityError(RepoError): pass + +class LockError(IOError): + def __init__(self, errno, strerror, filename, desc): + IOError.__init__(self, errno, strerror, filename) + self.desc = desc + +class LockHeld(LockError): + def __init__(self, errno, filename, desc, locker): + LockError.__init__(self, errno, 'Lock held', filename, desc) + self.locker = locker + +class LockUnavailable(LockError): + pass diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -8,7 +8,7 @@ from i18n import _ import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo -import errno, lock, os, shutil, util, extensions +import errno, lock, os, shutil, util, extensions, error import merge as _merge import verify as _verify @@ -161,7 +161,7 @@ def clone(ui, source, dest=None, pull=Fa # not pointed to by changesets, thus causing verify to # fail src_lock = src_repo.lock() - except lock.LockException: + except error.LockError: copy = False if copy: diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -637,7 +637,7 @@ class localrepository(repo.repository): def _lock(self, lockname, wait, releasefn, acquirefn, desc): try: l = lock.lock(lockname, 0, releasefn, desc=desc) - except lock.LockHeld, inst: + except error.LockHeld, inst: if not wait: raise self.ui.warn(_("waiting for lock on %s held by %r\n") % @@ -1023,7 +1023,7 @@ class localrepository(repo.repository): wlock = self.wlock(False) for f in fixup: self.dirstate.normal(f) - except lock.LockException: + except lock.LockError: pass finally: del wlock diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -5,20 +5,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import errno, os, socket, time, util - -class LockException(IOError): - def __init__(self, errno, strerror, filename, desc): - IOError.__init__(self, errno, strerror, filename) - self.desc = desc - -class LockHeld(LockException): - def __init__(self, errno, filename, desc, locker): - LockException.__init__(self, errno, 'Lock held', filename, desc) - self.locker = locker - -class LockUnavailable(LockException): - pass +import errno, os, socket, time, util, error class lock(object): # lock is symlink on platforms that support it, file on others. @@ -48,14 +35,14 @@ class lock(object): try: self.trylock() return 1 - except LockHeld, inst: + except error.LockHeld, inst: if timeout != 0: time.sleep(1) if timeout > 0: timeout -= 1 continue - raise LockHeld(errno.ETIMEDOUT, inst.filename, self.desc, - inst.locker) + raise error.LockHeld(errno.ETIMEDOUT, inst.filename, self.desc, + inst.locker) def trylock(self): if lock._host is None: @@ -69,11 +56,11 @@ class lock(object): if why.errno == errno.EEXIST: locker = self.testlock() if locker is not None: - raise LockHeld(errno.EAGAIN, self.f, self.desc, - locker) + raise error.LockHeld(errno.EAGAIN, self.f, self.desc, + locker) else: - raise LockUnavailable(why.errno, why.strerror, - why.filename, self.desc) + raise error.LockUnavailable(why.errno, why.strerror, + why.filename, self.desc) def testlock(self): """return id of locker if lock is valid, else None. @@ -106,7 +93,7 @@ class lock(object): l.trylock() os.unlink(self.f) l.release() - except (LockHeld, LockUnavailable): + except error.LockError: return locker def release(self): diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py --- a/mercurial/streamclone.py +++ b/mercurial/streamclone.py @@ -5,7 +5,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import util, lock +import util, error from i18n import _ class StreamException(Exception): @@ -51,7 +51,7 @@ def stream_out(repo, untrusted=False): total_bytes += size finally: del l - except (lock.LockHeld, lock.LockUnavailable): + except error.LockError: raise StreamException(2) yield '0\n'