71
71
if getattr(sys, "frozen", None):
72
72
# allow import additional libs from ./_lib for bzr.exe only
73
sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
73
sys.path.append(os.path.normpath(
74
os.path.join(os.path.dirname(__file__), '_lib')))
79
from dulwich import __version__ as dulwich_version
81
raise bzr_errors.DependencyNotPresent("dulwich",
82
"bzr-git: Please install dulwich, https://launchpad.net/dulwich")
84
if dulwich_version < dulwich_minimum_version:
85
raise bzr_errors.DependencyNotPresent("dulwich",
86
"bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
87
dulwich_minimum_version)
75
90
_versions_checked = False
76
91
def lazy_check_versions():
77
92
global _versions_checked
78
93
if _versions_checked:
80
96
_versions_checked = True
82
from dulwich import __version__ as dulwich_version
84
raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
86
if dulwich_version < dulwich_minimum_version:
87
raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Dulwich is too old; at least %d.%d.%d is required" % dulwich_minimum_version)
89
bzrdir.format_registry.register_lazy('git',
98
bzrdir.format_registry.register_lazy('git',
90
99
"bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
91
100
help='GIT repository.', native=False, experimental=True,
94
103
from bzrlib.revisionspec import revspec_registry
95
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
104
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
96
105
"RevisionSpec_git")
108
from bzrlib.revisionspec import dwim_revspecs
112
from bzrlib.plugins.git.revspec import RevisionSpec_git
113
dwim_revspecs.append(RevisionSpec_git)
99
116
class GitBzrDirFormat(bzrdir.BzrDirFormat):
101
118
_lock_class = TransportLock
120
colocated_branches = True
122
def __eq__(self, other):
123
return type(self) == type(other)
103
125
def is_supported(self):
121
143
lazy_check_versions()
123
# we dont grok readonly - git isn't integrated with transport.
125
if url.startswith('readonly+'):
126
url = url[len('readonly+'):]
129
gitrepo = dulwich.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
130
except bzr_errors.NotLocalUrl:
131
raise bzr_errors.NotBranchError(path=transport.base)
144
from bzrlib.plugins.git.transportgit import TransportRepo
145
gitrepo = TransportRepo(transport)
132
146
from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
133
147
lockfiles = GitLockableFiles(transport, GitLock())
134
148
return LocalGitDir(transport, lockfiles, gitrepo, self)
137
151
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)
153
if not transport.has_any(['info/refs', '.git/branches',
155
raise bzr_errors.NotBranchError(path=transport.base)
156
except bzr_errors.NoSuchFile:
157
raise bzr_errors.NotBranchError(path=transport.base)
158
from bzrlib import urlutils
159
if urlutils.split(transport.base)[1] == ".git":
160
raise bzr_errors.NotBranchError(path=transport.base)
149
161
lazy_check_versions()
166
178
from bzrlib.transport.local import LocalTransport
168
180
if not isinstance(transport, LocalTransport):
169
raise NotImplementedError(self.initialize,
181
raise NotImplementedError(self.initialize,
170
182
"Can't create Git Repositories/branches on "
171
183
"non-local transports")
173
184
lazy_check_versions()
174
185
from dulwich.repo import Repo
175
Repo.create(transport.local_abspath(".").encode(osutils._fs_enc))
186
Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
176
187
return self.open(transport)
178
189
def is_supported(self):
194
205
url = transport.base
195
206
if url.startswith('readonly+'):
196
207
url = url[len('readonly+'):]
197
if (not url.startswith("git://") and
198
not url.startswith("git+")):
208
if (not url.startswith("git://") and not url.startswith("git+")):
199
209
raise bzr_errors.NotBranchError(transport.base)
200
210
from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
201
211
if not isinstance(transport, GitSmartTransport):
210
220
url = transport.base
211
221
if url.startswith('readonly+'):
212
222
url = url[len('readonly+'):]
213
if (not url.startswith("git://") and
214
not url.startswith("git+")):
223
if (not url.startswith("git://") and not url.startswith("git+")):
215
224
raise bzr_errors.NotBranchError(transport.base)
216
225
# little ugly, but works
233
242
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
234
243
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
236
register_transport_proto('git://',
245
register_transport_proto('git://',
237
246
help="Access using the Git smart server protocol.")
238
register_transport_proto('git+ssh://',
247
register_transport_proto('git+ssh://',
239
248
help="Access using the Git smart server protocol over SSH.")
241
250
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
243
252
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
244
253
'SSHGitSmartTransport')
246
foreign_vcs_registry.register_lazy("git",
255
foreign_vcs_registry.register_lazy("git",
247
256
"bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
249
258
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
250
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
259
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
251
260
"bzrlib.plugins.git.commands")
261
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
262
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
253
264
def update_stanza(rev, stanza):
254
265
mapping = getattr(rev, "mapping", None)
264
275
from bzrlib.transport import transport_server_registry
265
276
transport_server_registry.register_lazy('git',
266
'bzrlib.plugins.git.server',
277
'bzrlib.plugins.git.server',
268
279
'Git Smart server protocol over TCP. (default port: 9418)')
271
from bzrlib.repository import network_format_registry as repository_network_format_registry
272
repository_network_format_registry.register_lazy('git',
282
from bzrlib.repository import (
283
network_format_registry as repository_network_format_registry,
285
repository_network_format_registry.register_lazy('git',
273
286
'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
275
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
288
from bzrlib.bzrdir import (
289
network_format_registry as bzrdir_network_format_registry,
276
291
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
279
def get_rich_root_format(stacked=False):
281
return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
283
return bzrdir.format_registry.make_bzrdir("default-rich-root")
285
293
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
286
294
'send_git', 'Git am-style diff format')
297
from bzrlib.diff import format_registry as diff_format_registry
301
diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
302
'GitDiffTree', 'Git am-style diff format')
288
304
def test_suite():
289
305
from bzrlib.plugins.git import tests
290
306
return tests.test_suite()