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(
74
os.path.join(os.path.dirname(__file__), '_lib')))
73
sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
76
75
_versions_checked = False
77
76
def lazy_check_versions():
83
82
from dulwich import __version__ as dulwich_version
84
83
except ImportError:
85
raise bzr_errors.DependencyNotPresent("dulwich",
86
"bzr-git: Please install dulwich, https://launchpad.net/dulwich")
84
raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
88
86
if dulwich_version < dulwich_minimum_version:
89
raise bzr_errors.DependencyNotPresent("dulwich",
90
"bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
91
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)
93
bzrdir.format_registry.register_lazy('git',
89
bzrdir.format_registry.register_lazy('git',
94
90
"bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
95
91
help='GIT repository.', native=False, experimental=True,
98
94
from bzrlib.revisionspec import revspec_registry
99
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
95
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
100
96
"RevisionSpec_git")
103
from bzrlib.revisionspec import dwim_revspecs
107
from bzrlib.plugins.git.revspec import RevisionSpec_git
108
dwim_revspecs.append(RevisionSpec_git)
111
99
class GitBzrDirFormat(bzrdir.BzrDirFormat):
113
100
_lock_class = TransportLock
115
colocated_branches = True
117
102
def is_supported(self):
132
117
"""Open this directory.
135
lazy_check_versions()
136
from bzrlib.plugins.git.transportgit import TransportRepo
137
gitrepo = TransportRepo(transport)
121
# we dont grok readonly - git isn't integrated with transport.
123
if url.startswith('readonly+'):
124
url = url[len('readonly+'):]
127
gitrepo = dulwich.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
128
except bzr_errors.NotLocalUrl:
129
raise bzr_errors.NotBranchError(path=transport.base)
138
130
from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
139
131
lockfiles = GitLockableFiles(transport, GitLock())
140
132
return LocalGitDir(transport, lockfiles, gitrepo, self)
143
135
def probe_transport(klass, transport):
145
if not transport.has_any(['info/refs', '.git/branches',
147
raise bzr_errors.NotBranchError(path=transport.base)
148
except bzr_errors.NoSuchFile:
149
raise bzr_errors.NotBranchError(path=transport.base)
150
from bzrlib import urlutils
151
if urlutils.split(transport.base)[1] == ".git":
152
raise bzr_errors.NotBranchError(path=transport.base)
153
lazy_check_versions()
136
"""Our format is present if the transport ends in '.not/'."""
137
from bzrlib.transport.local import LocalTransport
139
if not isinstance(transport, LocalTransport):
140
raise bzr_errors.NotBranchError(path=transport.base)
142
# This should quickly filter out most things that are not
143
# git repositories, saving us the trouble from loading dulwich.
144
if not transport.has(".git") and not transport.has("objects"):
145
raise bzr_errors.NotBranchError(path=transport.base)
170
163
from bzrlib.transport.local import LocalTransport
172
165
if not isinstance(transport, LocalTransport):
173
raise NotImplementedError(self.initialize,
166
raise NotImplementedError(self.initialize,
174
167
"Can't create Git Repositories/branches on "
175
168
"non-local transports")
176
lazy_check_versions()
177
170
from dulwich.repo import Repo
178
Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
171
Repo.create(transport.local_abspath(".").encode(osutils._fs_enc))
179
172
return self.open(transport)
181
174
def is_supported(self):
197
190
url = transport.base
198
191
if url.startswith('readonly+'):
199
192
url = url[len('readonly+'):]
200
if (not url.startswith("git://") and not url.startswith("git+")):
193
if (not url.startswith("git://") and
194
not url.startswith("git+")):
201
195
raise bzr_errors.NotBranchError(transport.base)
202
196
from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
203
197
if not isinstance(transport, GitSmartTransport):
212
206
url = transport.base
213
207
if url.startswith('readonly+'):
214
208
url = url[len('readonly+'):]
215
if (not url.startswith("git://") and not url.startswith("git+")):
209
if (not url.startswith("git://") and
210
not url.startswith("git+")):
216
211
raise bzr_errors.NotBranchError(transport.base)
217
212
# little ugly, but works
234
229
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
235
230
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
237
register_transport_proto('git://',
232
register_transport_proto('git://',
238
233
help="Access using the Git smart server protocol.")
239
register_transport_proto('git+ssh://',
234
register_transport_proto('git+ssh://',
240
235
help="Access using the Git smart server protocol over SSH.")
242
237
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
244
239
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
245
240
'SSHGitSmartTransport')
247
foreign_vcs_registry.register_lazy("git",
242
foreign_vcs_registry.register_lazy("git",
248
243
"bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
250
245
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
251
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
246
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
252
247
"bzrlib.plugins.git.commands")
253
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
254
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
256
249
def update_stanza(rev, stanza):
257
250
mapping = getattr(rev, "mapping", None)
267
260
from bzrlib.transport import transport_server_registry
268
261
transport_server_registry.register_lazy('git',
269
'bzrlib.plugins.git.server',
262
'bzrlib.plugins.git.server',
271
264
'Git Smart server protocol over TCP. (default port: 9418)')
274
from bzrlib.repository import (
275
network_format_registry as repository_network_format_registry,
277
repository_network_format_registry.register_lazy('git',
267
from bzrlib.repository import network_format_registry as repository_network_format_registry
268
repository_network_format_registry.register_lazy('git',
278
269
'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
280
from bzrlib.bzrdir import (
281
network_format_registry as bzrdir_network_format_registry,
271
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
283
272
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
275
def get_rich_root_format(stacked=False):
277
return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
279
return bzrdir.format_registry.make_bzrdir("default-rich-root")
285
281
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
286
282
'send_git', 'Git am-style diff format')
289
from bzrlib.diff import format_registry as diff_format_registry
293
diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
294
'GitDiffTree', 'Git am-style diff format')
296
284
def test_suite():
297
285
from bzrlib.plugins.git import tests
298
286
return tests.test_suite()