##// END OF EJS Templates
error: move repo errors...
Matt Mackall -
r7637:1d54e2f6 default
parent child Browse files
Show More
@@ -30,7 +30,6 b' from mercurial import extensions'
30 30 from mercurial.i18n import _
31 31 from mercurial import cmdutil, util, commands, changelog
32 32 from mercurial.node import nullid, nullrev
33 from mercurial.repo import RepoError
34 33 import mercurial, mercurial.localrepo, mercurial.repair, os
35 34
36 35 def parse(repo):
@@ -15,7 +15,6 b''
15 15
16 16 import os, time
17 17 from mercurial.i18n import _
18 from mercurial.repo import RepoError
19 18 from mercurial.node import bin, hex, nullid
20 19 from mercurial import hg, util, context, error
21 20
@@ -33,7 +32,7 b' class mercurial_sink(converter_sink):'
33 32 self.repo = hg.repository(self.ui, path)
34 33 if not self.repo.local():
35 34 raise NoRepo(_('%s is not a local Mercurial repo') % path)
36 except RepoError, err:
35 except error.RepoError, err:
37 36 ui.print_exc()
38 37 raise NoRepo(err.args[0])
39 38 else:
@@ -43,7 +42,7 b' class mercurial_sink(converter_sink):'
43 42 if not self.repo.local():
44 43 raise NoRepo(_('%s is not a local Mercurial repo') % path)
45 44 self.created.append(path)
46 except RepoError, err:
45 except error.RepoError, err:
47 46 ui.print_exc()
48 47 raise NoRepo("could not create hg repo %s as sink" % path)
49 48 self.lock = None
@@ -159,7 +158,7 b' class mercurial_sink(converter_sink):'
159 158 try:
160 159 parentctx = self.repo[self.tagsbranch]
161 160 tagparent = parentctx.node()
162 except RepoError, inst:
161 except error.RepoError, inst:
163 162 parentctx = None
164 163 tagparent = nullid
165 164
@@ -200,8 +199,8 b' class mercurial_source(converter_source)'
200 199 # try to provoke an exception if this isn't really a hg
201 200 # repo, but some other bogus compatible-looking url
202 201 if not self.repo.local():
203 raise RepoError()
204 except RepoError:
202 raise error.RepoError()
203 except error.RepoError:
205 204 ui.print_exc()
206 205 raise NoRepo("%s is not a local Mercurial repo" % path)
207 206 self.lastrev = None
@@ -213,7 +212,7 b' class mercurial_source(converter_source)'
213 212 if startnode is not None:
214 213 try:
215 214 startnode = self.repo.lookup(startnode)
216 except repo.RepoError:
215 except error.RepoError:
217 216 raise util.Abort(_('%s is not a valid start revision')
218 217 % startnode)
219 218 startrev = self.repo.changelog.rev(startnode)
@@ -31,9 +31,8 b' refresh contents of top applied patch '
31 31
32 32 from mercurial.i18n import _
33 33 from mercurial.node import bin, hex, short
34 from mercurial.repo import RepoError
35 34 from mercurial import commands, cmdutil, hg, patch, revlog, util
36 from mercurial import repair, extensions, url
35 from mercurial import repair, extensions, url, error
37 36 import os, sys, re, errno
38 37
39 38 commands.norepo += " qclone"
@@ -1741,7 +1740,7 b' def clone(ui, source, dest=None, **opts)'
1741 1740 patchespath = opts['patches'] or patchdir(sr)
1742 1741 try:
1743 1742 pr = hg.repository(ui, patchespath)
1744 except RepoError:
1743 except error.RepoError:
1745 1744 raise util.Abort(_('versioned patch repository not found'
1746 1745 ' (see qinit -c)'))
1747 1746 qbase, destrev = None, None
@@ -1757,7 +1756,7 b' def clone(ui, source, dest=None, **opts)'
1757 1756 elif sr.capable('lookup'):
1758 1757 try:
1759 1758 qbase = sr.lookup('qbase')
1760 except RepoError:
1759 except error.RepoError:
1761 1760 pass
1762 1761 ui.note(_('cloning main repo\n'))
1763 1762 sr, dr = hg.clone(ui, sr.url(), dest,
@@ -24,6 +24,7 b' For example, if you can refer to a revis'
24 24 foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
25 25 '''
26 26 import mercurial.repo
27 from mercurial import error
27 28
28 29 def reposetup(ui, repo):
29 30 if not repo.local():
@@ -34,7 +35,7 b' def reposetup(ui, repo):'
34 35 try:
35 36 _super = super(parentrevspecrepo, self)
36 37 return _super.lookup(key)
37 except mercurial.repo.RepoError:
38 except error.RepoError:
38 39 pass
39 40
40 41 circ = key.find('^')
@@ -50,7 +51,7 b' def reposetup(ui, repo):'
50 51 base = key[:end]
51 52 try:
52 53 node = _super.lookup(base)
53 except mercurial.repo.RepoError:
54 except error.RepoError:
54 55 # eek - reraise the first error
55 56 return _super.lookup(key)
56 57
@@ -156,7 +156,7 b' class bundlerepository(localrepo.localre'
156 156 self._tempparent = None
157 157 try:
158 158 localrepo.localrepository.__init__(self, ui, path)
159 except repo.RepoError:
159 except error.RepoError:
160 160 self._tempparent = tempfile.mkdtemp()
161 161 tmprepo = localrepo.instance(ui,self._tempparent,1)
162 162 localrepo.localrepository.__init__(self, ui, self._tempparent)
@@ -6,7 +6,6 b''
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from node import hex, nullid, nullrev, short
9 from repo import RepoError, NoCapability
10 9 from i18n import _, gettext
11 10 import os, re, sys
12 11 import hg, util, revlog, bundlerepo, extensions, copies, context, error
@@ -1671,7 +1670,7 b' def import_(ui, repo, patch1, *patches, '
1671 1670 p2 = repo.lookup(p2)
1672 1671 if p1 == wp[0].node():
1673 1672 repo.dirstate.setparents(p1, p2)
1674 except RepoError:
1673 except error.RepoError:
1675 1674 pass
1676 1675 if opts.get('exact') or opts.get('import_branch'):
1677 1676 repo.dirstate.setbranch(branch or 'default')
@@ -2179,10 +2178,10 b' def pull(ui, repo, source="default", **o'
2179 2178 if revs:
2180 2179 try:
2181 2180 revs = [other.lookup(rev) for rev in revs]
2182 except NoCapability:
2183 error = _("Other repository doesn't support revision lookup, "
2184 "so a rev cannot be specified.")
2185 raise util.Abort(error)
2181 except error.CapabilityError:
2182 err = _("Other repository doesn't support revision lookup, "
2183 "so a rev cannot be specified.")
2184 raise util.Abort(err)
2186 2185
2187 2186 modheads = repo.pull(other, heads=revs, force=opts.get('force'))
2188 2187 return postincoming(ui, repo, modheads, opts.get('update'), checkout)
@@ -2649,7 +2648,7 b' def serve(ui, repo, **opts):'
2649 2648
2650 2649 if opts["stdio"]:
2651 2650 if repo is None:
2652 raise RepoError(_("There is no Mercurial repository here"
2651 raise error.RepoError(_("There is no Mercurial repository here"
2653 2652 " (.hg not found)"))
2654 2653 s = sshserver.sshserver(ui, repo)
2655 2654 s.serve_forever()
@@ -2664,8 +2663,8 b' def serve(ui, repo, **opts):'
2664 2663 repo.ui.setconfig("web", o, str(opts[o]))
2665 2664
2666 2665 if repo is None and not ui.config("web", "webdir_conf"):
2667 raise RepoError(_("There is no Mercurial repository here"
2668 " (.hg not found)"))
2666 raise error.RepoError(_("There is no Mercurial repository here"
2667 " (.hg not found)"))
2669 2668
2670 2669 class service:
2671 2670 def init(self):
@@ -6,7 +6,6 b''
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from i18n import _
9 from repo import RepoError
10 9 import os, sys, atexit, signal, pdb, socket, errno, shlex, time
11 10 import util, commands, hg, lock, fancyopts, extensions, hook, error
12 11 import cmdutil
@@ -62,7 +61,7 b' def _runcatch(ui, args):'
62 61 except cmdutil.UnknownCommand, inst:
63 62 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0])
64 63 commands.help_(ui, 'shortlist')
65 except RepoError, inst:
64 except error.RepoError, inst:
66 65 ui.warn(_("abort: %s!\n") % inst)
67 66 except lock.LockHeld, inst:
68 67 if inst.errno == errno.ETIMEDOUT:
@@ -342,7 +341,7 b' def _dispatch(ui, args):'
342 341 if not repo.local():
343 342 raise util.Abort(_("repository '%s' is not local") % path)
344 343 ui.setconfig("bundle", "mainreporoot", repo.root)
345 except RepoError:
344 except error.RepoError:
346 345 if cmd not in commands.optionalrepo.split():
347 346 if args and not path: # try to infer -R from command args
348 347 repos = map(_findrepo, args)
@@ -350,8 +349,8 b' def _dispatch(ui, args):'
350 349 if guess and repos.count(guess) == len(repos):
351 350 return _dispatch(ui, ['--repository', guess] + fullargs)
352 351 if not path:
353 raise RepoError(_("There is no Mercurial repository here"
354 " (.hg not found)"))
352 raise error.RepoError(_("There is no Mercurial repository"
353 " here (.hg not found)"))
355 354 raise
356 355 args.insert(0, repo)
357 356
@@ -27,3 +27,9 b' class LookupError(RevlogError, KeyError)'
27 27
28 28 class ParseError(Exception):
29 29 """Exception raised on errors in parsing the command line."""
30
31 class RepoError(Exception):
32 pass
33
34 class CapabilityError(RepoError):
35 pass
@@ -8,7 +8,6 b''
8 8
9 9 import os, mimetypes
10 10 from mercurial.node import hex, nullid
11 from mercurial.repo import RepoError
12 11 from mercurial import ui, hg, util, hook, error
13 12 from mercurial import templater, templatefilters
14 13 from common import get_mtime, style_map, ErrorResponse
@@ -191,7 +190,7 b' class hgweb(object):'
191 190 if 'manifest' not in msg:
192 191 msg = 'revision not found: %s' % err.name
193 192 return tmpl('error', error=msg)
194 except (RepoError, error.RevlogError), inst:
193 except (error.RepoError, error.RevlogError), inst:
195 194 req.respond(HTTP_SERVER_ERROR, ctype)
196 195 return tmpl('error', error=str(inst))
197 196 except ErrorResponse, inst:
@@ -8,8 +8,7 b''
8 8
9 9 import os
10 10 from mercurial.i18n import _
11 from mercurial.repo import RepoError
12 from mercurial import ui, hg, util, templater, templatefilters
11 from mercurial import ui, hg, util, templater, templatefilters, error
13 12 from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen,\
14 13 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
15 14 from hgweb_mod import hgweb
@@ -150,7 +149,7 b' class hgwebdir(object):'
150 149 except IOError, inst:
151 150 msg = inst.strerror
152 151 raise ErrorResponse(HTTP_SERVER_ERROR, msg)
153 except RepoError, inst:
152 except error.RepoError, inst:
154 153 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
155 154
156 155 # browse subdirectories
@@ -7,8 +7,7 b''
7 7 # of the GNU General Public License, incorporated herein by reference.
8 8
9 9 import os, sys, errno, urllib, BaseHTTPServer, socket, SocketServer, traceback
10 from mercurial import hg, util
11 from mercurial.repo import RepoError
10 from mercurial import hg, util, error
12 11 from hgweb_mod import hgweb
13 12 from hgwebdir_mod import hgwebdir
14 13 from mercurial.i18n import _
@@ -249,8 +248,8 b' def create_server(ui, repo):'
249 248 elif repo is not None:
250 249 hgwebobj = hgweb(hg.repository(repo.ui, repo.root))
251 250 else:
252 raise RepoError(_("There is no Mercurial repository here"
253 " (.hg not found)"))
251 raise error.RepoError(_("There is no Mercurial repository"
252 " here (.hg not found)"))
254 253 return hgwebobj
255 254 self.application = make_handler()
256 255
@@ -10,7 +10,6 b' import webutil'
10 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 from mercurial.repo import RepoError
14 13 from common import paritygen, staticfile, get_contact, ErrorResponse
15 14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
16 15 from mercurial import graphmod, util
@@ -169,7 +168,7 b' def changelog(web, req, tmpl, shortlog ='
169 168 hi = len(web.repo) - 1
170 169 try:
171 170 ctx = web.repo[hi]
172 except RepoError:
171 except error.RepoError:
173 172 return _search(web, tmpl, hi) # XXX redirect to 404 page?
174 173
175 174 def changelist(limit=0, **map):
@@ -7,10 +7,8 b''
7 7 # of the GNU General Public License, incorporated herein by reference.
8 8
9 9 import os, copy
10 from mercurial import match, patch
10 from mercurial import match, patch, util, error
11 11 from mercurial.node import hex, nullid
12 from mercurial.repo import RepoError
13 from mercurial import util
14 12
15 13 def up(p):
16 14 if p[0] != "/":
@@ -55,7 +53,7 b' def revnavgen(pos, pagelen, limit, nodef'
55 53 yield {"label": label, "node": node}
56 54
57 55 yield {"label": "tip", "node": "tip"}
58 except RepoError:
56 except error.RepoError:
59 57 pass
60 58
61 59 return nav
@@ -124,7 +122,7 b' def changectx(repo, req):'
124 122
125 123 try:
126 124 ctx = repo[changeid]
127 except RepoError:
125 except error.RepoError:
128 126 man = repo.manifest
129 127 ctx = repo[man.linkrev(man.rev(man.lookup(changeid)))]
130 128
@@ -138,7 +136,7 b' def filectx(repo, req):'
138 136 changeid = req.form['filenode'][0]
139 137 try:
140 138 fctx = repo[changeid][path]
141 except RepoError:
139 except error.RepoError:
142 140 fctx = repo.filectx(path, fileid=changeid)
143 141
144 142 return fctx
@@ -9,8 +9,7 b''
9 9 from node import bin, hex, nullid
10 10 from i18n import _
11 11 import repo, os, urllib, urllib2, urlparse, zlib, util, httplib
12 import errno, socket, changegroup, statichttprepo
13 import url
12 import errno, socket, changegroup, statichttprepo, error, url
14 13
15 14 def zgenerator(f):
16 15 zd = zlib.decompressobj()
@@ -48,7 +47,7 b' class httprepository(repo.repository):'
48 47 if self.caps is None:
49 48 try:
50 49 self.caps = util.set(self.do_read('capabilities').split())
51 except repo.RepoError:
50 except error.RepoError:
52 51 self.caps = util.set()
53 52 self.ui.debug(_('capabilities: %s\n') %
54 53 (' '.join(self.caps or ['none'])))
@@ -99,19 +98,19 b' class httprepository(repo.repository):'
99 98 proto.startswith('text/plain') or
100 99 proto.startswith('application/hg-changegroup')):
101 100 self.ui.debug(_("Requested URL: '%s'\n") % cu)
102 raise repo.RepoError(_("'%s' does not appear to be an hg repository")
103 % self._url)
101 raise error.RepoError(_("'%s' does not appear to be an hg repository")
102 % self._url)
104 103
105 104 if proto.startswith('application/mercurial-'):
106 105 try:
107 106 version = proto.split('-', 1)[1]
108 107 version_info = tuple([int(n) for n in version.split('.')])
109 108 except ValueError:
110 raise repo.RepoError(_("'%s' sent a broken Content-Type "
111 "header (%s)") % (self._url, proto))
109 raise error.RepoError(_("'%s' sent a broken Content-Type "
110 "header (%s)") % (self._url, proto))
112 111 if version_info > (0, 1):
113 raise repo.RepoError(_("'%s' uses newer protocol %s") %
114 (self._url, version))
112 raise error.RepoError(_("'%s' uses newer protocol %s") %
113 (self._url, version))
115 114
116 115 return resp
117 116
@@ -129,7 +128,7 b' class httprepository(repo.repository):'
129 128 success, data = d[:-1].split(' ', 1)
130 129 if int(success):
131 130 return bin(data)
132 raise repo.RepoError(data)
131 raise error.RepoError(data)
133 132
134 133 def heads(self):
135 134 d = self.do_read("heads")
@@ -233,6 +232,6 b' def instance(ui, path, create):'
233 232 inst = httprepository(ui, path)
234 233 inst.between([(nullid, nullid)])
235 234 return inst
236 except repo.RepoError:
235 except error.RepoError:
237 236 ui.note('(falling back to static-http)\n')
238 237 return statichttprepo.instance(ui, "static-" + path, create)
@@ -47,9 +47,9 b' class localrepository(repo.repository):'
47 47 reqfile.write("%s\n" % r)
48 48 reqfile.close()
49 49 else:
50 raise repo.RepoError(_("repository %s not found") % path)
50 raise error.RepoError(_("repository %s not found") % path)
51 51 elif create:
52 raise repo.RepoError(_("repository %s already exists") % path)
52 raise error.RepoError(_("repository %s already exists") % path)
53 53 else:
54 54 # find requirements
55 55 requirements = []
@@ -57,7 +57,7 b' class localrepository(repo.repository):'
57 57 requirements = self.opener("requires").read().splitlines()
58 58 for r in requirements:
59 59 if r not in self.supported:
60 raise repo.RepoError(_("requirement '%s' not supported") % r)
60 raise error.RepoError(_("requirement '%s' not supported") % r)
61 61 except IOError, inst:
62 62 if inst.errno != errno.ENOENT:
63 63 raise
@@ -460,7 +460,7 b' class localrepository(repo.repository):'
460 460 key = hex(key)
461 461 except:
462 462 pass
463 raise repo.RepoError(_("unknown revision '%s'") % key)
463 raise error.RepoError(_("unknown revision '%s'") % key)
464 464
465 465 def local(self):
466 466 return True
@@ -566,7 +566,7 b' class localrepository(repo.repository):'
566 566
567 567 # abort here if the journal already exists
568 568 if os.path.exists(self.sjoin("journal")):
569 raise repo.RepoError(_("journal already exists - run hg recover"))
569 raise error.RepoError(_("journal already exists - run hg recover"))
570 570
571 571 # save dirstate for rollback
572 572 try:
@@ -1393,7 +1393,8 b' class localrepository(repo.repository):'
1393 1393 # sanity check our fetch list
1394 1394 for f in fetch.keys():
1395 1395 if f in m:
1396 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1396 raise error.RepoError(_("already have changeset ")
1397 + short(f[:4]))
1397 1398
1398 1399 if base.keys() == [nullid]:
1399 1400 if force:
@@ -8,12 +8,6 b''
8 8
9 9 from i18n import _
10 10
11 class RepoError(Exception):
12 pass
13
14 class NoCapability(RepoError):
15 pass
16
17 11 class repository(object):
18 12 def capable(self, name):
19 13 '''tell whether repo supports named capability.
@@ -31,9 +25,9 b' class repository(object):'
31 25 def requirecap(self, name, purpose):
32 26 '''raise an exception if the given capability is not present'''
33 27 if not self.capable(name):
34 raise NoCapability(_('cannot %s; remote repository does not '
35 'support the %r capability') %
36 (purpose, name))
28 raise error.CapabilityError(
29 _('cannot %s; remote repository does not '
30 'support the %r capability') % (purpose, name))
37 31
38 32 def local(self):
39 33 return False
@@ -7,7 +7,7 b''
7 7
8 8 from node import bin, hex
9 9 from i18n import _
10 import repo, os, re, util
10 import repo, os, re, util, error
11 11
12 12 class remotelock(object):
13 13 def __init__(self, repo):
@@ -26,7 +26,7 b' class sshrepository(repo.repository):'
26 26
27 27 m = re.match(r'^ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?$', path)
28 28 if not m:
29 self.raise_(repo.RepoError(_("couldn't parse location %s") % path))
29 self.raise_(error.RepoError(_("couldn't parse location %s") % path))
30 30
31 31 self.user = m.group(2)
32 32 self.host = m.group(3)
@@ -45,7 +45,7 b' class sshrepository(repo.repository):'
45 45 ui.note(_('running %s\n') % cmd)
46 46 res = util.system(cmd)
47 47 if res != 0:
48 self.raise_(repo.RepoError(_("could not create remote repo")))
48 self.raise_(error.RepoError(_("could not create remote repo")))
49 49
50 50 self.validate_repo(ui, sshcmd, args, remotecmd)
51 51
@@ -78,7 +78,7 b' class sshrepository(repo.repository):'
78 78 lines.append(l)
79 79 max_noise -= 1
80 80 else:
81 self.raise_(repo.RepoError(_("no suitable response from remote hg")))
81 self.raise_(error.RepoError(_("no suitable response from remote hg")))
82 82
83 83 self.capabilities = util.set()
84 84 lines.reverse()
@@ -157,7 +157,7 b' class sshrepository(repo.repository):'
157 157 if int(success):
158 158 return bin(data)
159 159 else:
160 self.raise_(repo.RepoError(data))
160 self.raise_(error.RepoError(data))
161 161
162 162 def heads(self):
163 163 d = self.call("heads")
@@ -198,7 +198,7 b' class sshrepository(repo.repository):'
198 198 d = self.call("unbundle", heads=' '.join(map(hex, heads)))
199 199 if d:
200 200 # remote may send "unsynced changes"
201 self.raise_(repo.RepoError(_("push refused: %s") % d))
201 self.raise_(error.RepoError(_("push refused: %s") % d))
202 202
203 203 while 1:
204 204 d = cg.read(4096)
@@ -211,7 +211,7 b' class sshrepository(repo.repository):'
211 211 r = self._recv()
212 212 if r:
213 213 # remote may send "unsynced changes"
214 self.raise_(repo.RepoError(_("push failed: %s") % r))
214 self.raise_(error.RepoError(_("push failed: %s") % r))
215 215
216 216 r = self._recv()
217 217 try:
@@ -222,7 +222,7 b' class sshrepository(repo.repository):'
222 222 def addchangegroup(self, cg, source, url):
223 223 d = self.call("addchangegroup")
224 224 if d:
225 self.raise_(repo.RepoError(_("push refused: %s") % d))
225 self.raise_(error.RepoError(_("push refused: %s") % d))
226 226 while 1:
227 227 d = cg.read(4096)
228 228 if not d:
@@ -8,7 +8,7 b''
8 8 # of the GNU General Public License, incorporated herein by reference.
9 9
10 10 from i18n import _
11 import changelog, byterange, url
11 import changelog, byterange, url, error
12 12 import repo, localrepo, manifest, util, store
13 13 import urllib, urllib2, errno
14 14
@@ -79,13 +79,13 b' class statichttprepository(localrepo.loc'
79 79 raise
80 80 # we do not care about empty old-style repositories here
81 81 msg = _("'%s' does not appear to be an hg repository") % path
82 raise repo.RepoError(msg)
82 raise error.RepoError(msg)
83 83 requirements = []
84 84
85 85 # check them
86 86 for r in requirements:
87 87 if r not in self.supported:
88 raise repo.RepoError(_("requirement '%s' not supported") % r)
88 raise error.RepoError(_("requirement '%s' not supported") % r)
89 89
90 90 # setup store
91 91 def pjoin(a, b):
General Comments 0
You need to be logged in to leave comments. Login now