error: move repo errors
authorMatt Mackall <mpm@selenic.com>
Mon, 12 Jan 2009 10:42:31 -0600
changeset 7637 1d54e2f6c0b7
parent 7636 e3f8c6d6b72e
child 7638 f83a2b1d1a71
error: move repo errors rename NoCapability to CapabilityError
hgext/bookmarks.py
hgext/convert/hg.py
hgext/mq.py
hgext/parentrevspec.py
mercurial/bundlerepo.py
mercurial/commands.py
mercurial/dispatch.py
mercurial/error.py
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/hgwebdir_mod.py
mercurial/hgweb/server.py
mercurial/hgweb/webcommands.py
mercurial/hgweb/webutil.py
mercurial/httprepo.py
mercurial/localrepo.py
mercurial/repo.py
mercurial/sshrepo.py
mercurial/statichttprepo.py
--- a/hgext/bookmarks.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/hgext/bookmarks.py	Mon Jan 12 10:42:31 2009 -0600
@@ -30,7 +30,6 @@
 from mercurial.i18n import _
 from mercurial import cmdutil, util, commands, changelog
 from mercurial.node import nullid, nullrev
-from mercurial.repo import RepoError
 import mercurial, mercurial.localrepo, mercurial.repair, os
 
 def parse(repo):
--- a/hgext/convert/hg.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/hgext/convert/hg.py	Mon Jan 12 10:42:31 2009 -0600
@@ -15,7 +15,6 @@
 
 import os, time
 from mercurial.i18n import _
-from mercurial.repo import RepoError
 from mercurial.node import bin, hex, nullid
 from mercurial import hg, util, context, error
 
@@ -33,7 +32,7 @@
                 self.repo = hg.repository(self.ui, path)
                 if not self.repo.local():
                     raise NoRepo(_('%s is not a local Mercurial repo') % path)
-            except RepoError, err:
+            except error.RepoError, err:
                 ui.print_exc()
                 raise NoRepo(err.args[0])
         else:
@@ -43,7 +42,7 @@
                 if not self.repo.local():
                     raise NoRepo(_('%s is not a local Mercurial repo') % path)
                 self.created.append(path)
-            except RepoError, err:
+            except error.RepoError, err:
                 ui.print_exc()
                 raise NoRepo("could not create hg repo %s as sink" % path)
         self.lock = None
@@ -159,7 +158,7 @@
          try:
              parentctx = self.repo[self.tagsbranch]
              tagparent = parentctx.node()
-         except RepoError, inst:
+         except error.RepoError, inst:
              parentctx = None
              tagparent = nullid
 
@@ -200,8 +199,8 @@
             # try to provoke an exception if this isn't really a hg
             # repo, but some other bogus compatible-looking url
             if not self.repo.local():
-                raise RepoError()
-        except RepoError:
+                raise error.RepoError()
+        except error.RepoError:
             ui.print_exc()
             raise NoRepo("%s is not a local Mercurial repo" % path)
         self.lastrev = None
@@ -213,7 +212,7 @@
         if startnode is not None:
             try:
                 startnode = self.repo.lookup(startnode)
-            except repo.RepoError:
+            except error.RepoError:
                 raise util.Abort(_('%s is not a valid start revision')
                                  % startnode)
             startrev = self.repo.changelog.rev(startnode)
--- a/hgext/mq.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/hgext/mq.py	Mon Jan 12 10:42:31 2009 -0600
@@ -31,9 +31,8 @@
 
 from mercurial.i18n import _
 from mercurial.node import bin, hex, short
-from mercurial.repo import RepoError
 from mercurial import commands, cmdutil, hg, patch, revlog, util
-from mercurial import repair, extensions, url
+from mercurial import repair, extensions, url, error
 import os, sys, re, errno
 
 commands.norepo += " qclone"
@@ -1741,7 +1740,7 @@
     patchespath = opts['patches'] or patchdir(sr)
     try:
         pr = hg.repository(ui, patchespath)
-    except RepoError:
+    except error.RepoError:
         raise util.Abort(_('versioned patch repository not found'
                            ' (see qinit -c)'))
     qbase, destrev = None, None
@@ -1757,7 +1756,7 @@
     elif sr.capable('lookup'):
         try:
             qbase = sr.lookup('qbase')
-        except RepoError:
+        except error.RepoError:
             pass
     ui.note(_('cloning main repo\n'))
     sr, dr = hg.clone(ui, sr.url(), dest,
--- a/hgext/parentrevspec.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/hgext/parentrevspec.py	Mon Jan 12 10:42:31 2009 -0600
@@ -24,6 +24,7 @@
   foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
 '''
 import mercurial.repo
+from mercurial import error
 
 def reposetup(ui, repo):
     if not repo.local():
@@ -34,7 +35,7 @@
             try:
                 _super = super(parentrevspecrepo, self)
                 return _super.lookup(key)
-            except mercurial.repo.RepoError:
+            except error.RepoError:
                 pass
 
             circ = key.find('^')
@@ -50,7 +51,7 @@
             base = key[:end]
             try:
                 node = _super.lookup(base)
-            except mercurial.repo.RepoError:
+            except error.RepoError:
                 # eek - reraise the first error
                 return _super.lookup(key)
 
--- a/mercurial/bundlerepo.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/bundlerepo.py	Mon Jan 12 10:42:31 2009 -0600
@@ -156,7 +156,7 @@
         self._tempparent = None
         try:
             localrepo.localrepository.__init__(self, ui, path)
-        except repo.RepoError:
+        except error.RepoError:
             self._tempparent = tempfile.mkdtemp()
             tmprepo = localrepo.instance(ui,self._tempparent,1)
             localrepo.localrepository.__init__(self, ui, self._tempparent)
--- a/mercurial/commands.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/commands.py	Mon Jan 12 10:42:31 2009 -0600
@@ -6,7 +6,6 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 from node import hex, nullid, nullrev, short
-from repo import RepoError, NoCapability
 from i18n import _, gettext
 import os, re, sys
 import hg, util, revlog, bundlerepo, extensions, copies, context, error
@@ -1671,7 +1670,7 @@
                         p2 = repo.lookup(p2)
                         if p1 == wp[0].node():
                             repo.dirstate.setparents(p1, p2)
-                    except RepoError:
+                    except error.RepoError:
                         pass
                 if opts.get('exact') or opts.get('import_branch'):
                     repo.dirstate.setbranch(branch or 'default')
@@ -2179,10 +2178,10 @@
     if revs:
         try:
             revs = [other.lookup(rev) for rev in revs]
-        except NoCapability:
-            error = _("Other repository doesn't support revision lookup, "
-                      "so a rev cannot be specified.")
-            raise util.Abort(error)
+        except error.CapabilityError:
+            err = _("Other repository doesn't support revision lookup, "
+                    "so a rev cannot be specified.")
+            raise util.Abort(err)
 
     modheads = repo.pull(other, heads=revs, force=opts.get('force'))
     return postincoming(ui, repo, modheads, opts.get('update'), checkout)
@@ -2649,7 +2648,7 @@
 
     if opts["stdio"]:
         if repo is None:
-            raise RepoError(_("There is no Mercurial repository here"
+            raise error.RepoError(_("There is no Mercurial repository here"
                               " (.hg not found)"))
         s = sshserver.sshserver(ui, repo)
         s.serve_forever()
@@ -2664,8 +2663,8 @@
                 repo.ui.setconfig("web", o, str(opts[o]))
 
     if repo is None and not ui.config("web", "webdir_conf"):
-        raise RepoError(_("There is no Mercurial repository here"
-                          " (.hg not found)"))
+        raise error.RepoError(_("There is no Mercurial repository here"
+                                " (.hg not found)"))
 
     class service:
         def init(self):
--- a/mercurial/dispatch.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/dispatch.py	Mon Jan 12 10:42:31 2009 -0600
@@ -6,7 +6,6 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 from i18n import _
-from repo import RepoError
 import os, sys, atexit, signal, pdb, socket, errno, shlex, time
 import util, commands, hg, lock, fancyopts, extensions, hook, error
 import cmdutil
@@ -62,7 +61,7 @@
     except cmdutil.UnknownCommand, inst:
         ui.warn(_("hg: unknown command '%s'\n") % inst.args[0])
         commands.help_(ui, 'shortlist')
-    except RepoError, inst:
+    except error.RepoError, inst:
         ui.warn(_("abort: %s!\n") % inst)
     except lock.LockHeld, inst:
         if inst.errno == errno.ETIMEDOUT:
@@ -342,7 +341,7 @@
             if not repo.local():
                 raise util.Abort(_("repository '%s' is not local") % path)
             ui.setconfig("bundle", "mainreporoot", repo.root)
-        except RepoError:
+        except error.RepoError:
             if cmd not in commands.optionalrepo.split():
                 if args and not path: # try to infer -R from command args
                     repos = map(_findrepo, args)
@@ -350,8 +349,8 @@
                     if guess and repos.count(guess) == len(repos):
                         return _dispatch(ui, ['--repository', guess] + fullargs)
                 if not path:
-                    raise RepoError(_("There is no Mercurial repository here"
-                                      " (.hg not found)"))
+                    raise error.RepoError(_("There is no Mercurial repository"
+                                      " here (.hg not found)"))
                 raise
         args.insert(0, repo)
 
--- a/mercurial/error.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/error.py	Mon Jan 12 10:42:31 2009 -0600
@@ -27,3 +27,9 @@
 
 class ParseError(Exception):
     """Exception raised on errors in parsing the command line."""
+
+class RepoError(Exception):
+    pass
+
+class CapabilityError(RepoError):
+    pass
--- a/mercurial/hgweb/hgweb_mod.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Jan 12 10:42:31 2009 -0600
@@ -8,7 +8,6 @@
 
 import os, mimetypes
 from mercurial.node import hex, nullid
-from mercurial.repo import RepoError
 from mercurial import ui, hg, util, hook, error
 from mercurial import templater, templatefilters
 from common import get_mtime, style_map, ErrorResponse
@@ -191,7 +190,7 @@
             if 'manifest' not in msg:
                 msg = 'revision not found: %s' % err.name
             return tmpl('error', error=msg)
-        except (RepoError, error.RevlogError), inst:
+        except (error.RepoError, error.RevlogError), inst:
             req.respond(HTTP_SERVER_ERROR, ctype)
             return tmpl('error', error=str(inst))
         except ErrorResponse, inst:
--- a/mercurial/hgweb/hgwebdir_mod.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/hgweb/hgwebdir_mod.py	Mon Jan 12 10:42:31 2009 -0600
@@ -8,8 +8,7 @@
 
 import os
 from mercurial.i18n import _
-from mercurial.repo import RepoError
-from mercurial import ui, hg, util, templater, templatefilters
+from mercurial import ui, hg, util, templater, templatefilters, error
 from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen,\
                    get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
 from hgweb_mod import hgweb
@@ -150,7 +149,7 @@
                         except IOError, inst:
                             msg = inst.strerror
                             raise ErrorResponse(HTTP_SERVER_ERROR, msg)
-                        except RepoError, inst:
+                        except error.RepoError, inst:
                             raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
 
                     # browse subdirectories
--- a/mercurial/hgweb/server.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/hgweb/server.py	Mon Jan 12 10:42:31 2009 -0600
@@ -7,8 +7,7 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 import os, sys, errno, urllib, BaseHTTPServer, socket, SocketServer, traceback
-from mercurial import hg, util
-from mercurial.repo import RepoError
+from mercurial import hg, util, error
 from hgweb_mod import hgweb
 from hgwebdir_mod import hgwebdir
 from mercurial.i18n import _
@@ -249,8 +248,8 @@
                 elif repo is not None:
                     hgwebobj = hgweb(hg.repository(repo.ui, repo.root))
                 else:
-                    raise RepoError(_("There is no Mercurial repository here"
-                                      " (.hg not found)"))
+                    raise error.RepoError(_("There is no Mercurial repository"
+                                            " here (.hg not found)"))
                 return hgwebobj
             self.application = make_handler()
 
--- a/mercurial/hgweb/webcommands.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/hgweb/webcommands.py	Mon Jan 12 10:42:31 2009 -0600
@@ -10,7 +10,6 @@
 from mercurial import error, archival, templatefilters
 from mercurial.node import short, hex, nullid
 from mercurial.util import binary, datestr
-from mercurial.repo import RepoError
 from common import paritygen, staticfile, get_contact, ErrorResponse
 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
 from mercurial import graphmod, util
@@ -169,7 +168,7 @@
             hi = len(web.repo) - 1
         try:
             ctx = web.repo[hi]
-        except RepoError:
+        except error.RepoError:
             return _search(web, tmpl, hi) # XXX redirect to 404 page?
 
     def changelist(limit=0, **map):
--- a/mercurial/hgweb/webutil.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/hgweb/webutil.py	Mon Jan 12 10:42:31 2009 -0600
@@ -7,10 +7,8 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 import os, copy
-from mercurial import match, patch
+from mercurial import match, patch, util, error
 from mercurial.node import hex, nullid
-from mercurial.repo import RepoError
-from mercurial import util
 
 def up(p):
     if p[0] != "/":
@@ -55,7 +53,7 @@
                 yield {"label": label, "node": node}
 
             yield {"label": "tip", "node": "tip"}
-        except RepoError:
+        except error.RepoError:
             pass
 
     return nav
@@ -124,7 +122,7 @@
 
     try:
         ctx = repo[changeid]
-    except RepoError:
+    except error.RepoError:
         man = repo.manifest
         ctx = repo[man.linkrev(man.rev(man.lookup(changeid)))]
 
@@ -138,7 +136,7 @@
         changeid = req.form['filenode'][0]
     try:
         fctx = repo[changeid][path]
-    except RepoError:
+    except error.RepoError:
         fctx = repo.filectx(path, fileid=changeid)
 
     return fctx
--- a/mercurial/httprepo.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/httprepo.py	Mon Jan 12 10:42:31 2009 -0600
@@ -9,8 +9,7 @@
 from node import bin, hex, nullid
 from i18n import _
 import repo, os, urllib, urllib2, urlparse, zlib, util, httplib
-import errno, socket, changegroup, statichttprepo
-import url
+import errno, socket, changegroup, statichttprepo, error, url
 
 def zgenerator(f):
     zd = zlib.decompressobj()
@@ -48,7 +47,7 @@
         if self.caps is None:
             try:
                 self.caps = util.set(self.do_read('capabilities').split())
-            except repo.RepoError:
+            except error.RepoError:
                 self.caps = util.set()
             self.ui.debug(_('capabilities: %s\n') %
                           (' '.join(self.caps or ['none'])))
@@ -99,19 +98,19 @@
                 proto.startswith('text/plain') or
                 proto.startswith('application/hg-changegroup')):
             self.ui.debug(_("Requested URL: '%s'\n") % cu)
-            raise repo.RepoError(_("'%s' does not appear to be an hg repository")
-                               % self._url)
+            raise error.RepoError(_("'%s' does not appear to be an hg repository")
+                                  % self._url)
 
         if proto.startswith('application/mercurial-'):
             try:
                 version = proto.split('-', 1)[1]
                 version_info = tuple([int(n) for n in version.split('.')])
             except ValueError:
-                raise repo.RepoError(_("'%s' sent a broken Content-Type "
-                                     "header (%s)") % (self._url, proto))
+                raise error.RepoError(_("'%s' sent a broken Content-Type "
+                                        "header (%s)") % (self._url, proto))
             if version_info > (0, 1):
-                raise repo.RepoError(_("'%s' uses newer protocol %s") %
-                                   (self._url, version))
+                raise error.RepoError(_("'%s' uses newer protocol %s") %
+                                      (self._url, version))
 
         return resp
 
@@ -129,7 +128,7 @@
         success, data = d[:-1].split(' ', 1)
         if int(success):
             return bin(data)
-        raise repo.RepoError(data)
+        raise error.RepoError(data)
 
     def heads(self):
         d = self.do_read("heads")
@@ -233,6 +232,6 @@
             inst = httprepository(ui, path)
         inst.between([(nullid, nullid)])
         return inst
-    except repo.RepoError:
+    except error.RepoError:
         ui.note('(falling back to static-http)\n')
         return statichttprepo.instance(ui, "static-" + path, create)
--- a/mercurial/localrepo.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/localrepo.py	Mon Jan 12 10:42:31 2009 -0600
@@ -47,9 +47,9 @@
                     reqfile.write("%s\n" % r)
                 reqfile.close()
             else:
-                raise repo.RepoError(_("repository %s not found") % path)
+                raise error.RepoError(_("repository %s not found") % path)
         elif create:
-            raise repo.RepoError(_("repository %s already exists") % path)
+            raise error.RepoError(_("repository %s already exists") % path)
         else:
             # find requirements
             requirements = []
@@ -57,7 +57,7 @@
                 requirements = self.opener("requires").read().splitlines()
                 for r in requirements:
                     if r not in self.supported:
-                        raise repo.RepoError(_("requirement '%s' not supported") % r)
+                        raise error.RepoError(_("requirement '%s' not supported") % r)
             except IOError, inst:
                 if inst.errno != errno.ENOENT:
                     raise
@@ -460,7 +460,7 @@
                 key = hex(key)
         except:
             pass
-        raise repo.RepoError(_("unknown revision '%s'") % key)
+        raise error.RepoError(_("unknown revision '%s'") % key)
 
     def local(self):
         return True
@@ -566,7 +566,7 @@
 
         # abort here if the journal already exists
         if os.path.exists(self.sjoin("journal")):
-            raise repo.RepoError(_("journal already exists - run hg recover"))
+            raise error.RepoError(_("journal already exists - run hg recover"))
 
         # save dirstate for rollback
         try:
@@ -1393,7 +1393,8 @@
         # sanity check our fetch list
         for f in fetch.keys():
             if f in m:
-                raise repo.RepoError(_("already have changeset ") + short(f[:4]))
+                raise error.RepoError(_("already have changeset ")
+                                      + short(f[:4]))
 
         if base.keys() == [nullid]:
             if force:
--- a/mercurial/repo.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/repo.py	Mon Jan 12 10:42:31 2009 -0600
@@ -8,12 +8,6 @@
 
 from i18n import _
 
-class RepoError(Exception):
-    pass
-
-class NoCapability(RepoError):
-    pass
-
 class repository(object):
     def capable(self, name):
         '''tell whether repo supports named capability.
@@ -31,9 +25,9 @@
     def requirecap(self, name, purpose):
         '''raise an exception if the given capability is not present'''
         if not self.capable(name):
-            raise NoCapability(_('cannot %s; remote repository does not '
-                                 'support the %r capability') %
-                               (purpose, name))
+            raise error.CapabilityError(
+                _('cannot %s; remote repository does not '
+                  'support the %r capability') % (purpose, name))
 
     def local(self):
         return False
--- a/mercurial/sshrepo.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/sshrepo.py	Mon Jan 12 10:42:31 2009 -0600
@@ -7,7 +7,7 @@
 
 from node import bin, hex
 from i18n import _
-import repo, os, re, util
+import repo, os, re, util, error
 
 class remotelock(object):
     def __init__(self, repo):
@@ -26,7 +26,7 @@
 
         m = re.match(r'^ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?$', path)
         if not m:
-            self.raise_(repo.RepoError(_("couldn't parse location %s") % path))
+            self.raise_(error.RepoError(_("couldn't parse location %s") % path))
 
         self.user = m.group(2)
         self.host = m.group(3)
@@ -45,7 +45,7 @@
             ui.note(_('running %s\n') % cmd)
             res = util.system(cmd)
             if res != 0:
-                self.raise_(repo.RepoError(_("could not create remote repo")))
+                self.raise_(error.RepoError(_("could not create remote repo")))
 
         self.validate_repo(ui, sshcmd, args, remotecmd)
 
@@ -78,7 +78,7 @@
             lines.append(l)
             max_noise -= 1
         else:
-            self.raise_(repo.RepoError(_("no suitable response from remote hg")))
+            self.raise_(error.RepoError(_("no suitable response from remote hg")))
 
         self.capabilities = util.set()
         lines.reverse()
@@ -157,7 +157,7 @@
         if int(success):
             return bin(data)
         else:
-            self.raise_(repo.RepoError(data))
+            self.raise_(error.RepoError(data))
 
     def heads(self):
         d = self.call("heads")
@@ -198,7 +198,7 @@
         d = self.call("unbundle", heads=' '.join(map(hex, heads)))
         if d:
             # remote may send "unsynced changes"
-            self.raise_(repo.RepoError(_("push refused: %s") % d))
+            self.raise_(error.RepoError(_("push refused: %s") % d))
 
         while 1:
             d = cg.read(4096)
@@ -211,7 +211,7 @@
         r = self._recv()
         if r:
             # remote may send "unsynced changes"
-            self.raise_(repo.RepoError(_("push failed: %s") % r))
+            self.raise_(error.RepoError(_("push failed: %s") % r))
 
         r = self._recv()
         try:
@@ -222,7 +222,7 @@
     def addchangegroup(self, cg, source, url):
         d = self.call("addchangegroup")
         if d:
-            self.raise_(repo.RepoError(_("push refused: %s") % d))
+            self.raise_(error.RepoError(_("push refused: %s") % d))
         while 1:
             d = cg.read(4096)
             if not d:
--- a/mercurial/statichttprepo.py	Sun Jan 11 23:04:24 2009 -0600
+++ b/mercurial/statichttprepo.py	Mon Jan 12 10:42:31 2009 -0600
@@ -8,7 +8,7 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 from i18n import _
-import changelog, byterange, url
+import changelog, byterange, url, error
 import repo, localrepo, manifest, util, store
 import urllib, urllib2, errno
 
@@ -79,13 +79,13 @@
                     raise
                 # we do not care about empty old-style repositories here
                 msg = _("'%s' does not appear to be an hg repository") % path
-                raise repo.RepoError(msg)
+                raise error.RepoError(msg)
             requirements = []
 
         # check them
         for r in requirements:
             if r not in self.supported:
-                raise repo.RepoError(_("requirement '%s' not supported") % r)
+                raise error.RepoError(_("requirement '%s' not supported") % r)
 
         # setup store
         def pjoin(a, b):