Rev 27: Use local importing to make sure we actually get the modules we ask for. in http://bazaar.launchpad.net/%7Ejameinel/bzr-hg/demandload_import_fixes
John Arbash Meinel
john at arbash-meinel.com
Tue Jul 31 19:31:42 BST 2007
At http://bazaar.launchpad.net/%7Ejameinel/bzr-hg/demandload_import_fixes
------------------------------------------------------------
revno: 27
revision-id: john at arbash-meinel.com-20070731183147-cybug7bbq0ia4a2u
parent: robertc at robertcollins.net-20070711151717-1yookaori2o2efsp
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: hg
timestamp: Tue 2007-07-31 13:31:47 -0500
message:
Use local importing to make sure we actually get the modules we ask for.
With hg 0.9.4, it seems they auto-enable demand importing of all modules.
Which breaks in odd ways. (import mercurial.ui; mercurial.ui.ui() fails with
no 'ui' object on that module).
Using direct from foo import bar gets around most of that.
modified:
__init__.py __init__.py-20060531211707-2fy7rwqqcmfgf8ve-1
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-07-11 14:56:50 +0000
+++ b/__init__.py 2007-07-31 18:31:47 +0000
@@ -31,26 +31,30 @@
import os
import stat
-import mercurial.commands
-import mercurial.cmdutil
-import mercurial.hg
-import mercurial.node
+from mercurial import (
+ cmdutil as _hg_cmdutil,
+ hg as _hg_hg,
+ node as _hg_node,
+ ui as _hg_ui,
+ )
from mercurial.node import hex, bin
-import mercurial.ui
-import bzrlib.branch
-import bzrlib.bzrdir
+from bzrlib import (
+ branch,
+ bzrdir,
+ errors,
+ inventory as _mod_inventory,
+ lockable_files,
+ repository,
+ ui,
+ workingtree,
+ )
from bzrlib.decorators import *
-import bzrlib.errors as errors
-from bzrlib.inventory import Inventory
-import bzrlib.lockable_files
from bzrlib.osutils import basename, split_lines, sha_strings
-import bzrlib.repository
from bzrlib.revision import Revision
from bzrlib.tests import TestLoader, TestCaseWithTransport
from bzrlib.transport.local import LocalTransport
from bzrlib.tsort import topo_sort
-import bzrlib.workingtree
def hgrevid_from_bzr(revision_id):
@@ -86,7 +90,7 @@
raise errors.TokenLockingNotSupported(self)
-class HgLockableFiles(bzrlib.lockable_files.LockableFiles):
+class HgLockableFiles(lockable_files.LockableFiles):
"""Hg specific lockable files abstraction."""
def __init__(self, lock, transport):
@@ -105,7 +109,7 @@
self.branch = branch
-class HgRepositoryFormat(bzrlib.repository.RepositoryFormat):
+class HgRepositoryFormat(repository.RepositoryFormat):
"""Mercurial Repository Format.
This is currently not aware of different repository formats,
@@ -118,7 +122,7 @@
return "Mercurial Repository"
-class HgRepository(bzrlib.repository.Repository):
+class HgRepository(repository.Repository):
"""An adapter to mercurial repositories for bzr."""
def __init__(self, hgrepo, hgdir, lockfiles):
@@ -130,7 +134,7 @@
def _check(self, revision_ids):
# TODO: Call out to mercurial for consistency checking?
- return bzrlib.branch.BranchCheckResult(self)
+ return branch.BranchCheckResult(self)
def get_inventory(self, revision_id):
"""Synthesize a bzr inventory from an hg manifest...
@@ -160,7 +164,7 @@
manifest = self._hgrepo.manifest.read(log[0])
all_relevant_revisions = self.get_revision_graph(revision_id)
ancestry_cache = {}
- result = Inventory()
+ result = _mod_inventory.Inventory()
# each directory is a key - i.e. 'foo'
# the value is the current chosen revision value for it.
# we walk up the hierarchy - when a dir changes .revision, its parent
@@ -258,7 +262,7 @@
while parent_cls:
current_cl = parent_cls.pop()
# the nullid isn't useful.
- if current_cl == mercurial.node.nullid:
+ if current_cl == _hg_node.nullid:
continue
if current_cl not in known_manifests:
current_manifest_id = self._hgrepo.changelog.read(current_cl)[0]
@@ -284,7 +288,7 @@
while parent_cl_ids:
current_cl_id_child, current_cl_id = parent_cl_ids.pop()
# the nullid isn't useful.
- if current_cl_id == mercurial.node.nullid:
+ if current_cl_id == _hg_node.nullid:
continue
if current_cl_id not in known_manifests:
current_manifest_id = self._hgrepo.changelog.read(current_cl_id)[0]
@@ -297,7 +301,7 @@
good_id = current_cl_id_child
continue
# walk to the parents
- if (mercurial.node.nullid, mercurial.node.nullid) == self._hgrepo.changelog.parents(current_cl_id):
+ if (_hg_node.nullid, _hg_node.nullid) == self._hgrepo.changelog.parents(current_cl_id):
# we have reached the root:
good_id = current_cl_id
continue
@@ -325,9 +329,9 @@
hgchange = self._hgrepo.changelog.read(hgrevid_from_bzr(revision_id))
hgparents = self._hgrepo.changelog.parents(hgrevid_from_bzr(revision_id))
result.parent_ids = []
- if hgparents[0] != mercurial.node.nullid:
+ if hgparents[0] != _hg_node.nullid:
result.parent_ids.append(bzrrevid_from_hg(hgparents[0]))
- if hgparents[1] != mercurial.node.nullid:
+ if hgparents[1] != _hg_node.nullid:
result.parent_ids.append(bzrrevid_from_hg(hgparents[1]))
result.message = hgchange[4]
result.inventory_sha1 = ""
@@ -362,7 +366,7 @@
return False
-class HgBranchFormat(bzrlib.branch.BranchFormat):
+class HgBranchFormat(branch.BranchFormat):
"""Mercurial Branch Format.
This is currently not aware of different branch formats,
@@ -389,11 +393,11 @@
return basename(self._branch.base[:-1])
-class HgBranch(bzrlib.branch.Branch):
+class HgBranch(branch.Branch):
"""An adapter to mercurial repositories for bzr Branch objects."""
def __init__(self, hgrepo, hgdir, lockfiles):
- bzrlib.branch.Branch.__init__(self)
+ branch.Branch.__init__(self)
self._hgrepo = hgrepo
self.bzrdir = hgdir
self.control_files = lockfiles
@@ -403,7 +407,7 @@
def _check(self):
# TODO: Call out to mercurial for consistency checking?
- return bzrlib.branch.BranchCheckResult(self)
+ return branch.BranchCheckResult(self)
def get_parent(self):
"""Return the URL of the parent branch."""
@@ -434,7 +438,7 @@
tip = hgrevid_from_bzr(self.last_revision())
revs = []
next_rev = tip
- while next_rev != mercurial.node.nullid:
+ while next_rev != _hg_node.nullid:
revs.append(bzrrevid_from_hg(next_rev))
next_rev = self._hgrepo.changelog.parents(next_rev)[0]
revs.reverse()
@@ -464,7 +468,7 @@
return to_bzrdir.open_branch()
-class HgWorkingTreeFormat(bzrlib.workingtree.WorkingTreeFormat):
+class HgWorkingTreeFormat(workingtree.WorkingTreeFormat):
"""Working Tree format for Mercurial Working Trees.
This is currently not aware of different working tree formats,
@@ -477,7 +481,7 @@
return "Mercurial Working Tree"
-class HgWorkingTree(bzrlib.workingtree.WorkingTree):
+class HgWorkingTree(workingtree.WorkingTree):
"""An adapter to mercurial repositories for bzr WorkingTree obejcts."""
def __init__(self, hgrepo, hgdir, lockfiles):
@@ -499,7 +503,7 @@
@needs_write_lock
def commit(self, message, *args, **kwargs):
# TODO: selected file lists etc.
- files, matchfn, anypats = mercurial.cmdutil.matchpats(self._hgrepo)
+ files, matchfn, anypats = _hg_cmdutil.matchpats(self._hgrepo)
self._hgrepo.commit([], message, None, None, matchfn, wlock=self._control_files._lock)
# def read_working_inventory(self):
@@ -516,7 +520,7 @@
self.branch.unlock()
-class HgDir(bzrlib.bzrdir.BzrDir):
+class HgDir(bzrdir.BzrDir):
"""An adapter to the '.hg' dir used by mercurial."""
def __init__(self, hgrepo, transport, lockfiles, format):
@@ -584,7 +588,7 @@
return HgWorkingTree(self._hgrepo, self, self._lockfiles)
-class HgBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
+class HgBzrDirFormat(bzrdir.BzrDirFormat):
"""The .hg directory control format."""
def get_converter(self):
@@ -614,10 +618,10 @@
path = transport.local_abspath('.').encode('utf-8')
else:
raise errors.BzrCommandError('cannot use hg on %s transport' % transport)
- ui = mercurial.ui.ui()
- repository = mercurial.hg.repository(ui, path, create=_create)
- lockfiles = HgLockableFiles(HgLock(repository), transport)
- return HgDir(repository, transport, lockfiles, self)
+ hgui = _hg_ui.ui()
+ repo = _hg_hg.repository(hgui, path, create=_create)
+ lockfiles = HgLockableFiles(HgLock(repo), transport)
+ return HgDir(repo, transport, lockfiles, self)
@classmethod
def probe_transport(klass, transport):
@@ -639,14 +643,14 @@
raise errors.NotBranchError(path=transport.base)
-bzrlib.bzrdir.BzrDirFormat.register_control_format(HgBzrDirFormat)
-
-
-class HgToSomethingConverter(bzrlib.bzrdir.Converter):
+bzrdir.BzrDirFormat.register_control_format(HgBzrDirFormat)
+
+
+class HgToSomethingConverter(bzrdir.Converter):
"""A class to upgrade an hg dir to something else."""
-class FromHgRepository(bzrlib.repository.InterRepository):
+class FromHgRepository(repository.InterRepository):
"""Hg to any repository actions."""
@classmethod
@@ -708,7 +712,7 @@
order = [rev_id for rev_id in order if rev_id in needed]
total = len(order)
inventories = {}
- pb = bzrlib.ui.ui_factory.nested_progress_bar()
+ pb = ui.ui_factory.nested_progress_bar()
try:
for index, revision_id in enumerate(order):
pb.update('fetching revisions', index, total)
@@ -719,7 +723,7 @@
log = self.source._hgrepo.changelog.read(hgrevid)
manifest = self.source._hgrepo.manifest.read(log[0])
for fileid in inventory:
- if fileid == bzrlib.inventory.ROOT_ID:
+ if fileid == _mod_inventory.ROOT_ID:
continue
entry = inventory[fileid]
if inventory[fileid].revision == revision_id:
@@ -772,7 +776,7 @@
"""Be compatible with HgRepositories."""
return isinstance(source, HgRepository)
-bzrlib.repository.InterRepository.register_optimiser(FromHgRepository)
+repository.InterRepository.register_optimiser(FromHgRepository)
def test_suite():
return TestLoader().loadTestsFromName(__name__)
@@ -792,7 +796,7 @@
# changes it behaviour, we want this test to start failing.
self.tree.add(['a', 'b', 'dir/c'])
self.tree.commit('foo')
- revone_inventory = Inventory()
+ revone_inventory = _mod_inventory.Inventory()
tip = self.tree.last_revision()
entry = revone_inventory.add_path('a', kind='file', file_id='hg:a')
entry.revision = tip
More information about the bazaar-commits
mailing list