Merge lp:~lifeless/bzr-git/bug-526133 into lp:bzr-git

Proposed by Robert Collins on 2010-02-23
Status: Rejected
Rejected by: Jelmer Vernooij on 2010-04-07
Proposed branch: lp:~lifeless/bzr-git/bug-526133
Merge into: lp:bzr-git
Diff against target: 216 lines (+110/-54)
2 files modified
NEWS (+3/-0)
__init__.py (+107/-54)
To merge this branch: bzr merge lp:~lifeless/bzr-git/bug-526133
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle 2010-02-23 Pending
Bazaar Developers 2010-02-23 Pending
Review via email: mp+19944@code.launchpad.net
To post a comment you must log in.
Robert Collins (lifeless) wrote :

as per request - a [hackish] but function deregister. I made register() so that it can be done again, and to group up the registration activities.

Jelmer Vernooij (jelmer) wrote :

On Tue, 2010-02-23 at 07:27 +0000, Robert Collins wrote:
> Robert Collins has proposed merging lp:~lifeless/bzr-git/bug-526133 into lp:bzr-git.
>
> Requested reviews:
> Michael Hudson (mwhudson)
> Bazaar Developers (bzr)
> Related bugs:
> #526133 need to be able to unload bzr-git
> https://bugs.launchpad.net/bugs/526133
>
>
> as per request - a [hackish] but function deregister. I made register() so that it can be done again, and to group up the registration activities.
I wonder, since this is hackish and specific to Launchpad, should it
perhaps land in lp:~launchpad-pqm/bzr-git/devel ?

Cheers,

Jelmer

Robert Collins (lifeless) wrote :

On Tue, 2010-02-23 at 14:30 +0000, Jelmer Vernooij wrote:

> I wonder, since this is hackish and specific to Launchpad, should it
> perhaps land in lp:~launchpad-pqm/bzr-git/devel ?

Up to you; either way is fine with me.

-Rob

Michael Hudson-Doyle (mwhudson) wrote :

Jelmer Vernooij wrote:
> On Tue, 2010-02-23 at 07:27 +0000, Robert Collins wrote:
>> Robert Collins has proposed merging lp:~lifeless/bzr-git/bug-526133 into lp:bzr-git.
>>
>> Requested reviews:
>> Michael Hudson (mwhudson)
>> Bazaar Developers (bzr)
>> Related bugs:
>> #526133 need to be able to unload bzr-git
>> https://bugs.launchpad.net/bugs/526133
>>
>>
>> as per request - a [hackish] but function deregister. I made register() so that it can be done again, and to group up the registration activities.
> I wonder, since this is hackish and specific to Launchpad, should it
> perhaps land in lp:~launchpad-pqm/bzr-git/devel ?

I tested the hack in ec2 and it seems sufficient for Launchpad's needs.

Cheers,
mwh

Jelmer Vernooij (jelmer) wrote :

should we land this in lp:~launchpad-pqm/bzr-git/devel?

Michael Hudson-Doyle (mwhudson) wrote :

Jelmer Vernooij wrote:
> should we land this in lp:~launchpad-pqm/bzr-git/devel?

Yes please. I've been meaning to do it, but you know...

Cheers,
mwh

Unmerged revisions

722. By Robert Collins on 2010-02-23

Support for unregistering from bzrlib, requested by Launchpad developers in bug 526133.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-02-18 12:04:46 +0000
3+++ NEWS 2010-02-23 07:27:18 +0000
4@@ -23,6 +23,9 @@
5
6 * Support (dumb) HTTP repositories. (#373688, Jelmer Vernooij)
7
8+ * Support for unregistering from bzrlib, requested by Launchpad developers in
9+ bug #526133. (Robert Collins)
10+
11 0.4.3 2010-01-19
12
13 BUG FIXES
14
15=== modified file '__init__.py'
16--- __init__.py 2010-02-12 19:14:43 +0000
17+++ __init__.py 2010-02-23 07:27:18 +0000
18@@ -46,6 +46,7 @@
19 bzrdir,
20 errors as bzr_errors,
21 osutils,
22+ transport,
23 )
24 from bzrlib.foreign import (
25 foreign_vcs_registry,
26@@ -87,23 +88,6 @@
27 if dulwich_version < dulwich_minimum_version:
28 raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Dulwich is too old; at least %d.%d.%d is required" % dulwich_minimum_version)
29
30-bzrdir.format_registry.register_lazy('git',
31- "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
32- help='GIT repository.', native=False, experimental=True,
33- )
34-
35-from bzrlib.revisionspec import revspec_registry
36-revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
37- "RevisionSpec_git")
38-
39-try:
40- from bzrlib.revisionspec import dwim_revspecs
41-except ImportError:
42- pass
43-else:
44- from bzrlib.plugins.git.revspec import RevisionSpec_git
45- dwim_revspecs.append(RevisionSpec_git)
46-
47
48 class GitBzrDirFormat(bzrdir.BzrDirFormat):
49
50@@ -229,50 +213,118 @@
51 raise bzr_errors.UninitializableFormat(self)
52
53
54-bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
55-bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
56-
57-register_transport_proto('git://',
58- help="Access using the Git smart server protocol.")
59-register_transport_proto('git+ssh://',
60- help="Access using the Git smart server protocol over SSH.")
61-
62-register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
63- 'TCPGitSmartTransport')
64-register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
65- 'SSHGitSmartTransport')
66-
67-foreign_vcs_registry.register_lazy("git",
68- "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
69-
70-plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
71-plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
72- "bzrlib.plugins.git.commands")
73-
74 def update_stanza(rev, stanza):
75 mapping = getattr(rev, "mapping", None)
76 if mapping is not None and mapping.revid_prefix.startswith("git-"):
77 stanza.add("git-commit", rev.foreign_revid)
78
79
80-rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
81-if rio_hooks is not None:
82- rio_hooks.install_named_hook('revision', update_stanza, None)
83-
84-
85+from bzrlib.revisionspec import revspec_registry
86+try:
87+ from bzrlib.revisionspec import dwim_revspecs
88+except ImportError:
89+ dwim_revspecs = None
90 from bzrlib.transport import transport_server_registry
91-transport_server_registry.register_lazy('git',
92- 'bzrlib.plugins.git.server',
93- 'serve_git',
94- 'Git Smart server protocol over TCP. (default port: 9418)')
95-
96-
97 from bzrlib.repository import network_format_registry as repository_network_format_registry
98-repository_network_format_registry.register_lazy('git',
99- 'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
100-
101 from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
102-bzrdir_network_format_registry.register('git', GitBzrDirFormat)
103+
104+__registered = False
105+def register():
106+ """Register bzr-git into all the registration points around.
107+
108+ If already registered, nothing will be done.
109+ """
110+ global __registered
111+ if __registered:
112+ return
113+ # Register for .git locally
114+ bzrdir.format_registry.register_lazy('git',
115+ "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
116+ help='GIT repository.', native=False, experimental=True,
117+ )
118+ # Register so that a .git repo on a remote server can be opened using
119+ # smart methods rather than VFS.
120+ bzrdir_network_format_registry.register('git', GitBzrDirFormat)
121+ repository_network_format_registry.register_lazy('git',
122+ 'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
123+ revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
124+ "RevisionSpec_git")
125+ if dwim_revspecs is not None:
126+ from bzrlib.plugins.git.revspec import RevisionSpec_git
127+ dwim_revspecs.append(RevisionSpec_git)
128+ bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
129+ bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
130+ register_transport_proto('git://',
131+ help="Access using the Git smart server protocol.")
132+ register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
133+ 'TCPGitSmartTransport')
134+ register_transport_proto('git+ssh://',
135+ help="Access using the Git smart server protocol over SSH.")
136+ register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
137+ 'SSHGitSmartTransport')
138+ foreign_vcs_registry.register_lazy("git",
139+ "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
140+ plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
141+ plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
142+ "bzrlib.plugins.git.commands")
143+ rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
144+ if rio_hooks is not None:
145+ rio_hooks.install_named_hook('revision', update_stanza, None)
146+ transport_server_registry.register_lazy('git',
147+ 'bzrlib.plugins.git.server',
148+ 'serve_git',
149+ 'Git Smart server protocol over TCP. (default port: 9418)')
150+ send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
151+ 'send_git', 'Git am-style diff format')
152+ __registered = True
153+
154+
155+def deregister():
156+ """Remove the registration of bzr-git from bzrlib.
157+
158+ This is generally not needed and a bad idea; however it is needed to deal
159+ with limitations in the launchpad test suite where some parts of it test
160+ behaviour that changes when other repository types are available.
161+
162+ Note: This is a bit hackish, but does the job. Like register, it is
163+ idempotent. This can be improved in time by adding deregistration to bzr
164+ core. However, this function only exists to work around bugs in the
165+ launchpad test suite, so its general cleanliness should not matter. Once
166+ launchpad fixes its test suite, this function can be deleted safely.
167+
168+ See bug #526133.
169+ """
170+ global __registered
171+ if not __registered:
172+ return
173+ def unregister(registry, key):
174+ registry._dict.pop(key)
175+ registry._help_dict.pop(key)
176+ registry._info_dict.pop(key)
177+ bzrdir.format_registry._registration_order.remove('git')
178+ unregister(bzrdir.format_registry, 'git')
179+ unregister(bzrdir_network_format_registry, 'git')
180+ unregister(revspec_registry, 'git:')
181+ if dwim_revspecs is not None:
182+ from bzrlib.plugins.git.revspec import RevisionSpec_git
183+ dwim_revspecs.remove(RevisionSpec_git)
184+ bzrdir.BzrDirFormat._control_formats.remove(LocalGitBzrDirFormat)
185+ bzrdir.BzrDirFormat._control_formats.remove(RemoteGitBzrDirFormat)
186+ # Technically, this is cheating: other plugins might offer git:// too and
187+ # this wipes it out totally.
188+ unregister(transport.transport_list_registry, 'git://')
189+ unregister(transport.transport_list_registry, 'git+ssh://')
190+ unregister(foreign_vcs_registry, "git")
191+ unregister(plugin_cmds, 'git-import')
192+ unregister(plugin_cmds, 'git-object')
193+ rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
194+ if rio_hooks is not None:
195+ hook = rio_hooks['revision']
196+ hook._callbacks.remove(update_stanza)
197+ unregister(transport_server_registry, 'git')
198+ unregister(repository_network_format_registry, 'git')
199+ unregister(send_format_registry, 'git')
200+ __registered = False
201
202
203 def get_rich_root_format(stacked=False):
204@@ -281,9 +333,10 @@
205 else:
206 return bzrdir.format_registry.make_bzrdir("default-rich-root")
207
208-send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
209- 'send_git', 'Git am-style diff format')
210
211 def test_suite():
212 from bzrlib.plugins.git import tests
213 return tests.test_suite()
214+
215+
216+register()

Subscribers

People subscribed via source and target branches

to all changes: