diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py --- a/hgext/convert/hg.py +++ b/hgext/convert/hg.py @@ -15,6 +15,7 @@ import os, time from mercurial.i18n import _ +from mercurial.repo import RepoError from mercurial.node import bin, hex, nullid from mercurial import hg, revlog, util @@ -32,7 +33,7 @@ class mercurial_sink(converter_sink): self.repo = hg.repository(self.ui, path) if not self.repo.local(): raise NoRepo(_('%s is not a local Mercurial repo') % path) - except hg.RepoError, err: + except RepoError, err: ui.print_exc() raise NoRepo(err.args[0]) else: @@ -42,7 +43,7 @@ class mercurial_sink(converter_sink): if not self.repo.local(): raise NoRepo(_('%s is not a local Mercurial repo') % path) self.created.append(path) - except hg.RepoError, err: + except RepoError, err: ui.print_exc() raise NoRepo("could not create hg repo %s as sink" % path) self.lock = None @@ -155,7 +156,7 @@ class mercurial_sink(converter_sink): bin(p1), bin(p2), extra=extra) self.repo.dirstate.clear() text = "(octopus merge fixup)\n" - p2 = hg.hex(self.repo.changelog.tip()) + p2 = hex(self.repo.changelog.tip()) if self.filemapmode and nparents == 1: man = self.repo.manifest @@ -194,7 +195,7 @@ class mercurial_sink(converter_sink): extra['branch'] = self.tagsbranch try: tagparent = self.repo.changectx(self.tagsbranch).node() - except hg.RepoError, inst: + except RepoError, inst: tagparent = nullid self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", date, tagparent, nullid, extra=extra) @@ -212,8 +213,8 @@ class mercurial_source(converter_source) # 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 hg.RepoError() - except hg.RepoError: + raise RepoError() + except RepoError: ui.print_exc() raise NoRepo("%s is not a local Mercurial repo" % path) self.lastrev = None diff --git a/hgext/hgk.py b/hgext/hgk.py --- a/hgext/hgk.py +++ b/hgext/hgk.py @@ -46,7 +46,8 @@ # vdiff on hovered and selected revisions. import os -from mercurial import hg, commands, util, patch, revlog +from mercurial import commands, util, patch, revlog +from mercurial.node import nullid, nullrev, short def difftree(ui, repo, node1=None, node2=None, *files, **opts): """diff trees from two commits""" @@ -57,18 +58,18 @@ def difftree(ui, repo, node1=None, node2 status = repo.status(node1, node2, files=files)[:5] modified, added, removed, deleted, unknown = status - empty = hg.short(hg.nullid) + empty = short(nullid) for f in modified: # TODO get file permissions ui.write(":100664 100664 %s %s M\t%s\t%s\n" % - (hg.short(mmap[f]), hg.short(mmap2[f]), f, f)) + (short(mmap[f]), short(mmap2[f]), f, f)) for f in added: ui.write(":000000 100664 %s %s N\t%s\t%s\n" % - (empty, hg.short(mmap2[f]), f, f)) + (empty, short(mmap2[f]), f, f)) for f in removed: ui.write(":100664 000000 %s %s D\t%s\t%s\n" % - (hg.short(mmap[f]), empty, f, f)) + (short(mmap[f]), empty, f, f)) ## while True: @@ -104,9 +105,9 @@ def catcommit(ui, repo, n, prefix, ctx=N if ctx is None: ctx = repo.changectx(n) (p1, p2) = ctx.parents() - ui.write("tree %s\n" % hg.short(ctx.changeset()[0])) # use ctx.node() instead ?? - if p1: ui.write("parent %s\n" % hg.short(p1.node())) - if p2: ui.write("parent %s\n" % hg.short(p2.node())) + ui.write("tree %s\n" % short(ctx.changeset()[0])) # use ctx.node() instead ?? + if p1: ui.write("parent %s\n" % short(p1.node())) + if p2: ui.write("parent %s\n" % short(p2.node())) date = ctx.date() description = ctx.description().replace("\0", "") lines = description.splitlines() @@ -132,7 +133,7 @@ def base(ui, repo, node1, node2): node1 = repo.lookup(node1) node2 = repo.lookup(node2) n = repo.changelog.ancestor(node1, node2) - ui.write(hg.short(n) + "\n") + ui.write(short(n) + "\n") def catfile(ui, repo, type=None, r=None, **opts): """cat a specific revision""" @@ -252,27 +253,27 @@ def revtree(ui, args, repo, full="tree", parentstr = "" if parents: pp = repo.changelog.parents(n) - if pp[0] != hg.nullid: - parentstr += " " + hg.short(pp[0]) - if pp[1] != hg.nullid: - parentstr += " " + hg.short(pp[1]) + if pp[0] != nullid: + parentstr += " " + short(pp[0]) + if pp[1] != nullid: + parentstr += " " + short(pp[1]) if not full: - ui.write("%s%s\n" % (hg.short(n), parentstr)) + ui.write("%s%s\n" % (short(n), parentstr)) elif full == "commit": - ui.write("%s%s\n" % (hg.short(n), parentstr)) + ui.write("%s%s\n" % (short(n), parentstr)) catcommit(ui, repo, n, ' ', ctx) else: (p1, p2) = repo.changelog.parents(n) - (h, h1, h2) = map(hg.short, (n, p1, p2)) + (h, h1, h2) = map(short, (n, p1, p2)) (i1, i2) = map(repo.changelog.rev, (p1, p2)) date = ctx.date()[0] ui.write("%s %s:%s" % (date, h, mask)) mask = is_reachable(want_sha1, reachable, p1) - if i1 != hg.nullrev and mask > 0: + if i1 != nullrev and mask > 0: ui.write("%s:%s " % (h1, mask)), mask = is_reachable(want_sha1, reachable, p2) - if i2 != hg.nullrev and mask > 0: + if i2 != nullrev and mask > 0: ui.write("%s:%s " % (h2, mask)) ui.write("\n") if maxnr and count >= maxnr: diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -30,6 +30,8 @@ refresh contents of top applied patch ''' 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 import os, sys, re, errno @@ -1254,7 +1256,7 @@ class queue: elif lines[i].startswith('Dirstate:'): l = lines[i].rstrip() l = l[10:].split(' ') - qpp = [ hg.bin(x) for x in l ] + qpp = [ bin(x) for x in l ] elif datastart != None: l = lines[i].rstrip() se = statusentry(l) @@ -1277,7 +1279,7 @@ class queue: if rev not in heads: self.ui.warn("save entry has children, leaving it alone\n") else: - self.ui.warn("removing save entry %s\n" % hg.short(rev)) + self.ui.warn("removing save entry %s\n" % short(rev)) pp = repo.dirstate.parents() if rev in pp: update = True @@ -1286,7 +1288,7 @@ class queue: self.strip(repo, rev, update=update, backup='strip') if qpp: self.ui.warn("saved queue repository parents: %s %s\n" % - (hg.short(qpp[0]), hg.short(qpp[1]))) + (short(qpp[0]), short(qpp[1]))) if qupdate: self.ui.status(_("queue directory updating\n")) r = self.qrepo() @@ -1311,7 +1313,7 @@ class queue: r = self.qrepo() if r: pp = r.dirstate.parents() - msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) + msg += "\nDirstate: %s %s" % (hex(pp[0]), hex(pp[1])) msg += "\n\nPatch Data:\n" text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and "\n".join(ar) + '\n' or "") @@ -1597,7 +1599,7 @@ def clone(ui, source, dest=None, **opts) patchespath = opts['patches'] or patchdir(sr) try: pr = hg.repository(ui, patchespath) - except hg.RepoError: + except RepoError: raise util.Abort(_('versioned patch repository not found' ' (see qinit -c)')) qbase, destrev = None, None diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -6,6 +6,7 @@ # of the GNU General Public License, incorporated herein by reference. from node import hex, nullid, nullrev, short +from repo import RepoError from i18n import _ import os, re, sys, urllib import hg, util, revlog, bundlerepo, extensions @@ -311,7 +312,7 @@ def bisect(ui, repo, rev=None, extra=Non try: for kind in state: for node in state[kind]: - f.write("%s %s\n" % (kind, hg.hex(node))) + f.write("%s %s\n" % (kind, hex(node))) f.rename() finally: del wlock @@ -333,7 +334,7 @@ def bisect(ui, repo, rev=None, extra=Non rev = repo.changelog.rev(node) ui.write(_("Testing changeset %s:%s " "(%s changesets remaining, ~%s tests)\n") - % (rev, hg.short(node), changesets, tests)) + % (rev, short(node), changesets, tests)) if not noupdate: cmdutil.bail_if_changed(repo) return hg.clean(repo, node) @@ -1522,7 +1523,7 @@ def import_(ui, repo, patch1, *patches, p2 = repo.lookup(p2) if p1 == wp[0].node(): repo.dirstate.setparents(p1, p2) - except hg.RepoError: + except RepoError: pass if opts.get('exact') or opts.get('import_branch'): repo.dirstate.setbranch(branch or 'default') @@ -2437,8 +2438,8 @@ def serve(ui, repo, **opts): if opts["stdio"]: if repo is None: - raise hg.RepoError(_("There is no Mercurial repository here" - " (.hg not found)")) + raise RepoError(_("There is no Mercurial repository here" + " (.hg not found)")) s = sshserver.sshserver(ui, repo) s.serve_forever() @@ -2452,8 +2453,8 @@ def serve(ui, repo, **opts): repo.ui.setconfig("web", o, str(opts[o])) if repo is None and not ui.config("web", "webdir_conf"): - raise hg.RepoError(_("There is no Mercurial repository here" - " (.hg not found)")) + raise RepoError(_("There is no Mercurial repository here" + " (.hg not found)")) class service: def init(self): diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -6,6 +6,7 @@ # of the GNU General Public License, incorporated herein by reference. from i18n import _ +from repo import RepoError import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex, time import util, commands, hg, lock, fancyopts, revlog, version, extensions, hook import cmdutil @@ -64,7 +65,7 @@ def _runcatch(ui, args): except cmdutil.UnknownCommand, inst: ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) commands.help_(ui, 'shortlist') - except hg.RepoError, inst: + except RepoError, inst: ui.warn(_("abort: %s!\n") % inst) except lock.LockHeld, inst: if inst.errno == errno.ETIMEDOUT: @@ -341,7 +342,7 @@ def _dispatch(ui, args): if not repo.local(): raise util.Abort(_("repository '%s' is not local") % path) ui.setconfig("bundle", "mainreporoot", repo.root) - except hg.RepoError: + except RepoError: if cmd not in commands.optionalrepo.split(): if args and not path: # try to infer -R from command args repos = map(_findrepo, args) @@ -349,8 +350,8 @@ def _dispatch(ui, args): if guess and repos.count(guess) == len(repos): return _dispatch(ui, ['--repository', guess] + fullargs) if not path: - raise hg.RepoError(_("There is no Mercurial repository here" - " (.hg not found)")) + raise RepoError(_("There is no Mercurial repository here" + " (.hg not found)")) raise d = lambda: func(ui, repo, *args, **cmdoptions) else: diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py --- a/mercurial/hbisect.py +++ b/mercurial/hbisect.py @@ -8,7 +8,8 @@ # of the GNU General Public License, incorporated herein by reference. from i18n import _ -import hg, util +from node import short +import util def bisect(changelog, state): clparents = changelog.parentrevs @@ -41,7 +42,7 @@ def bisect(changelog, state): bad = changelog.node(badrev) if not ancestors: # now we're confused raise util.Abort(_("Inconsistent state, %s:%s is good and bad") - % (badrev, hg.short(bad))) + % (badrev, short(bad))) # build children dict children = {} diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -6,8 +6,6 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -from node import bin, hex, nullid, nullrev, short -from repo import NoCapability, RepoError from i18n import _ import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo import errno, lock, os, shutil, util, extensions diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -8,6 +8,7 @@ import os, mimetypes, re from mercurial.node import hex, nullid, short +from mercurial.repo import RepoError from mercurial import mdiff, ui, hg, util, archival, patch, hook from mercurial import revlog, templater, templatefilters, changegroup from common import get_mtime, style_map, paritygen, countgen, get_contact @@ -74,7 +75,7 @@ def revnavgen(pos, pagelen, limit, nodef yield {"label": label, "node": node} yield {"label": "tip", "node": "tip"} - except hg.RepoError: + except RepoError: pass return nav @@ -248,7 +249,7 @@ class hgweb(object): except revlog.LookupError, err: req.respond(HTTP_NOT_FOUND, ctype) req.write(tmpl('error', error='revision not found: %s' % err.name)) - except (hg.RepoError, revlog.RevlogError), inst: + except (RepoError, revlog.RevlogError), inst: req.respond(HTTP_SERVER_ERROR, ctype) req.write(tmpl('error', error=str(inst))) except ErrorResponse, inst: @@ -915,7 +916,7 @@ class hgweb(object): try: ctx = self.repo.changectx(changeid) - except hg.RepoError: + except RepoError: man = self.repo.manifest mn = man.lookup(changeid) ctx = self.repo.changectx(man.linkrev(mn)) @@ -931,7 +932,7 @@ class hgweb(object): try: ctx = self.repo.changectx(changeid) fctx = ctx.filectx(path) - except hg.RepoError: + except RepoError: fctx = self.repo.filectx(path, fileid=changeid) return fctx diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -8,6 +8,7 @@ import os from mercurial.i18n import gettext as _ +from mercurial.repo import RepoError from mercurial import ui, hg, util, templater, templatefilters from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen,\ get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR @@ -110,7 +111,7 @@ class hgwebdir(object): except IOError, inst: msg = inst.strerror raise ErrorResponse(HTTP_SERVER_ERROR, msg) - except hg.RepoError, inst: + except RepoError, inst: raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) # browse subdirectories diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -8,6 +8,7 @@ import os, sys, errno, urllib, BaseHTTPServer, socket, SocketServer, traceback from mercurial import hg, util +from mercurial.repo import RepoError from hgweb_mod import hgweb from hgwebdir_mod import hgwebdir from mercurial.i18n import gettext as _ @@ -247,8 +248,8 @@ def create_server(ui, repo): elif repo is not None: hgwebobj = hgweb(hg.repository(repo.ui, repo.root)) else: - raise hg.RepoError(_("There is no Mercurial repository here" - " (.hg not found)")) + raise RepoError(_("There is no Mercurial repository here" + " (.hg not found)")) return hgwebobj self.application = make_handler() @@ -277,7 +278,7 @@ def create_server(ui, repo): def __init__(self, *args, **kwargs): if self.address_family is None: - raise hg.RepoError(_('IPv6 not available on this system')) + raise RepoError(_('IPv6 not available on this system')) super(IPv6HTTPServer, self).__init__(*args, **kwargs) if ssl_cert: diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -6,7 +6,8 @@ # of the GNU General Public License, incorporated herein by reference. import os, mimetypes -from mercurial import revlog, util, hg +from mercurial import revlog, util +from mercurial.repo import RepoError from common import staticfile, ErrorResponse, HTTP_OK, HTTP_NOT_FOUND # __all__ is populated with the allowed commands. Be sure to add to it if @@ -67,7 +68,7 @@ def changelog(web, req, tmpl, shortlog = hi = web.repo.changelog.count() - 1 try: ctx = web.repo.changectx(hi) - except hg.RepoError: + except RepoError: return web.search(tmpl, hi) # XXX redirect to 404 page? return web.changelog(tmpl, ctx, shortlog = shortlog)