83
85
_versions_checked = True
85
format_registry.register_lazy('git',
86
__name__ + ".dir", "LocalGitControlDirFormat",
87
help='GIT repository.', native=False, experimental=False,
90
format_registry.register_lazy('git-bare',
91
__name__ + ".dir", "BareLocalGitControlDirFormat",
88
format_registry.register_lazy(
89
'git', __name__ + ".dir", "LocalGitControlDirFormat",
90
help='GIT repository.', native=False, experimental=False)
92
format_registry.register_lazy(
93
'git-bare', __name__ + ".dir", "BareLocalGitControlDirFormat",
92
94
help='Bare GIT repository (no working tree).', native=False,
96
97
from ..revisionspec import (RevisionSpec_dwim, revspec_registry)
97
98
revspec_registry.register_lazy("git:", __name__ + ".revspec",
99
100
RevisionSpec_dwim.append_possible_lazy_revspec(
100
101
__name__ + ".revspec", "RevisionSpec_git")
105
106
def probe_transport(self, transport):
107
108
external_url = transport.external_url()
108
except bzr_errors.InProcessTransport:
109
raise bzr_errors.NotBranchError(path=transport.base)
109
except brz_errors.InProcessTransport:
110
raise brz_errors.NotBranchError(path=transport.base)
110
111
if (external_url.startswith("http:") or
111
external_url.startswith("https:")):
112
external_url.startswith("https:")):
112
113
# Already handled by RemoteGitProber
113
raise bzr_errors.NotBranchError(path=transport.base)
114
raise brz_errors.NotBranchError(path=transport.base)
114
115
from .. import urlutils
115
116
if urlutils.split(transport.base)[1] == ".git":
116
raise bzr_errors.NotBranchError(path=transport.base)
117
raise brz_errors.NotBranchError(path=transport.base)
117
118
if not transport.has_any(['objects', '.git/objects', '.git']):
118
raise bzr_errors.NotBranchError(path=transport.base)
119
raise brz_errors.NotBranchError(path=transport.base)
119
120
lazy_check_versions()
120
121
from .dir import (
121
122
BareLocalGitControlDirFormat,
144
145
class RemoteGitProber(Prober):
146
147
def probe_http_transport(self, transport):
148
# This function intentionally doesn't use any of the support code under
149
# breezy.git, since it's called for every repository that's
150
# accessed over HTTP, whether it's Git, Bzr or something else.
151
# Importing Dulwich and the other support code adds unnecessray slowdowns.
147
152
from .. import urlutils
148
base_url, _ = urlutils.split_segment_parameters(transport.external_url())
149
url = urlutils.join(base_url, "info/refs") + "?service=git-upload-pack"
150
from ..transport.http import Request
153
base_url, _ = urlutils.split_segment_parameters(
154
transport.external_url())
155
url = urlutils.URL.from_string(base_url)
156
url.user = url.quoted_user = None
157
url.password = url.quoted_password = None
158
url = urlutils.join(str(url), "info/refs") + "?service=git-upload-pack"
151
159
headers = {"Content-Type": "application/x-git-upload-pack-request",
152
160
"Accept": "application/x-git-upload-pack-result",
154
req = Request('GET', url, accepted_errors=[200, 403, 404, 405],
156
(scheme, user, password, host, port, path) = urlutils.parse_url(req.get_full_url())
162
(scheme, user, password, host, port,
163
path) = urlutils.parse_url(url)
157
164
if host == "github.com":
158
# GitHub requires we lie. https://github.com/dulwich/dulwich/issues/562
165
# GitHub requires we lie.
166
# https://github.com/dulwich/dulwich/issues/562
159
167
req.add_header("User-Agent", user_agent_for_github())
160
168
elif host == "bazaar.launchpad.net":
161
169
# Don't attempt Git probes against bazaar.launchpad.net; pad.lv/1744830
162
raise bzr_errors.NotBranchError(transport.base)
163
resp = transport._perform(req)
164
if resp.code in (404, 405):
165
raise bzr_errors.NotBranchError(transport.base)
170
raise brz_errors.NotBranchError(transport.base)
171
resp = transport.request('GET', url, headers=headers)
172
if resp.status in (404, 405):
173
raise brz_errors.NotBranchError(transport.base)
175
raise errors.InvalidHttpResponse(
176
url, 'Unable to handle http code %d' % resp.status)
166
178
headers = resp.headers
167
179
ct = headers.get("Content-Type")
169
raise bzr_errors.NotBranchError(transport.base)
181
raise brz_errors.NotBranchError(transport.base)
170
182
if ct.startswith("application/x-git"):
171
183
from .remote import RemoteGitControlDirFormat
172
184
return RemoteGitControlDirFormat()
243
257
if rev.mapping.vcs == foreign_vcs_git:
244
258
return foreign_revid
246
raise bzr_errors.InvalidRevisionId(rev.revision_id, None)
260
raise brz_errors.InvalidRevisionId(rev.revision_id, None)
249
263
def update_stanza(rev, stanza):
250
mapping = getattr(rev, "mapping", None)
252
265
git_commit = extract_git_foreign_revid(rev)
253
except bzr_errors.InvalidRevisionId:
266
except brz_errors.InvalidRevisionId:
256
269
stanza.add("git-commit", git_commit)
258
272
from ..hooks import install_lazy_named_hook
259
install_lazy_named_hook("breezy.version_info_formats.format_rio",
273
install_lazy_named_hook(
274
"breezy.version_info_formats.format_rio",
260
275
"RioVersionInfoBuilder.hooks", "revision", update_stanza,
264
transport_server_registry.register_lazy('git',
265
__name__ + '.server',
278
transport_server_registry.register_lazy(
279
'git', __name__ + '.server', 'serve_git',
267
280
'Git Smart server protocol over TCP. (default port: 9418)')
269
transport_server_registry.register_lazy('git-receive-pack',
270
__name__ + '.server',
282
transport_server_registry.register_lazy(
283
'git-receive-pack', __name__ + '.server',
271
284
'serve_git_receive_pack',
272
285
help='Git Smart server receive pack command. (inetd mode only)')
273
transport_server_registry.register_lazy('git-upload-pack',
274
__name__ + 'git.server',
286
transport_server_registry.register_lazy(
287
'git-upload-pack', __name__ + 'git.server',
275
288
'serve_git_upload_pack',
276
289
help='Git Smart server upload pack command. (inetd mode only)')
279
292
format_registry as repository_format_registry,
280
293
network_format_registry as repository_network_format_registry,
282
repository_network_format_registry.register_lazy(b'git',
283
__name__ + '.repository', 'GitRepositoryFormat')
295
repository_network_format_registry.register_lazy(
296
b'git', __name__ + '.repository', 'GitRepositoryFormat')
285
298
register_extra_lazy_repository_format = getattr(repository_format_registry,
286
"register_extra_lazy")
299
"register_extra_lazy")
287
300
register_extra_lazy_repository_format(__name__ + '.repository',
288
'GitRepositoryFormat')
301
'GitRepositoryFormat')
290
303
from ..branch import (
291
304
network_format_registry as branch_network_format_registry,
293
branch_network_format_registry.register_lazy(b'git',
294
__name__ + '.branch', 'LocalGitBranchFormat')
306
branch_network_format_registry.register_lazy(
307
b'git', __name__ + '.branch', 'LocalGitBranchFormat')
297
310
from ..branch import (
315
328
'GitWorkingTreeFormat',
318
controldir_network_format_registry.register_lazy(b'git',
319
__name__ + ".dir", "GitControlDirFormat")
323
from ..registry import register_lazy
325
from ..diff import format_registry as diff_format_registry
326
diff_format_registry.register_lazy('git', __name__ + '.send',
327
'GitDiffTree', 'Git am-style diff format')
330
format_registry as send_format_registry,
332
send_format_registry.register_lazy('git', __name__ + '.send',
333
'send_git', 'Git am-style diff format')
335
from ..directory_service import directories
336
directories.register_lazy('github:', __name__ + '.directory',
339
directories.register_lazy('git@github.com:', __name__ + '.directory',
343
from ..help_topics import (
346
topic_registry.register_lazy('git', __name__ + '.help', 'help_git',
347
'Using Bazaar with Git')
349
from ..foreign import (
350
foreign_vcs_registry,
352
foreign_vcs_registry.register_lazy("git",
353
__name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
355
register_lazy("breezy.diff", "format_registry",
356
'git', __name__ + '.send', 'GitDiffTree',
357
'Git am-style diff format')
358
register_lazy("breezy.send", "format_registry",
359
'git', __name__ + '.send', 'send_git',
360
'Git am-style diff format')
361
register_lazy('breezy.directory_service', 'directories', 'github:',
362
__name__ + '.directory', 'GitHubDirectory',
364
register_lazy('breezy.directory_service', 'directories',
365
'git@github.com:', __name__ + '.directory',
366
'GitHubDirectory', 'GitHub directory.')
367
register_lazy('breezy.help_topics', 'topic_registry',
368
'git', __name__ + '.help', 'help_git',
369
'Using Bazaar with Git')
370
register_lazy('breezy.foreign', 'foreign_vcs_registry', "git",
371
__name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
331
controldir_network_format_registry.register_lazy(
332
b'git', __name__ + ".dir", "GitControlDirFormat")
335
from ..diff import format_registry as diff_format_registry
336
diff_format_registry.register_lazy(
337
'git', __name__ + '.send',
338
'GitDiffTree', 'Git am-style diff format')
341
format_registry as send_format_registry,
343
send_format_registry.register_lazy('git', __name__ + '.send',
344
'send_git', 'Git am-style diff format')
346
from ..directory_service import directories
347
directories.register_lazy('github:', __name__ + '.directory',
350
directories.register_lazy('git@github.com:', __name__ + '.directory',
354
from ..help_topics import (
357
topic_registry.register_lazy(
358
'git', __name__ + '.help', 'help_git', 'Using Bazaar with Git')
360
from ..foreign import (
361
foreign_vcs_registry,
363
foreign_vcs_registry.register_lazy(
364
"git", __name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
373
367
def update_git_cache(repository, revid):
374
368
"""Update the git cache after a local commit."""
375
369
if getattr(repository, "_git", None) is not None:
376
return # No need to update cache for git repositories
370
return # No need to update cache for git repositories
378
372
if not repository.control_transport.has("git"):
379
return # No existing cache, don't bother updating
373
return # No existing cache, don't bother updating
381
375
lazy_check_versions()
382
except bzr_errors.DependencyNotPresent as e:
376
except brz_errors.DependencyNotPresent as e:
383
377
# dulwich is probably missing. silently ignore
384
378
trace.mutter("not updating git map for %r: %s",
387
381
from .object_store import BazaarObjectStore
388
382
store = BazaarObjectStore(repository)
420
415
from .server import git_http_hook
421
416
return git_http_hook(branch, environ['REQUEST_METHOD'],
422
environ['PATH_INFO'])
417
environ['PATH_INFO'])
424
420
install_lazy_named_hook("breezy.branch",
425
"Branch.hooks", "post_commit", post_commit_update_cache,
421
"Branch.hooks", "post_commit",
422
post_commit_update_cache, "git cache")
427
423
install_lazy_named_hook("breezy.plugins.loggerhead.apps.branch",
428
"BranchWSGIApp.hooks", "controller",
429
loggerhead_git_hook, "git support")
424
"BranchWSGIApp.hooks", "controller",
425
loggerhead_git_hook, "git support")
432
428
from ..config import (