Mercurial > hg-stable
changeset 7633:08cabecfa8a8
errors: move revlog errors
- create error.py for exception classes to reduce demandloading
- move revlog exceptions to it
- change users to import error and drop revlog import if possible
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 11 Jan 2009 22:48:28 -0600 |
parents | 9626819b2e3d |
children | 14a4337a9b9b |
files | hgext/convert/hg.py hgext/imerge.py hgext/transplant.py mercurial/bundlerepo.py mercurial/changelog.py mercurial/commands.py mercurial/context.py mercurial/dispatch.py mercurial/error.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/webcommands.py mercurial/localrepo.py mercurial/manifest.py mercurial/revlog.py |
diffstat | 14 files changed, 73 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/convert/hg.py Sat Jan 10 18:02:38 2009 -0600 +++ b/hgext/convert/hg.py Sun Jan 11 22:48:28 2009 -0600 @@ -17,7 +17,7 @@ from mercurial.i18n import _ from mercurial.repo import RepoError from mercurial.node import bin, hex, nullid -from mercurial import hg, revlog, util, context +from mercurial import hg, util, context, error from common import NoRepo, commit, converter_source, converter_sink @@ -244,7 +244,7 @@ def getfile(self, name, rev): try: return self.changectx(rev)[name].data() - except revlog.LookupError, err: + except error.LookupError, err: raise IOError(err) def getmode(self, name, rev): @@ -283,7 +283,7 @@ copies[name] = copysource except TypeError: pass - except revlog.LookupError, e: + except error.LookupError, e: if not self.ignoreerrors: raise self.ignored[name] = 1
--- a/hgext/imerge.py Sat Jan 10 18:02:38 2009 -0600 +++ b/hgext/imerge.py Sun Jan 11 22:48:28 2009 -0600 @@ -8,7 +8,7 @@ from mercurial.i18n import _ from mercurial.node import hex, short from mercurial import commands, cmdutil, dispatch, fancyopts -from mercurial import hg, filemerge, util, revlog +from mercurial import hg, filemerge, util, error import os, tarfile class InvalidStateFileException(Exception): pass @@ -78,7 +78,7 @@ try: parents = [self.repo.changectx(n) for n in status[:2]] - except revlog.LookupError, e: + except error.LookupError, e: raise util.Abort(_('merge parent %s not in repository') % short(e.name))
--- a/hgext/transplant.py Sat Jan 10 18:02:38 2009 -0600 +++ b/hgext/transplant.py Sun Jan 11 22:48:28 2009 -0600 @@ -16,7 +16,7 @@ from mercurial.i18n import _ import os, tempfile from mercurial import bundlerepo, changegroup, cmdutil, hg, merge -from mercurial import patch, revlog, util +from mercurial import patch, revlog, util, error class transplantentry: def __init__(self, lnode, rnode): @@ -380,7 +380,7 @@ def hasnode(repo, node): try: return repo.changelog.rev(node) != None - except revlog.RevlogError: + except error.RevlogError: return False def browserevs(ui, repo, nodes, opts):
--- a/mercurial/bundlerepo.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/bundlerepo.py Sun Jan 11 22:48:28 2009 -0600 @@ -13,7 +13,7 @@ from node import hex, nullid, short from i18n import _ import changegroup, util, os, struct, bz2, zlib, tempfile, shutil, mdiff -import repo, localrepo, changelog, manifest, filelog, revlog, context +import repo, localrepo, changelog, manifest, filelog, revlog, context, error class bundlerevlog(revlog.revlog): def __init__(self, opener, indexfile, bundlefile, @@ -48,8 +48,8 @@ continue for p in (p1, p2): if not p in self.nodemap: - raise revlog.LookupError(p1, self.indexfile, - _("unknown parent")) + raise error.LookupError(p1, self.indexfile, + _("unknown parent")) if linkmapper is None: link = n else: @@ -119,7 +119,7 @@ p1, p2 = self.parents(node) if node != revlog.hash(text, p1, p2): - raise revlog.RevlogError(_("integrity check failed on %s:%d") + raise error.RevlogError(_("integrity check failed on %s:%d") % (self.datafile, self.rev(node))) self._cache = (node, self.rev(node), text)
--- a/mercurial/changelog.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/changelog.py Sun Jan 11 22:48:28 2009 -0600 @@ -8,7 +8,7 @@ from node import bin, hex, nullid from revlog import revlog, RevlogError from i18n import _ -import util +import util, error def _string_escape(text): """ @@ -179,7 +179,8 @@ user = user.strip() if "\n" in user: - raise RevlogError(_("username %s contains a newline") % repr(user)) + raise error.RevlogError(_("username %s contains a newline") + % repr(user)) user, desc = util.fromlocal(user), util.fromlocal(desc) if date:
--- a/mercurial/commands.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/commands.py Sun Jan 11 22:48:28 2009 -0600 @@ -9,7 +9,7 @@ from repo import RepoError, NoCapability from i18n import _, gettext import os, re, sys -import hg, util, revlog, bundlerepo, extensions, copies, context +import hg, util, revlog, bundlerepo, extensions, copies, context, error import difflib, patch, time, help, mdiff, tempfile, url import archival, changegroup, cmdutil, hgweb.server, sshserver, hbisect import merge as merge_ @@ -1214,7 +1214,7 @@ copied = getfile(fn).renamed(ctx.filenode(fn)) if copied: copies.setdefault(rev, {})[fn] = copied[0] - except revlog.LookupError: + except error.LookupError: pass elif st == 'iter': for fn, m in util.sort(matches[rev].items()): @@ -1887,7 +1887,7 @@ try: return repo[rev][fn].renamed() - except revlog.LookupError: + except error.LookupError: pass return None @@ -2086,7 +2086,7 @@ continue try: filenodes.append(cp.filenode(file_)) - except revlog.LookupError: + except error.LookupError: pass if not filenodes: raise util.Abort(_("'%s' not found in manifest!") % file_) @@ -2857,7 +2857,7 @@ try: hn = hexfunc(n) r = "%5d:%s" % (repo.changelog.rev(n), hn) - except revlog.LookupError: + except error.LookupError: r = " ?:%s" % hn else: spaces = " " * (30 - util.locallen(t))
--- a/mercurial/context.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/context.py Sun Jan 11 22:48:28 2009 -0600 @@ -7,7 +7,7 @@ from node import nullid, nullrev, short, hex from i18n import _ -import ancestor, bdiff, revlog, util, os, errno +import ancestor, bdiff, error, util, os, errno class propertycache(object): def __init__(self, func): @@ -125,15 +125,15 @@ try: return self._manifest[path], self._manifest.flags(path) except KeyError: - raise revlog.LookupError(self._node, path, - _('not found in manifest')) + raise error.LookupError(self._node, path, + _('not found in manifest')) if '_manifestdelta' in self.__dict__ or path in self.files(): if path in self._manifestdelta: return self._manifestdelta[path], self._manifestdelta.flags(path) node, flag = self._repo.manifest.find(self._changeset[0], path) if not node: - raise revlog.LookupError(self._node, path, - _('not found in manifest')) + raise error.LookupError(self._node, path, + _('not found in manifest')) return node, flag @@ -143,7 +143,7 @@ def flags(self, path): try: return self._fileinfo(path)[1] - except revlog.LookupError: + except error.LookupError: return '' def filectx(self, path, fileid=None, filelog=None): @@ -235,7 +235,7 @@ try: n = self._filenode return True - except revlog.LookupError: + except error.LookupError: # file is missing return False @@ -316,7 +316,7 @@ try: if fnode == p.filenode(name): return None - except revlog.LookupError: + except error.LookupError: pass return renamed
--- a/mercurial/dispatch.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/dispatch.py Sun Jan 11 22:48:28 2009 -0600 @@ -8,7 +8,7 @@ from i18n import _ from repo import RepoError import os, sys, atexit, signal, pdb, socket, errno, shlex, time -import util, commands, hg, lock, fancyopts, revlog, extensions, hook +import util, commands, hg, lock, fancyopts, extensions, hook, error import cmdutil import ui as _ui @@ -76,7 +76,7 @@ except lock.LockUnavailable, inst: ui.warn(_("abort: could not lock %s: %s\n") % (inst.desc or inst.filename, inst.strerror)) - except revlog.RevlogError, inst: + except error.RevlogError, inst: ui.warn(_("abort: %s!\n") % inst) except util.SignalInterrupt: ui.warn(_("killed!\n"))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/error.py Sun Jan 11 22:48:28 2009 -0600 @@ -0,0 +1,26 @@ +""" +error.py - Mercurial exceptions + +This allows us to catch exceptions at higher levels without forcing imports + +Copyright 2005-2008 Matt Mackall <mpm@selenic.com> + +This software may be used and distributed according to the terms +of the GNU General Public License, incorporated herein by reference. +""" + +# Do not import anything here, please + +class RevlogError(Exception): + pass + +class LookupError(RevlogError, KeyError): + def __init__(self, name, index, message): + self.name = name + if isinstance(name, str) and len(name) == 20: + from node import short + name = short(name) + RevlogError.__init__(self, '%s@%s: %s' % (index, name, message)) + + def __str__(self): + return RevlogError.__str__(self)
--- a/mercurial/hgweb/hgweb_mod.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/hgweb/hgweb_mod.py Sun Jan 11 22:48:28 2009 -0600 @@ -9,8 +9,8 @@ import os, mimetypes from mercurial.node import hex, nullid from mercurial.repo import RepoError -from mercurial import ui, hg, util, hook -from mercurial import revlog, templater, templatefilters +from mercurial import ui, hg, util, hook, error +from mercurial import templater, templatefilters from common import get_mtime, style_map, ErrorResponse from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED @@ -185,13 +185,13 @@ return content - except revlog.LookupError, err: + except error.LookupError, err: req.respond(HTTP_NOT_FOUND, ctype) msg = str(err) if 'manifest' not in msg: msg = 'revision not found: %s' % err.name return tmpl('error', error=msg) - except (RepoError, revlog.RevlogError), inst: + except (RepoError, error.RevlogError), inst: req.respond(HTTP_SERVER_ERROR, ctype) return tmpl('error', error=str(inst)) except ErrorResponse, inst:
--- a/mercurial/hgweb/webcommands.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/hgweb/webcommands.py Sun Jan 11 22:48:28 2009 -0600 @@ -7,7 +7,7 @@ import os, mimetypes, re, cgi, copy import webutil -from mercurial import revlog, archival, templatefilters +from mercurial import error, archival, templatefilters from mercurial.node import short, hex, nullid from mercurial.util import binary, datestr from mercurial.repo import RepoError @@ -39,7 +39,7 @@ try: fctx = webutil.filectx(web.repo, req) - except revlog.LookupError, inst: + except error.LookupError, inst: try: content = manifest(web, req, tmpl) req.respond(HTTP_OK, web.ctype) @@ -93,7 +93,7 @@ return manifest(web, req, tmpl) try: return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) - except revlog.LookupError, inst: + except error.LookupError, inst: try: return manifest(web, req, tmpl) except ErrorResponse: @@ -521,7 +521,7 @@ fctx = webutil.filectx(web.repo, req) f = fctx.path() fl = fctx.filelog() - except revlog.LookupError: + except error.LookupError: f = webutil.cleanpath(web.repo, req.form['file'][0]) fl = web.repo.file(f) numrevs = len(fl)
--- a/mercurial/localrepo.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/localrepo.py Sun Jan 11 22:48:28 2009 -0600 @@ -10,7 +10,7 @@ import repo, changegroup import changelog, dirstate, filelog, manifest, context, weakref import lock, transaction, stat, errno, ui, store -import os, revlog, time, util, extensions, hook, inspect +import os, time, util, extensions, hook, inspect, error import match as match_ import merge as merge_ @@ -177,7 +177,7 @@ else: try: prevtags = self.filectx('.hgtags', parent).data() - except revlog.LookupError: + except error.LookupError: pass fp = self.wfile('.hgtags', 'wb') if prevtags: @@ -332,7 +332,7 @@ rev = c.rev() try: fnode = c.filenode('.hgtags') - except revlog.LookupError: + except error.LookupError: continue ret.append((rev, node, fnode)) if fnode in last:
--- a/mercurial/manifest.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/manifest.py Sun Jan 11 22:48:28 2009 -0600 @@ -6,9 +6,9 @@ # of the GNU General Public License, incorporated herein by reference. from node import bin, hex, nullid -from revlog import revlog, RevlogError +from revlog import revlog from i18n import _ -import array, struct, mdiff, parsers, util +import array, struct, mdiff, parsers, util, error class manifestdict(dict): def __init__(self, mapping=None, flags=None): @@ -125,7 +125,8 @@ def checkforbidden(l): for f in l: if '\n' in f or '\r' in f: - raise RevlogError(_("'\\n' and '\\r' disallowed in filenames")) + raise error.RevlogError( + _("'\\n' and '\\r' disallowed in filenames")) # if we're using the listcache, make sure it is valid and # parented by the same node we're diffing against
--- a/mercurial/revlog.py Sat Jan 10 18:02:38 2009 -0600 +++ b/mercurial/revlog.py Sun Jan 11 22:48:28 2009 -0600 @@ -13,7 +13,7 @@ from node import bin, hex, nullid, nullrev, short from i18n import _ import changegroup, errno, ancestor, mdiff, parsers -import struct, util, zlib +import struct, util, zlib, error _pack = struct.pack _unpack = struct.unpack @@ -29,18 +29,8 @@ REVLOG_DEFAULT_FORMAT = REVLOGNG REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS -class RevlogError(Exception): - pass - -class LookupError(RevlogError, KeyError): - def __init__(self, name, index, message): - self.name = name - if isinstance(name, str) and len(name) == 20: - name = short(name) - RevlogError.__init__(self, _('%s@%s: %s') % (index, name, message)) - - def __str__(self): - return RevlogError.__str__(self) +RevlogError = error.RevlogError +LookupError = error.LookupError def getoffset(q): return int(q >> 16)