30
# versions ending in 'exp' mean experimental mappings
31
# versions ending in 'dev' mean development version
32
# versions ending in 'final' mean release (well tested, etc)
33
version_info = (0, 3, 3, 'dev', 0)
31
bzr_compatible_versions,
32
bzr_plugin_version as version_info,
33
dulwich_minimum_version,
35
36
if version_info[3] == 'final':
36
37
version_string = '%d.%d.%d' % version_info[:3]
38
39
version_string = '%d.%d.%d%s%d' % version_info
39
40
__version__ = version_string
41
MINIMUM_DULWICH_VERSION = (0, 3, 1)
42
COMPATIBLE_BZR_VERSIONS = [(1, 14, 0), (1, 15, 0)]
44
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
42
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
47
45
from bzrlib import (
49
46
errors as bzr_errors,
50
from bzrlib.controldir import (
58
from bzrlib.bzrdir import (
64
ControlDirFormat = BzrDirFormat
66
has_controldir = False
52
70
from bzrlib.foreign import (
53
71
foreign_vcs_registry,
73
from bzrlib.help_topics import (
55
76
from bzrlib.lockable_files import (
62
83
from bzrlib.commands import (
65
from bzrlib.trace import (
68
86
from bzrlib.version_info_formats.format_rio import (
69
87
RioVersionInfoBuilder,
89
from bzrlib.send import (
90
format_registry as send_format_registry,
73
94
if getattr(sys, "frozen", None):
74
95
# allow import additional libs from ./_lib for bzr.exe only
75
sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
96
sys.path.append(os.path.normpath(
97
os.path.join(os.path.dirname(__file__), '_lib')))
100
def import_dulwich():
102
from dulwich import __version__ as dulwich_version
104
raise bzr_errors.DependencyNotPresent("dulwich",
105
"bzr-git: Please install dulwich, https://launchpad.net/dulwich")
107
if dulwich_version < dulwich_minimum_version:
108
raise bzr_errors.DependencyNotPresent("dulwich",
109
"bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
110
dulwich_minimum_version)
77
113
_versions_checked = False
78
114
def lazy_check_versions():
79
115
global _versions_checked
80
116
if _versions_checked:
82
119
_versions_checked = True
84
from dulwich import __version__ as dulwich_version
86
raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
88
if dulwich_version < MINIMUM_DULWICH_VERSION:
89
raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
91
bzrdir.format_registry.register_lazy('git',
92
"bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
121
format_registry.register_lazy('git',
122
"bzrlib.plugins.git.dir", "LocalGitControlDirFormat",
93
123
help='GIT repository.', native=False, experimental=True,
96
126
from bzrlib.revisionspec import revspec_registry
97
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
127
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
98
128
"RevisionSpec_git")
101
class GitBzrDirFormat(bzrdir.BzrDirFormat):
131
from bzrlib.revisionspec import dwim_revspecs
135
from bzrlib.plugins.git.revspec import RevisionSpec_git
136
dwim_revspecs.append(RevisionSpec_git)
139
class GitControlDirFormat(ControlDirFormat):
102
141
_lock_class = TransportLock
143
colocated_branches = True
145
def __eq__(self, other):
146
return type(self) == type(other)
104
148
def is_supported(self):
111
class LocalGitBzrDirFormat(GitBzrDirFormat):
112
"""The .git directory control format."""
115
def _known_formats(self):
116
return set([LocalGitBzrDirFormat()])
118
def open(self, transport, _found=None):
119
"""Open this directory.
122
import dulwich as git
123
# we dont grok readonly - git isn't integrated with transport.
125
if url.startswith('readonly+'):
126
url = url[len('readonly+'):]
155
class LocalGitProber(Prober):
157
def probe_transport(self, transport):
129
gitrepo = git.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
130
except bzr_errors.NotLocalUrl:
131
raise bzr_errors.NotBranchError(path=transport.base)
132
from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
133
lockfiles = GitLockableFiles(transport, GitLock())
134
return LocalGitDir(transport, lockfiles, gitrepo, self)
137
def probe_transport(klass, transport):
138
"""Our format is present if the transport ends in '.not/'."""
139
from bzrlib.transport.local import LocalTransport
141
if not isinstance(transport, LocalTransport):
142
raise bzr_errors.NotBranchError(path=transport.base)
144
# This should quickly filter out most things that are not
145
# git repositories, saving us the trouble from loading dulwich.
146
if not transport.has(".git") and not transport.has("objects"):
147
raise bzr_errors.NotBranchError(path=transport.base)
149
import dulwich as git
159
if not transport.has_any(['info/refs', '.git/branches',
161
raise bzr_errors.NotBranchError(path=transport.base)
162
except bzr_errors.NoSuchFile:
163
raise bzr_errors.NotBranchError(path=transport.base)
164
from bzrlib import urlutils
165
if urlutils.split(transport.base)[1] == ".git":
166
raise bzr_errors.NotBranchError(path=transport.base)
167
lazy_check_versions()
169
format = LocalGitControlDirFormat()
152
171
format.open(transport)
154
except git.errors.NotGitRepository, e:
173
except dulwich.errors.NotGitRepository, e:
155
174
raise bzr_errors.NotBranchError(path=transport.base)
156
175
raise bzr_errors.NotBranchError(path=transport.base)
178
class LocalGitControlDirFormat(GitControlDirFormat):
179
"""The .git directory control format."""
182
def _known_formats(self):
183
return set([LocalGitControlDirFormat()])
185
def open(self, transport, _found=None):
186
"""Open this directory.
189
lazy_check_versions()
190
from bzrlib.plugins.git.transportgit import TransportRepo
191
gitrepo = TransportRepo(transport)
192
from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
193
lockfiles = GitLockableFiles(transport, GitLock())
194
return LocalGitDir(transport, lockfiles, gitrepo, self)
197
def probe_transport(klass, transport):
198
prober = LocalGitProber()
199
return prober.probe_transport(transport)
158
201
def get_format_description(self):
159
202
return "Local Git Repository"
165
208
from bzrlib.transport.local import LocalTransport
167
210
if not isinstance(transport, LocalTransport):
168
raise NotImplementedError(self.initialize,
211
raise NotImplementedError(self.initialize,
169
212
"Can't create Git Repositories/branches on "
170
213
"non-local transports")
214
lazy_check_versions()
172
215
from dulwich.repo import Repo
173
Repo.create(transport.local_abspath(".").encode(osutils._fs_enc))
216
Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
174
217
return self.open(transport)
176
219
def is_supported(self):
180
class RemoteGitBzrDirFormat(GitBzrDirFormat):
223
class RemoteGitProber(Prober):
225
def probe_transport(self, transport):
227
if url.startswith('readonly+'):
228
url = url[len('readonly+'):]
229
if (not url.startswith("git://") and not url.startswith("git+")):
230
raise bzr_errors.NotBranchError(transport.base)
231
# little ugly, but works
232
format = RemoteGitControlDirFormat()
233
from bzrlib.plugins.git.remote import GitSmartTransport
234
if not isinstance(transport, GitSmartTransport):
235
raise bzr_errors.NotBranchError(transport.base)
240
class RemoteGitControlDirFormat(GitControlDirFormat):
181
241
"""The .git directory control format."""
184
244
def _known_formats(self):
185
return set([RemoteGitBzrDirFormat()])
245
return set([RemoteGitControlDirFormat()])
187
247
def open(self, transport, _found=None):
188
248
"""Open this directory.
206
265
def probe_transport(klass, transport):
207
266
"""Our format is present if the transport ends in '.not/'."""
209
if url.startswith('readonly+'):
210
url = url[len('readonly+'):]
211
if (not url.startswith("git://") and
212
not url.startswith("git+")):
213
raise bzr_errors.NotBranchError(transport.base)
214
# little ugly, but works
216
from bzrlib.plugins.git.remote import GitSmartTransport
217
if not isinstance(transport, GitSmartTransport):
218
raise bzr_errors.NotBranchError(transport.base)
267
prober = RemoteGitProber()
268
return prober.probe_transport(transport)
221
270
def get_format_description(self):
222
271
return "Remote Git Repository"
228
277
raise bzr_errors.UninitializableFormat(self)
231
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
232
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
281
ControlDirFormat.register_format(LocalGitControlDirFormat)
282
ControlDirFormat.register_format(RemoteGitControlDirFormat)
283
ControlDirFormat.register_prober(LocalGitProber)
284
ControlDirFormat.register_prober(RemoteGitProber)
286
ControlDirFormat.register_control_format(LocalGitControlDirFormat)
287
ControlDirFormat.register_control_format(RemoteGitControlDirFormat)
234
register_transport_proto('git://',
289
register_transport_proto('git://',
235
290
help="Access using the Git smart server protocol.")
236
register_transport_proto('git+ssh://',
291
register_transport_proto('git+ssh://',
237
292
help="Access using the Git smart server protocol over SSH.")
239
294
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
241
296
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
242
297
'SSHGitSmartTransport')
244
foreign_vcs_registry.register_lazy("git",
299
foreign_vcs_registry.register_lazy("git",
245
300
"bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
247
302
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
248
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
303
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
249
304
"bzrlib.plugins.git.commands")
305
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
306
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
251
308
def update_stanza(rev, stanza):
252
309
mapping = getattr(rev, "mapping", None)
259
316
rio_hooks.install_named_hook('revision', update_stanza, None)
263
from bzrlib.transport import transport_server_registry
267
transport_server_registry.register_lazy('git',
268
'bzrlib.plugins.git.server',
270
'Git Smart server protocol over TCP. (default port: 9418)')
273
from bzrlib.repository import network_format_registry as repository_network_format_registry
274
repository_network_format_registry.register_lazy('git',
319
from bzrlib.transport import transport_server_registry
320
transport_server_registry.register_lazy('git',
321
'bzrlib.plugins.git.server',
323
'Git Smart server protocol over TCP. (default port: 9418)')
326
from bzrlib.repository import (
327
network_format_registry as repository_network_format_registry,
329
repository_network_format_registry.register_lazy('git',
275
330
'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
277
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
278
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
281
def get_rich_root_format(stacked=False):
283
return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
285
return bzrdir.format_registry.make_bzrdir("default-rich-root")
332
from bzrlib.bzrdir import (
333
network_format_registry as bzrdir_network_format_registry,
335
bzrdir_network_format_registry.register('git', GitControlDirFormat)
337
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
338
'send_git', 'Git am-style diff format')
340
topic_registry.register_lazy('git',
341
'bzrlib.plugins.git.help',
342
'help_git', 'Using Bazaar with Git')
345
from bzrlib.diff import format_registry as diff_format_registry
349
diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
350
'GitDiffTree', 'Git am-style diff format')
287
352
def test_suite():
288
353
from bzrlib.plugins.git import tests