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)
50
from bzrlib.foreign import (
53
from bzrlib.lockable_files import (
56
from bzrlib.transport import (
57
register_lazy_transport,
58
register_transport_proto,
60
from bzrlib.commands import (
63
from bzrlib.version_info_formats.format_rio import (
64
RioVersionInfoBuilder,
66
from bzrlib.send import (
67
format_registry as send_format_registry,
29
from bzrlib import bzrdir, errors as bzr_errors
30
from bzrlib.foreign import foreign_vcs_registry
31
from bzrlib.lockable_files import TransportLock
32
from bzrlib.transport import register_lazy_transport
33
from bzrlib.commands import plugin_cmds
34
from bzrlib.trace import warning
36
MINIMUM_DULWICH_VERSION = (0, 1, 0)
37
COMPATIBLE_BZR_VERSIONS = [(1, 11, 0), (1, 12, 0)]
71
39
if getattr(sys, "frozen", None):
72
40
# allow import additional libs from ./_lib for bzr.exe only
82
50
from dulwich import __version__ as dulwich_version
83
51
except ImportError:
84
raise bzr_errors.DependencyNotPresent("dulwich",
85
"bzr-git: Please install dulwich, https://launchpad.net/dulwich")
52
raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
87
if dulwich_version < dulwich_minimum_version:
88
raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Dulwich is too old; at least %d.%d.%d is required" % dulwich_minimum_version)
90
bzrdir.format_registry.register_lazy('git',
54
if dulwich_version < MINIMUM_DULWICH_VERSION:
55
raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
57
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
59
bzrdir.format_registry.register_lazy('git',
91
60
"bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
92
61
help='GIT repository.', native=False, experimental=True,
95
from bzrlib.revisionspec import revspec_registry
96
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
100
from bzrlib.revisionspec import dwim_revspecs
65
from bzrlib.revisionspec import revspec_registry
66
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
101
68
except ImportError:
70
from bzrlib.revisionspec import SPEC_TYPES
104
71
from bzrlib.plugins.git.revspec import RevisionSpec_git
105
dwim_revspecs.append(RevisionSpec_git)
72
SPEC_TYPES.append(RevisionSpec_git)
108
74
class GitBzrDirFormat(bzrdir.BzrDirFormat):
110
75
_lock_class = TransportLock
112
77
def is_supported(self):
115
def network_name(self):
119
81
class LocalGitBzrDirFormat(GitBzrDirFormat):
120
82
"""The .git directory control format."""
127
89
"""Open this directory.
130
lazy_check_versions()
131
93
# we dont grok readonly - git isn't integrated with transport.
132
from bzrlib.transport.local import LocalTransport
133
if isinstance(transport, LocalTransport):
135
gitrepo = dulwich.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
137
from bzrlib.plugins.git.transportgit import TransportRepo
138
gitrepo = TransportRepo(transport)
95
if url.startswith('readonly+'):
96
url = url[len('readonly+'):]
99
gitrepo = git.repo.Repo(transport.local_abspath("."))
100
except bzr_errors.NotLocalUrl:
101
raise bzr_errors.NotBranchError(path=transport.base)
139
102
from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
140
103
lockfiles = GitLockableFiles(transport, GitLock())
141
104
return LocalGitDir(transport, lockfiles, gitrepo, self)
144
107
def probe_transport(klass, transport):
146
if not (transport.has('info/refs') or
147
transport.has('.git/branches') or
148
transport.has('branches')):
149
raise bzr_errors.NotBranchError(path=transport.base)
150
except bzr_errors.NoSuchFile:
151
raise bzr_errors.NotBranchError(path=transport.base)
152
from bzrlib import urlutils
153
if urlutils.split(transport.base)[1] == ".git":
154
raise bzr_errors.NotBranchError(path=transport.base)
155
lazy_check_versions()
108
"""Our format is present if the transport ends in '.not/'."""
109
from bzrlib.transport.local import LocalTransport
111
if not isinstance(transport, LocalTransport):
112
raise bzr_errors.NotBranchError(path=transport.base)
114
# This should quickly filter out most things that are not
115
# git repositories, saving us the trouble from loading dulwich.
116
if not transport.has(".git") and not transport.has("objects"):
117
raise bzr_errors.NotBranchError(path=transport.base)
119
import dulwich as git
159
122
format.open(transport)
161
except dulwich.errors.NotGitRepository, e:
124
except git.errors.NotGitRepository, e:
162
125
raise bzr_errors.NotBranchError(path=transport.base)
163
126
raise bzr_errors.NotBranchError(path=transport.base)
172
135
from bzrlib.transport.local import LocalTransport
174
137
if not isinstance(transport, LocalTransport):
175
raise NotImplementedError(self.initialize,
138
raise NotImplementedError(self.initialize,
176
139
"Can't create Git Repositories/branches on "
177
140
"non-local transports")
178
lazy_check_versions()
179
142
from dulwich.repo import Repo
180
Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
143
Repo.create(transport.local_abspath("."))
181
144
return self.open(transport)
183
146
def is_supported(self):
195
158
"""Open this directory.
198
# we dont grok readonly - git isn't integrated with transport.
200
if url.startswith('readonly+'):
201
url = url[len('readonly+'):]
202
if (not url.startswith("git://") and not url.startswith("git+")):
203
raise bzr_errors.NotBranchError(transport.base)
204
161
from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
205
162
if not isinstance(transport, GitSmartTransport):
206
163
raise bzr_errors.NotBranchError(transport.base)
164
# we dont grok readonly - git isn't integrated with transport.
166
if url.startswith('readonly+'):
167
url = url[len('readonly+'):]
207
169
from bzrlib.plugins.git.dir import GitLockableFiles, GitLock
208
170
lockfiles = GitLockableFiles(transport, GitLock())
209
171
return RemoteGitDir(transport, lockfiles, self)
212
174
def probe_transport(klass, transport):
213
175
"""Our format is present if the transport ends in '.not/'."""
215
if url.startswith('readonly+'):
216
url = url[len('readonly+'):]
217
if (not url.startswith("git://") and not url.startswith("git+")):
218
raise bzr_errors.NotBranchError(transport.base)
219
176
# little ugly, but works
221
178
from bzrlib.plugins.git.remote import GitSmartTransport
222
179
if not isinstance(transport, GitSmartTransport):
223
180
raise bzr_errors.NotBranchError(transport.base)
181
# The only way to know a path exists and contains a valid repository
182
# is to do a request against it:
184
transport.fetch_pack(lambda x: [], None, lambda x: None,
185
lambda x: mutter("git: %s" % x))
186
except errors.git_errors.GitProtocolError:
187
raise bzr_errors.NotBranchError(path=transport.base)
190
raise bzr_errors.NotBranchError(path=transport.base)
226
192
def get_format_description(self):
227
193
return "Remote Git Repository"
236
202
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
237
203
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
239
register_transport_proto('git://',
240
help="Access using the Git smart server protocol.")
241
register_transport_proto('git+ssh://',
242
help="Access using the Git smart server protocol over SSH.")
244
205
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
245
'TCPGitSmartTransport')
246
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
247
'SSHGitSmartTransport')
249
foreign_vcs_registry.register_lazy("git",
250
"bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
208
foreign_vcs_registry.register_lazy("git",
209
"bzrlib.plugins.git.mapping",
211
"Stupid content tracker")
213
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
252
214
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
253
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
254
"bzrlib.plugins.git.commands")
256
def update_stanza(rev, stanza):
257
mapping = getattr(rev, "mapping", None)
258
if mapping is not None and mapping.revid_prefix.startswith("git-"):
259
stanza.add("git-commit", rev.foreign_revid)
262
rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
263
if rio_hooks is not None:
264
rio_hooks.install_named_hook('revision', update_stanza, None)
267
from bzrlib.transport import transport_server_registry
268
transport_server_registry.register_lazy('git',
269
'bzrlib.plugins.git.server',
271
'Git Smart server protocol over TCP. (default port: 9418)')
274
from bzrlib.repository import network_format_registry as repository_network_format_registry
275
repository_network_format_registry.register_lazy('git',
276
'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
278
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
279
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
282
def get_rich_root_format(stacked=False):
284
return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
286
return bzrdir.format_registry.make_bzrdir("default-rich-root")
288
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
289
'send_git', 'Git am-style diff format')
291
216
def test_suite():
292
217
from bzrlib.plugins.git import tests