[PATCH 7 of 7] Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg

Joel Rosdahl joel at rosdahl.net
Thu Mar 6 15:52:18 CST 2008


# HG changeset patch
# User Joel Rosdahl <joel at rosdahl.net>
# Date 1204840276 -3600
# Node ID ade7af14a1c01ffab3d747fea46143d0e53be40e
# Parent  c22bbc7b5592f5816c43c93eab71775d2a9b932c
Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg

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 @@
                 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 @@
                 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 @@
                                     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 @@
                 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 @@
             # 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 @@
         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 @@
     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 @@
     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 @@
             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 @@
 '''
 
 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 @@
             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 @@
             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 @@
                 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 @@
         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 @@
     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 @@
     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 @@
         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 @@
                         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 @@
 
     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 @@
                 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 @@
     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 @@
             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 @@
                     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 @@
     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 @@
                 yield {"label": label, "node": node}
 
             yield {"label": "tip", "node": "tip"}
-        except hg.RepoError:
+        except RepoError:
             pass
 
     return nav
@@ -248,7 +249,7 @@
         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:
@@ -909,7 +910,7 @@
 
         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))
@@ -925,7 +926,7 @@
         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 @@
                         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 @@
                 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 __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 @@
             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)


More information about the Mercurial-devel mailing list