Show More
@@ -0,0 +1,26 b'' | |||
|
1 | """ | |
|
2 | error.py - Mercurial exceptions | |
|
3 | ||
|
4 | This allows us to catch exceptions at higher levels without forcing imports | |
|
5 | ||
|
6 | Copyright 2005-2008 Matt Mackall <mpm@selenic.com> | |
|
7 | ||
|
8 | This software may be used and distributed according to the terms | |
|
9 | of the GNU General Public License, incorporated herein by reference. | |
|
10 | """ | |
|
11 | ||
|
12 | # Do not import anything here, please | |
|
13 | ||
|
14 | class RevlogError(Exception): | |
|
15 | pass | |
|
16 | ||
|
17 | class LookupError(RevlogError, KeyError): | |
|
18 | def __init__(self, name, index, message): | |
|
19 | self.name = name | |
|
20 | if isinstance(name, str) and len(name) == 20: | |
|
21 | from node import short | |
|
22 | name = short(name) | |
|
23 | RevlogError.__init__(self, '%s@%s: %s' % (index, name, message)) | |
|
24 | ||
|
25 | def __str__(self): | |
|
26 | return RevlogError.__str__(self) |
@@ -17,7 +17,7 b' import os, time' | |||
|
17 | 17 | from mercurial.i18n import _ |
|
18 | 18 | from mercurial.repo import RepoError |
|
19 | 19 | from mercurial.node import bin, hex, nullid |
|
20 |
from mercurial import hg, |
|
|
20 | from mercurial import hg, util, context, error | |
|
21 | 21 | |
|
22 | 22 | from common import NoRepo, commit, converter_source, converter_sink |
|
23 | 23 | |
@@ -244,7 +244,7 b' class mercurial_source(converter_source)' | |||
|
244 | 244 | def getfile(self, name, rev): |
|
245 | 245 | try: |
|
246 | 246 | return self.changectx(rev)[name].data() |
|
247 |
except |
|
|
247 | except error.LookupError, err: | |
|
248 | 248 | raise IOError(err) |
|
249 | 249 | |
|
250 | 250 | def getmode(self, name, rev): |
@@ -283,7 +283,7 b' class mercurial_source(converter_source)' | |||
|
283 | 283 | copies[name] = copysource |
|
284 | 284 | except TypeError: |
|
285 | 285 | pass |
|
286 |
except |
|
|
286 | except error.LookupError, e: | |
|
287 | 287 | if not self.ignoreerrors: |
|
288 | 288 | raise |
|
289 | 289 | self.ignored[name] = 1 |
@@ -8,7 +8,7 b' imerge - interactive merge' | |||
|
8 | 8 | from mercurial.i18n import _ |
|
9 | 9 | from mercurial.node import hex, short |
|
10 | 10 | from mercurial import commands, cmdutil, dispatch, fancyopts |
|
11 |
from mercurial import hg, filemerge, util, |
|
|
11 | from mercurial import hg, filemerge, util, error | |
|
12 | 12 | import os, tarfile |
|
13 | 13 | |
|
14 | 14 | class InvalidStateFileException(Exception): pass |
@@ -78,7 +78,7 b' class Imerge(object):' | |||
|
78 | 78 | |
|
79 | 79 | try: |
|
80 | 80 | parents = [self.repo.changectx(n) for n in status[:2]] |
|
81 |
except |
|
|
81 | except error.LookupError, e: | |
|
82 | 82 | raise util.Abort(_('merge parent %s not in repository') % |
|
83 | 83 | short(e.name)) |
|
84 | 84 |
@@ -16,7 +16,7 b' from a changeset hash to its hash in the' | |||
|
16 | 16 | from mercurial.i18n import _ |
|
17 | 17 | import os, tempfile |
|
18 | 18 | from mercurial import bundlerepo, changegroup, cmdutil, hg, merge |
|
19 | from mercurial import patch, revlog, util | |
|
19 | from mercurial import patch, revlog, util, error | |
|
20 | 20 | |
|
21 | 21 | class transplantentry: |
|
22 | 22 | def __init__(self, lnode, rnode): |
@@ -380,7 +380,7 b' class transplanter:' | |||
|
380 | 380 | def hasnode(repo, node): |
|
381 | 381 | try: |
|
382 | 382 | return repo.changelog.rev(node) != None |
|
383 |
except |
|
|
383 | except error.RevlogError: | |
|
384 | 384 | return False |
|
385 | 385 | |
|
386 | 386 | def browserevs(ui, repo, nodes, opts): |
@@ -13,7 +13,7 b' of the GNU General Public License, incor' | |||
|
13 | 13 | from node import hex, nullid, short |
|
14 | 14 | from i18n import _ |
|
15 | 15 | import changegroup, util, os, struct, bz2, zlib, tempfile, shutil, mdiff |
|
16 | import repo, localrepo, changelog, manifest, filelog, revlog, context | |
|
16 | import repo, localrepo, changelog, manifest, filelog, revlog, context, error | |
|
17 | 17 | |
|
18 | 18 | class bundlerevlog(revlog.revlog): |
|
19 | 19 | def __init__(self, opener, indexfile, bundlefile, |
@@ -48,8 +48,8 b' class bundlerevlog(revlog.revlog):' | |||
|
48 | 48 | continue |
|
49 | 49 | for p in (p1, p2): |
|
50 | 50 | if not p in self.nodemap: |
|
51 |
raise |
|
|
52 |
|
|
|
51 | raise error.LookupError(p1, self.indexfile, | |
|
52 | _("unknown parent")) | |
|
53 | 53 | if linkmapper is None: |
|
54 | 54 | link = n |
|
55 | 55 | else: |
@@ -119,7 +119,7 b' class bundlerevlog(revlog.revlog):' | |||
|
119 | 119 | |
|
120 | 120 | p1, p2 = self.parents(node) |
|
121 | 121 | if node != revlog.hash(text, p1, p2): |
|
122 |
raise |
|
|
122 | raise error.RevlogError(_("integrity check failed on %s:%d") | |
|
123 | 123 | % (self.datafile, self.rev(node))) |
|
124 | 124 | |
|
125 | 125 | self._cache = (node, self.rev(node), text) |
@@ -8,7 +8,7 b'' | |||
|
8 | 8 | from node import bin, hex, nullid |
|
9 | 9 | from revlog import revlog, RevlogError |
|
10 | 10 | from i18n import _ |
|
11 | import util | |
|
11 | import util, error | |
|
12 | 12 | |
|
13 | 13 | def _string_escape(text): |
|
14 | 14 | """ |
@@ -179,7 +179,8 b' class changelog(revlog):' | |||
|
179 | 179 | |
|
180 | 180 | user = user.strip() |
|
181 | 181 | if "\n" in user: |
|
182 |
raise RevlogError(_("username %s contains a newline") |
|
|
182 | raise error.RevlogError(_("username %s contains a newline") | |
|
183 | % repr(user)) | |
|
183 | 184 | user, desc = util.fromlocal(user), util.fromlocal(desc) |
|
184 | 185 | |
|
185 | 186 | if date: |
@@ -9,7 +9,7 b' from node import hex, nullid, nullrev, s' | |||
|
9 | 9 | from repo import RepoError, NoCapability |
|
10 | 10 | from i18n import _, gettext |
|
11 | 11 | import os, re, sys |
|
12 | import hg, util, revlog, bundlerepo, extensions, copies, context | |
|
12 | import hg, util, revlog, bundlerepo, extensions, copies, context, error | |
|
13 | 13 | import difflib, patch, time, help, mdiff, tempfile, url |
|
14 | 14 | import archival, changegroup, cmdutil, hgweb.server, sshserver, hbisect |
|
15 | 15 | import merge as merge_ |
@@ -1214,7 +1214,7 b' def grep(ui, repo, pattern, *pats, **opt' | |||
|
1214 | 1214 | copied = getfile(fn).renamed(ctx.filenode(fn)) |
|
1215 | 1215 | if copied: |
|
1216 | 1216 | copies.setdefault(rev, {})[fn] = copied[0] |
|
1217 |
except |
|
|
1217 | except error.LookupError: | |
|
1218 | 1218 | pass |
|
1219 | 1219 | elif st == 'iter': |
|
1220 | 1220 | for fn, m in util.sort(matches[rev].items()): |
@@ -1887,7 +1887,7 b' def log(ui, repo, *pats, **opts):' | |||
|
1887 | 1887 | |
|
1888 | 1888 | try: |
|
1889 | 1889 | return repo[rev][fn].renamed() |
|
1890 |
except |
|
|
1890 | except error.LookupError: | |
|
1891 | 1891 | pass |
|
1892 | 1892 | return None |
|
1893 | 1893 | |
@@ -2086,7 +2086,7 b' def parents(ui, repo, file_=None, **opts' | |||
|
2086 | 2086 | continue |
|
2087 | 2087 | try: |
|
2088 | 2088 | filenodes.append(cp.filenode(file_)) |
|
2089 |
except |
|
|
2089 | except error.LookupError: | |
|
2090 | 2090 | pass |
|
2091 | 2091 | if not filenodes: |
|
2092 | 2092 | raise util.Abort(_("'%s' not found in manifest!") % file_) |
@@ -2857,7 +2857,7 b' def tags(ui, repo):' | |||
|
2857 | 2857 | try: |
|
2858 | 2858 | hn = hexfunc(n) |
|
2859 | 2859 | r = "%5d:%s" % (repo.changelog.rev(n), hn) |
|
2860 |
except |
|
|
2860 | except error.LookupError: | |
|
2861 | 2861 | r = " ?:%s" % hn |
|
2862 | 2862 | else: |
|
2863 | 2863 | spaces = " " * (30 - util.locallen(t)) |
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | |
|
8 | 8 | from node import nullid, nullrev, short, hex |
|
9 | 9 | from i18n import _ |
|
10 |
import ancestor, bdiff, |
|
|
10 | import ancestor, bdiff, error, util, os, errno | |
|
11 | 11 | |
|
12 | 12 | class propertycache(object): |
|
13 | 13 | def __init__(self, func): |
@@ -125,15 +125,15 b' class changectx(object):' | |||
|
125 | 125 | try: |
|
126 | 126 | return self._manifest[path], self._manifest.flags(path) |
|
127 | 127 | except KeyError: |
|
128 |
raise |
|
|
129 |
|
|
|
128 | raise error.LookupError(self._node, path, | |
|
129 | _('not found in manifest')) | |
|
130 | 130 | if '_manifestdelta' in self.__dict__ or path in self.files(): |
|
131 | 131 | if path in self._manifestdelta: |
|
132 | 132 | return self._manifestdelta[path], self._manifestdelta.flags(path) |
|
133 | 133 | node, flag = self._repo.manifest.find(self._changeset[0], path) |
|
134 | 134 | if not node: |
|
135 |
raise |
|
|
136 |
|
|
|
135 | raise error.LookupError(self._node, path, | |
|
136 | _('not found in manifest')) | |
|
137 | 137 | |
|
138 | 138 | return node, flag |
|
139 | 139 | |
@@ -143,7 +143,7 b' class changectx(object):' | |||
|
143 | 143 | def flags(self, path): |
|
144 | 144 | try: |
|
145 | 145 | return self._fileinfo(path)[1] |
|
146 |
except |
|
|
146 | except error.LookupError: | |
|
147 | 147 | return '' |
|
148 | 148 | |
|
149 | 149 | def filectx(self, path, fileid=None, filelog=None): |
@@ -235,7 +235,7 b' class filectx(object):' | |||
|
235 | 235 | try: |
|
236 | 236 | n = self._filenode |
|
237 | 237 | return True |
|
238 |
except |
|
|
238 | except error.LookupError: | |
|
239 | 239 | # file is missing |
|
240 | 240 | return False |
|
241 | 241 | |
@@ -316,7 +316,7 b' class filectx(object):' | |||
|
316 | 316 | try: |
|
317 | 317 | if fnode == p.filenode(name): |
|
318 | 318 | return None |
|
319 |
except |
|
|
319 | except error.LookupError: | |
|
320 | 320 | pass |
|
321 | 321 | return renamed |
|
322 | 322 |
@@ -8,7 +8,7 b'' | |||
|
8 | 8 | from i18n import _ |
|
9 | 9 | from repo import RepoError |
|
10 | 10 | import os, sys, atexit, signal, pdb, socket, errno, shlex, time |
|
11 |
import util, commands, hg, lock, fancyopts, |
|
|
11 | import util, commands, hg, lock, fancyopts, extensions, hook, error | |
|
12 | 12 | import cmdutil |
|
13 | 13 | import ui as _ui |
|
14 | 14 | |
@@ -76,7 +76,7 b' def _runcatch(ui, args):' | |||
|
76 | 76 | except lock.LockUnavailable, inst: |
|
77 | 77 | ui.warn(_("abort: could not lock %s: %s\n") % |
|
78 | 78 | (inst.desc or inst.filename, inst.strerror)) |
|
79 |
except |
|
|
79 | except error.RevlogError, inst: | |
|
80 | 80 | ui.warn(_("abort: %s!\n") % inst) |
|
81 | 81 | except util.SignalInterrupt: |
|
82 | 82 | ui.warn(_("killed!\n")) |
@@ -9,8 +9,8 b'' | |||
|
9 | 9 | import os, mimetypes |
|
10 | 10 | from mercurial.node import hex, nullid |
|
11 | 11 | from mercurial.repo import RepoError |
|
12 | from mercurial import ui, hg, util, hook | |
|
13 |
from mercurial import |
|
|
12 | from mercurial import ui, hg, util, hook, error | |
|
13 | from mercurial import templater, templatefilters | |
|
14 | 14 | from common import get_mtime, style_map, ErrorResponse |
|
15 | 15 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
16 | 16 | from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED |
@@ -185,13 +185,13 b' class hgweb(object):' | |||
|
185 | 185 | |
|
186 | 186 | return content |
|
187 | 187 | |
|
188 |
except |
|
|
188 | except error.LookupError, err: | |
|
189 | 189 | req.respond(HTTP_NOT_FOUND, ctype) |
|
190 | 190 | msg = str(err) |
|
191 | 191 | if 'manifest' not in msg: |
|
192 | 192 | msg = 'revision not found: %s' % err.name |
|
193 | 193 | return tmpl('error', error=msg) |
|
194 |
except (RepoError, |
|
|
194 | except (RepoError, error.RevlogError), inst: | |
|
195 | 195 | req.respond(HTTP_SERVER_ERROR, ctype) |
|
196 | 196 | return tmpl('error', error=str(inst)) |
|
197 | 197 | except ErrorResponse, inst: |
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | |
|
8 | 8 | import os, mimetypes, re, cgi, copy |
|
9 | 9 | import webutil |
|
10 |
from mercurial import |
|
|
10 | from mercurial import error, archival, templatefilters | |
|
11 | 11 | from mercurial.node import short, hex, nullid |
|
12 | 12 | from mercurial.util import binary, datestr |
|
13 | 13 | from mercurial.repo import RepoError |
@@ -39,7 +39,7 b' def rawfile(web, req, tmpl):' | |||
|
39 | 39 | |
|
40 | 40 | try: |
|
41 | 41 | fctx = webutil.filectx(web.repo, req) |
|
42 |
except |
|
|
42 | except error.LookupError, inst: | |
|
43 | 43 | try: |
|
44 | 44 | content = manifest(web, req, tmpl) |
|
45 | 45 | req.respond(HTTP_OK, web.ctype) |
@@ -93,7 +93,7 b' def file(web, req, tmpl):' | |||
|
93 | 93 | return manifest(web, req, tmpl) |
|
94 | 94 | try: |
|
95 | 95 | return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) |
|
96 |
except |
|
|
96 | except error.LookupError, inst: | |
|
97 | 97 | try: |
|
98 | 98 | return manifest(web, req, tmpl) |
|
99 | 99 | except ErrorResponse: |
@@ -521,7 +521,7 b' def filelog(web, req, tmpl):' | |||
|
521 | 521 | fctx = webutil.filectx(web.repo, req) |
|
522 | 522 | f = fctx.path() |
|
523 | 523 | fl = fctx.filelog() |
|
524 |
except |
|
|
524 | except error.LookupError: | |
|
525 | 525 | f = webutil.cleanpath(web.repo, req.form['file'][0]) |
|
526 | 526 | fl = web.repo.file(f) |
|
527 | 527 | numrevs = len(fl) |
@@ -10,7 +10,7 b' from i18n import _' | |||
|
10 | 10 | import repo, changegroup |
|
11 | 11 | import changelog, dirstate, filelog, manifest, context, weakref |
|
12 | 12 | import lock, transaction, stat, errno, ui, store |
|
13 |
import os |
|
|
13 | import os, time, util, extensions, hook, inspect, error | |
|
14 | 14 | import match as match_ |
|
15 | 15 | import merge as merge_ |
|
16 | 16 | |
@@ -177,7 +177,7 b' class localrepository(repo.repository):' | |||
|
177 | 177 | else: |
|
178 | 178 | try: |
|
179 | 179 | prevtags = self.filectx('.hgtags', parent).data() |
|
180 |
except |
|
|
180 | except error.LookupError: | |
|
181 | 181 | pass |
|
182 | 182 | fp = self.wfile('.hgtags', 'wb') |
|
183 | 183 | if prevtags: |
@@ -332,7 +332,7 b' class localrepository(repo.repository):' | |||
|
332 | 332 | rev = c.rev() |
|
333 | 333 | try: |
|
334 | 334 | fnode = c.filenode('.hgtags') |
|
335 |
except |
|
|
335 | except error.LookupError: | |
|
336 | 336 | continue |
|
337 | 337 | ret.append((rev, node, fnode)) |
|
338 | 338 | if fnode in last: |
@@ -6,9 +6,9 b'' | |||
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from node import bin, hex, nullid |
|
9 |
from revlog import revlog |
|
|
9 | from revlog import revlog | |
|
10 | 10 | from i18n import _ |
|
11 | import array, struct, mdiff, parsers, util | |
|
11 | import array, struct, mdiff, parsers, util, error | |
|
12 | 12 | |
|
13 | 13 | class manifestdict(dict): |
|
14 | 14 | def __init__(self, mapping=None, flags=None): |
@@ -125,7 +125,8 b' class manifest(revlog):' | |||
|
125 | 125 | def checkforbidden(l): |
|
126 | 126 | for f in l: |
|
127 | 127 | if '\n' in f or '\r' in f: |
|
128 | raise RevlogError(_("'\\n' and '\\r' disallowed in filenames")) | |
|
128 | raise error.RevlogError( | |
|
129 | _("'\\n' and '\\r' disallowed in filenames")) | |
|
129 | 130 | |
|
130 | 131 | # if we're using the listcache, make sure it is valid and |
|
131 | 132 | # parented by the same node we're diffing against |
@@ -13,7 +13,7 b' of the GNU General Public License, incor' | |||
|
13 | 13 | from node import bin, hex, nullid, nullrev, short |
|
14 | 14 | from i18n import _ |
|
15 | 15 | import changegroup, errno, ancestor, mdiff, parsers |
|
16 | import struct, util, zlib | |
|
16 | import struct, util, zlib, error | |
|
17 | 17 | |
|
18 | 18 | _pack = struct.pack |
|
19 | 19 | _unpack = struct.unpack |
@@ -29,18 +29,8 b' REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDAT' | |||
|
29 | 29 | REVLOG_DEFAULT_FORMAT = REVLOGNG |
|
30 | 30 | REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS |
|
31 | 31 | |
|
32 | class RevlogError(Exception): | |
|
33 | pass | |
|
34 | ||
|
35 | class LookupError(RevlogError, KeyError): | |
|
36 | def __init__(self, name, index, message): | |
|
37 | self.name = name | |
|
38 | if isinstance(name, str) and len(name) == 20: | |
|
39 | name = short(name) | |
|
40 | RevlogError.__init__(self, _('%s@%s: %s') % (index, name, message)) | |
|
41 | ||
|
42 | def __str__(self): | |
|
43 | return RevlogError.__str__(self) | |
|
32 | RevlogError = error.RevlogError | |
|
33 | LookupError = error.LookupError | |
|
44 | 34 | |
|
45 | 35 | def getoffset(q): |
|
46 | 36 | return int(q >> 16) |
General Comments 0
You need to be logged in to leave comments.
Login now