1
# Copyright (C) 2006-2009 Canonical Ltd
3
# Authors: Robert Collins <robert.collins@canonical.com>
4
# Jelmer Vernooij <jelmer@samba.org>
5
# John Carr <john.carr@unrouted.co.uk>
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
"""A GIT branch and repository format implementation for bzr."""
31
bzr_compatible_versions,
32
bzr_plugin_version as version_info,
33
dulwich_minimum_version,
36
if version_info[3] == 'final':
37
version_string = '%d.%d.%d' % version_info[:3]
39
version_string = '%d.%d.%d%s%d' % version_info
40
__version__ = version_string
42
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
49
from bzrlib.controldir import (
53
network_format_registry as controldir_network_format_registry,
56
from bzrlib.foreign import (
59
from bzrlib.help_topics import (
62
from bzrlib.transport import (
63
register_lazy_transport,
64
register_transport_proto,
66
from bzrlib.commands import (
69
from bzrlib.send import (
70
format_registry as send_format_registry,
74
if getattr(sys, "frozen", None):
75
# allow import additional libs from ./_lib for bzr.exe only
76
sys.path.append(os.path.normpath(
77
os.path.join(os.path.dirname(__file__), '_lib')))
82
from dulwich import __version__ as dulwich_version
84
raise bzr_errors.DependencyNotPresent("dulwich",
85
"bzr-git: Please install dulwich, https://launchpad.net/dulwich")
87
if dulwich_version < dulwich_minimum_version:
88
raise bzr_errors.DependencyNotPresent("dulwich",
89
"bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
90
dulwich_minimum_version)
93
_versions_checked = False
94
def lazy_check_versions():
95
global _versions_checked
99
_versions_checked = True
101
format_registry.register_lazy('git',
102
"bzrlib.plugins.git.dir", "LocalGitControlDirFormat",
103
help='GIT repository.', native=False, experimental=False,
106
format_registry.register_lazy('git-bare',
107
"bzrlib.plugins.git.dir", "BareLocalGitControlDirFormat",
108
help='Bare GIT repository (no working tree).', native=False,
112
from bzrlib.revisionspec import revspec_registry
113
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
116
from bzrlib.revisionspec import dwim_revspecs, RevisionSpec_dwim
117
if getattr(RevisionSpec_dwim, "append_possible_lazy_revspec", None):
118
RevisionSpec_dwim.append_possible_lazy_revspec(
119
"bzrlib.plugins.git.revspec", "RevisionSpec_git")
121
from bzrlib.plugins.git.revspec import RevisionSpec_git
122
dwim_revspecs.append(RevisionSpec_git)
125
class LocalGitProber(Prober):
127
def probe_transport(self, transport):
129
if not transport.has_any(['info/refs', '.git/branches',
131
raise bzr_errors.NotBranchError(path=transport.base)
132
except bzr_errors.NoSuchFile:
133
raise bzr_errors.NotBranchError(path=transport.base)
134
from bzrlib import urlutils
135
if urlutils.split(transport.base)[1] == ".git":
136
raise bzr_errors.NotBranchError(path=transport.base)
137
lazy_check_versions()
139
from bzrlib.plugins.git.transportgit import TransportRepo
141
gitrepo = TransportRepo(transport)
142
except dulwich.errors.NotGitRepository, e:
143
raise bzr_errors.NotBranchError(path=transport.base)
145
from bzrlib.plugins.git.dir import (
146
BareLocalGitControlDirFormat,
147
LocalGitControlDirFormat,
150
return BareLocalGitControlDirFormat()
152
return LocalGitControlDirFormat()
155
def known_formats(cls):
156
from bzrlib.plugins.git.dir import (
157
BareLocalGitControlDirFormat,
158
LocalGitControlDirFormat,
160
return set([BareLocalGitControlDirFormat(), LocalGitControlDirFormat()])
163
class RemoteGitProber(Prober):
165
def probe_transport(self, transport):
167
if url.startswith('readonly+'):
168
url = url[len('readonly+'):]
169
if (not url.startswith("git://") and not url.startswith("git+")):
170
raise bzr_errors.NotBranchError(transport.base)
171
# little ugly, but works
172
from bzrlib.plugins.git.remote import (
174
RemoteGitControlDirFormat,
176
if not isinstance(transport, GitSmartTransport):
177
raise bzr_errors.NotBranchError(transport.base)
178
return RemoteGitControlDirFormat()
181
def known_formats(cls):
182
from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
183
return set([RemoteGitControlDirFormat()])
186
if not getattr(Prober, "known_formats", None): # bzr < 2.4
187
from bzrlib.plugins.git.dir import (
188
LocalGitControlDirFormat, BareLocalGitControlDirFormat,
190
from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
191
ControlDirFormat.register_format(LocalGitControlDirFormat())
192
ControlDirFormat.register_format(BareLocalGitControlDirFormat())
193
ControlDirFormat.register_format(RemoteGitControlDirFormat())
194
# Provide RevisionTree.get_file_revision, so various parts of bzr-svn
195
# can avoid inventories.
196
from bzrlib.revisiontree import RevisionTree
197
def get_file_revision(tree, file_id, path=None):
198
return tree.inventory[file_id].revision
199
RevisionTree.get_file_revision = get_file_revision
201
ControlDirFormat.register_prober(LocalGitProber)
202
ControlDirFormat.register_prober(RemoteGitProber)
204
register_transport_proto('git://',
205
help="Access using the Git smart server protocol.")
206
register_transport_proto('git+ssh://',
207
help="Access using the Git smart server protocol over SSH.")
209
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
210
'TCPGitSmartTransport')
211
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
212
'SSHGitSmartTransport')
214
foreign_vcs_registry.register_lazy("git",
215
"bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
217
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
218
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
219
"bzrlib.plugins.git.commands")
220
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
221
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
223
def update_stanza(rev, stanza):
224
mapping = getattr(rev, "mapping", None)
225
if mapping is not None and mapping.revid_prefix.startswith("git-"):
226
stanza.add("git-commit", rev.foreign_revid)
229
from bzrlib.hooks import install_lazy_named_hook
230
except ImportError: # Compatibility with bzr < 2.4
231
from bzrlib.version_info_formats.format_rio import (
232
RioVersionInfoBuilder,
234
RioVersionInfoBuilder.hooks.install_named_hook('revision', update_stanza,
237
install_lazy_named_hook("bzrlib.version_info_formats.format_rio",
238
"RioVersionInfoBuilder.hooks", "revision", update_stanza,
242
from bzrlib.transport import transport_server_registry
243
transport_server_registry.register_lazy('git',
244
'bzrlib.plugins.git.server',
246
'Git Smart server protocol over TCP. (default port: 9418)')
249
from bzrlib.repository import (
250
format_registry as repository_format_registry,
251
network_format_registry as repository_network_format_registry,
253
repository_network_format_registry.register_lazy('git',
254
'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
257
register_extra_lazy_repository_format = getattr(repository_format_registry,
258
"register_extra_lazy")
259
except AttributeError: # bzr < 2.4
262
register_extra_lazy_repository_format('bzrlib.plugins.git.repository',
263
'GitRepositoryFormat')
265
from bzrlib.branch import (
266
network_format_registry as branch_network_format_registry,
268
branch_network_format_registry.register_lazy('git',
269
'bzrlib.plugins.git.branch', 'GitBranchFormat')
272
from bzrlib.branch import (
273
format_registry as branch_format_registry,
275
except ImportError: # bzr < 2.4
278
branch_format_registry.register_extra_lazy(
279
'bzrlib.plugins.git.branch',
284
from bzrlib.workingtree import (
285
format_registry as workingtree_format_registry,
287
except ImportError: # bzr < 2.4
290
workingtree_format_registry.register_extra_lazy(
291
'bzrlib.plugins.git.workingtree',
292
'GitWorkingTreeFormat',
295
controldir_network_format_registry.register_lazy('git',
296
"bzrlib.plugins.git.dir", "GitControlDirFormat")
298
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
299
'send_git', 'Git am-style diff format')
301
topic_registry.register_lazy('git', 'bzrlib.plugins.git.help', 'help_git',
302
'Using Bazaar with Git')
304
from bzrlib.diff import format_registry as diff_format_registry
305
diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
306
'GitDiffTree', 'Git am-style diff format')
309
from bzrlib.plugins.git import tests
310
return tests.test_suite()