Rev 722: Support for unregistering from bzrlib, requested by Launchpad developers in bug 526133. in http://people.canonical.com/~robertc/baz2.0/plugins/git/trunk
Robert Collins
robertc at robertcollins.net
Tue Feb 23 07:24:13 GMT 2010
At http://people.canonical.com/~robertc/baz2.0/plugins/git/trunk
------------------------------------------------------------
revno: 722
revision-id: robertc at robertcollins.net-20100223072410-stwp29znc45q8b37
parent: jelmer at samba.org-20100218120446-lj4y1l8d0s1hyt02
fixes bug(s): https://launchpad.net/bugs/526133
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Tue 2010-02-23 18:24:10 +1100
message:
Support for unregistering from bzrlib, requested by Launchpad developers in bug 526133.
=== modified file 'NEWS'
--- a/NEWS 2010-02-18 12:04:46 +0000
+++ b/NEWS 2010-02-23 07:24:10 +0000
@@ -23,6 +23,9 @@
* Support (dumb) HTTP repositories. (#373688, Jelmer Vernooij)
+ * Support for unregistering from bzrlib, requested by Launchpad developers in
+ bug #526133. (Robert Collins)
+
0.4.3 2010-01-19
BUG FIXES
=== modified file '__init__.py'
--- a/__init__.py 2010-02-12 19:14:43 +0000
+++ b/__init__.py 2010-02-23 07:24:10 +0000
@@ -46,6 +46,7 @@
bzrdir,
errors as bzr_errors,
osutils,
+ transport,
)
from bzrlib.foreign import (
foreign_vcs_registry,
@@ -87,23 +88,6 @@
if dulwich_version < dulwich_minimum_version:
raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Dulwich is too old; at least %d.%d.%d is required" % dulwich_minimum_version)
-bzrdir.format_registry.register_lazy('git',
- "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
- help='GIT repository.', native=False, experimental=True,
- )
-
-from bzrlib.revisionspec import revspec_registry
-revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
- "RevisionSpec_git")
-
-try:
- from bzrlib.revisionspec import dwim_revspecs
-except ImportError:
- pass
-else:
- from bzrlib.plugins.git.revspec import RevisionSpec_git
- dwim_revspecs.append(RevisionSpec_git)
-
class GitBzrDirFormat(bzrdir.BzrDirFormat):
@@ -229,50 +213,118 @@
raise bzr_errors.UninitializableFormat(self)
-bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
-bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
-
-register_transport_proto('git://',
- help="Access using the Git smart server protocol.")
-register_transport_proto('git+ssh://',
- help="Access using the Git smart server protocol over SSH.")
-
-register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
- 'TCPGitSmartTransport')
-register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
- 'SSHGitSmartTransport')
-
-foreign_vcs_registry.register_lazy("git",
- "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
-
-plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
-plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
- "bzrlib.plugins.git.commands")
-
def update_stanza(rev, stanza):
mapping = getattr(rev, "mapping", None)
if mapping is not None and mapping.revid_prefix.startswith("git-"):
stanza.add("git-commit", rev.foreign_revid)
-rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
-if rio_hooks is not None:
- rio_hooks.install_named_hook('revision', update_stanza, None)
-
-
+from bzrlib.revisionspec import revspec_registry
+try:
+ from bzrlib.revisionspec import dwim_revspecs
+except ImportError:
+ dwim_revspecs = None
from bzrlib.transport import transport_server_registry
-transport_server_registry.register_lazy('git',
- 'bzrlib.plugins.git.server',
- 'serve_git',
- 'Git Smart server protocol over TCP. (default port: 9418)')
-
-
from bzrlib.repository import network_format_registry as repository_network_format_registry
-repository_network_format_registry.register_lazy('git',
- 'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
-
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
-bzrdir_network_format_registry.register('git', GitBzrDirFormat)
+
+__registered = False
+def register():
+ """Register bzr-git into all the registration points around.
+
+ If already registered, nothing will be done.
+ """
+ global __registered
+ if __registered:
+ return
+ # Register for .git locally
+ bzrdir.format_registry.register_lazy('git',
+ "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
+ help='GIT repository.', native=False, experimental=True,
+ )
+ # Register so that a .git repo on a remote server can be opened using
+ # smart methods rather than VFS.
+ bzrdir_network_format_registry.register('git', GitBzrDirFormat)
+ repository_network_format_registry.register_lazy('git',
+ 'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
+ revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
+ "RevisionSpec_git")
+ if dwim_revspecs is not None:
+ from bzrlib.plugins.git.revspec import RevisionSpec_git
+ dwim_revspecs.append(RevisionSpec_git)
+ bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
+ bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
+ register_transport_proto('git://',
+ help="Access using the Git smart server protocol.")
+ register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
+ 'TCPGitSmartTransport')
+ register_transport_proto('git+ssh://',
+ help="Access using the Git smart server protocol over SSH.")
+ register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
+ 'SSHGitSmartTransport')
+ foreign_vcs_registry.register_lazy("git",
+ "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
+ plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
+ plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
+ "bzrlib.plugins.git.commands")
+ rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
+ if rio_hooks is not None:
+ rio_hooks.install_named_hook('revision', update_stanza, None)
+ transport_server_registry.register_lazy('git',
+ 'bzrlib.plugins.git.server',
+ 'serve_git',
+ 'Git Smart server protocol over TCP. (default port: 9418)')
+ send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
+ 'send_git', 'Git am-style diff format')
+ __registered = True
+
+
+def deregister():
+ """Remove the registration of bzr-git from bzrlib.
+
+ This is generally not needed and a bad idea; however it is needed to deal
+ with limitations in the launchpad test suite where some parts of it test
+ behaviour that changes when other repository types are available.
+
+ Note: This is a bit hackish, but does the job. Like register, it is
+ idempotent. This can be improved in time by adding deregistration to bzr
+ core. However, this function only exists to work around bugs in the
+ launchpad test suite, so its general cleanliness should not matter. Once
+ launchpad fixes its test suite, this function can be deleted safely.
+
+ See bug #526133.
+ """
+ global __registered
+ if not __registered:
+ return
+ def unregister(registry, key):
+ registry._dict.pop(key)
+ registry._help_dict.pop(key)
+ registry._info_dict.pop(key)
+ bzrdir.format_registry._registration_order.remove('git')
+ unregister(bzrdir.format_registry, 'git')
+ unregister(bzrdir_network_format_registry, 'git')
+ unregister(revspec_registry, 'git:')
+ if dwim_revspecs is not None:
+ from bzrlib.plugins.git.revspec import RevisionSpec_git
+ dwim_revspecs.remove(RevisionSpec_git)
+ bzrdir.BzrDirFormat._control_formats.remove(LocalGitBzrDirFormat)
+ bzrdir.BzrDirFormat._control_formats.remove(RemoteGitBzrDirFormat)
+ # Technically, this is cheating: other plugins might offer git:// too and
+ # this wipes it out totally.
+ unregister(transport.transport_list_registry, 'git://')
+ unregister(transport.transport_list_registry, 'git+ssh://')
+ unregister(foreign_vcs_registry, "git")
+ unregister(plugin_cmds, 'git-import')
+ unregister(plugin_cmds, 'git-object')
+ rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
+ if rio_hooks is not None:
+ hook = rio_hooks['revision']
+ hook._callbacks.remove(update_stanza)
+ unregister(transport_server_registry, 'git')
+ unregister(repository_network_format_registry, 'git')
+ unregister(send_format_registry, 'git')
+ __registered = False
def get_rich_root_format(stacked=False):
@@ -281,9 +333,10 @@
else:
return bzrdir.format_registry.make_bzrdir("default-rich-root")
-send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
- 'send_git', 'Git am-style diff format')
def test_suite():
from bzrlib.plugins.git import tests
return tests.test_suite()
+
+
+register()
More information about the bazaar-commits
mailing list