45
45
from bzrlib import (
47
46
errors as bzr_errors,
50
from bzrlib.controldir import (
58
from bzrlib.bzrdir import (
64
ControlDirFormat = BzrDirFormat
66
has_controldir = False
50
70
from bzrlib.foreign import (
51
71
foreign_vcs_registry,
73
from bzrlib.help_topics import (
53
76
from bzrlib.lockable_files import (
73
96
sys.path.append(os.path.normpath(
74
97
os.path.join(os.path.dirname(__file__), '_lib')))
76
_versions_checked = False
77
def lazy_check_versions():
78
global _versions_checked
81
_versions_checked = True
100
def import_dulwich():
83
102
from dulwich import __version__ as dulwich_version
84
103
except ImportError:
90
109
"bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
91
110
dulwich_minimum_version)
93
bzrdir.format_registry.register_lazy('git',
94
"bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
95
help='GIT repository.', native=False, experimental=True,
113
_versions_checked = False
114
def lazy_check_versions():
115
global _versions_checked
116
if _versions_checked:
119
_versions_checked = True
121
format_registry.register_lazy('git',
122
"bzrlib.plugins.git.dir", "LocalGitControlDirFormat",
123
help='GIT repository.', native=False, experimental=False,
98
126
from bzrlib.revisionspec import revspec_registry
108
136
dwim_revspecs.append(RevisionSpec_git)
111
class GitBzrDirFormat(bzrdir.BzrDirFormat):
139
class GitControlDirFormat(ControlDirFormat):
113
141
_lock_class = TransportLock
115
143
colocated_branches = True
145
def __eq__(self, other):
146
return type(self) == type(other)
117
148
def is_supported(self):
124
class LocalGitBzrDirFormat(GitBzrDirFormat):
125
"""The .git directory control format."""
128
def _known_formats(self):
129
return set([LocalGitBzrDirFormat()])
131
def open(self, transport, _found=None):
132
"""Open this directory.
135
lazy_check_versions()
136
# we dont grok readonly - git isn't integrated with transport.
137
from bzrlib.transport.local import LocalTransport
138
if isinstance(transport, LocalTransport):
140
path = transport.local_abspath(".").encode(osutils._fs_enc)
141
gitrepo = dulwich.repo.Repo(path)
143
from bzrlib.plugins.git.transportgit import TransportRepo
144
gitrepo = TransportRepo(transport)
145
from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
146
lockfiles = GitLockableFiles(transport, GitLock())
147
return LocalGitDir(transport, lockfiles, gitrepo, self)
150
def probe_transport(klass, transport):
155
class LocalGitProber(Prober):
157
def probe_transport(self, transport):
152
159
if not transport.has_any(['info/refs', '.git/branches',
167
174
raise bzr_errors.NotBranchError(path=transport.base)
168
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)
170
201
def get_format_description(self):
171
202
return "Local Git Repository"
192
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):
193
241
"""The .git directory control format."""
243
supports_workingtrees = False
196
246
def _known_formats(self):
197
return set([RemoteGitBzrDirFormat()])
247
return set([RemoteGitControlDirFormat()])
199
249
def open(self, transport, _found=None):
200
250
"""Open this directory.
217
267
def probe_transport(klass, transport):
218
268
"""Our format is present if the transport ends in '.not/'."""
220
if url.startswith('readonly+'):
221
url = url[len('readonly+'):]
222
if (not url.startswith("git://") and not url.startswith("git+")):
223
raise bzr_errors.NotBranchError(transport.base)
224
# little ugly, but works
226
from bzrlib.plugins.git.remote import GitSmartTransport
227
if not isinstance(transport, GitSmartTransport):
228
raise bzr_errors.NotBranchError(transport.base)
269
prober = RemoteGitProber()
270
return prober.probe_transport(transport)
231
272
def get_format_description(self):
232
273
return "Remote Git Repository"
238
279
raise bzr_errors.UninitializableFormat(self)
241
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
242
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
283
ControlDirFormat.register_format(LocalGitControlDirFormat())
284
ControlDirFormat.register_format(RemoteGitControlDirFormat())
285
ControlDirFormat.register_prober(LocalGitProber)
286
ControlDirFormat.register_prober(RemoteGitProber)
288
ControlDirFormat.register_control_format(LocalGitControlDirFormat)
289
ControlDirFormat.register_control_format(RemoteGitControlDirFormat)
244
291
register_transport_proto('git://',
245
292
help="Access using the Git smart server protocol.")
284
331
repository_network_format_registry.register_lazy('git',
285
332
'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
287
from bzrlib.bzrdir import (
288
network_format_registry as bzrdir_network_format_registry,
290
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
335
from bzrlib.controldir import (
336
network_format_registry as controldir_network_format_registry,
339
from bzrlib.bzrdir import (
340
network_format_registry as controldir_network_format_registry,
342
controldir_network_format_registry.register('git', GitControlDirFormat)
292
344
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
293
345
'send_git', 'Git am-style diff format')
347
topic_registry.register_lazy('git',
348
'bzrlib.plugins.git.help',
349
'help_git', 'Using Bazaar with Git')
296
352
from bzrlib.diff import format_registry as diff_format_registry
297
353
except ImportError: