/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        from dulwich import __version__ as dulwich_version
65
65
    except ImportError:
66
66
        raise bzr_errors.DependencyNotPresent("dulwich",
67
 
            "bzr-git: Please install dulwich, https://www.dulwich.io/")
 
67
                                              "bzr-git: Please install dulwich, https://www.dulwich.io/")
68
68
    else:
69
69
        if dulwich_version < dulwich_minimum_version:
70
70
            raise bzr_errors.DependencyNotPresent("dulwich",
71
 
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
72
 
                    dulwich_minimum_version)
 
71
                                                  "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
 
72
                                                  dulwich_minimum_version)
73
73
 
74
74
 
75
75
_versions_checked = False
 
76
 
 
77
 
76
78
def lazy_check_versions():
77
79
    global _versions_checked
78
80
    if _versions_checked:
80
82
    import_dulwich()
81
83
    _versions_checked = True
82
84
 
 
85
 
83
86
format_registry.register_lazy('git',
84
 
    __name__ + ".dir", "LocalGitControlDirFormat",
85
 
    help='GIT repository.', native=False, experimental=False,
86
 
    )
 
87
                              __name__ + ".dir", "LocalGitControlDirFormat",
 
88
                              help='GIT repository.', native=False, experimental=False,
 
89
                              )
87
90
 
88
91
format_registry.register_lazy('git-bare',
89
 
    __name__ + ".dir", "BareLocalGitControlDirFormat",
90
 
    help='Bare GIT repository (no working tree).', native=False,
91
 
    experimental=False,
92
 
    )
 
92
                              __name__ + ".dir", "BareLocalGitControlDirFormat",
 
93
                              help='Bare GIT repository (no working tree).', native=False,
 
94
                              experimental=False,
 
95
                              )
93
96
 
94
97
from ..revisionspec import (RevisionSpec_dwim, revspec_registry)
95
98
revspec_registry.register_lazy("git:", __name__ + ".revspec",
96
 
    "RevisionSpec_git")
 
99
                               "RevisionSpec_git")
97
100
RevisionSpec_dwim.append_possible_lazy_revspec(
98
101
    __name__ + ".revspec", "RevisionSpec_git")
99
102
 
106
109
        except bzr_errors.InProcessTransport:
107
110
            raise bzr_errors.NotBranchError(path=transport.base)
108
111
        if (external_url.startswith("http:") or
109
 
            external_url.startswith("https:")):
 
112
                external_url.startswith("https:")):
110
113
            # Already handled by RemoteGitProber
111
114
            raise bzr_errors.NotBranchError(path=transport.base)
112
115
        from .. import urlutils
143
146
 
144
147
    def probe_http_transport(self, transport):
145
148
        from .. import urlutils
146
 
        base_url, _ = urlutils.split_segment_parameters(transport.external_url())
 
149
        base_url, _ = urlutils.split_segment_parameters(
 
150
            transport.external_url())
147
151
        url = urlutils.join(base_url, "info/refs") + "?service=git-upload-pack"
148
152
        from ..transport.http import Request
149
153
        headers = {"Content-Type": "application/x-git-upload-pack-request",
151
155
                   }
152
156
        req = Request('GET', url, accepted_errors=[200, 403, 404, 405],
153
157
                      headers=headers)
154
 
        (scheme, user, password, host, port, path) = urlutils.parse_url(req.get_full_url())
 
158
        (scheme, user, password, host, port,
 
159
         path) = urlutils.parse_url(req.get_full_url())
155
160
        if host == "github.com":
156
161
            # GitHub requires we lie. https://github.com/dulwich/dulwich/issues/562
157
162
            req.add_header("User-Agent", user_agent_for_github())
183
188
            raise bzr_errors.NotBranchError(path=transport.base)
184
189
 
185
190
        if (external_url.startswith("http:") or
186
 
            external_url.startswith("https:")):
 
191
                external_url.startswith("https:")):
187
192
            return self.probe_http_transport(transport)
188
193
 
189
194
        if (not external_url.startswith("git://") and
190
 
            not external_url.startswith("git+")):
 
195
                not external_url.startswith("git+")):
191
196
            raise bzr_errors.NotBranchError(transport.base)
192
197
 
193
198
        # little ugly, but works
209
214
ControlDirFormat._server_probers.append(RemoteGitProber)
210
215
 
211
216
register_transport_proto('git://',
212
 
        help="Access using the Git smart server protocol.")
 
217
                         help="Access using the Git smart server protocol.")
213
218
register_transport_proto('git+ssh://',
214
 
        help="Access using the Git smart server protocol over SSH.")
 
219
                         help="Access using the Git smart server protocol over SSH.")
215
220
 
216
221
register_lazy_transport("git://", __name__ + '.remote',
217
222
                        'TCPGitSmartTransport')
221
226
 
222
227
plugin_cmds.register_lazy("cmd_git_import", [], __name__ + ".commands")
223
228
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
224
 
    __name__ + ".commands")
 
229
                          __name__ + ".commands")
225
230
plugin_cmds.register_lazy("cmd_git_refs", [], __name__ + ".commands")
226
231
plugin_cmds.register_lazy("cmd_git_apply", [], __name__ + ".commands")
227
232
plugin_cmds.register_lazy("cmd_git_push_pristine_tar_deltas",
228
 
        ['git-push-pristine-tar', 'git-push-pristine'],
229
 
    __name__ + ".commands")
 
233
                          ['git-push-pristine-tar', 'git-push-pristine'],
 
234
                          __name__ + ".commands")
 
235
 
230
236
 
231
237
def extract_git_foreign_revid(rev):
232
238
    try:
253
259
    else:
254
260
        stanza.add("git-commit", git_commit)
255
261
 
 
262
 
256
263
from ..hooks import install_lazy_named_hook
257
264
install_lazy_named_hook("breezy.version_info_formats.format_rio",
258
 
    "RioVersionInfoBuilder.hooks", "revision", update_stanza,
259
 
    "git commits")
 
265
                        "RioVersionInfoBuilder.hooks", "revision", update_stanza,
 
266
                        "git commits")
260
267
 
261
268
 
262
269
transport_server_registry.register_lazy('git',
263
 
    __name__ + '.server',
264
 
    'serve_git',
265
 
    'Git Smart server protocol over TCP. (default port: 9418)')
 
270
                                        __name__ + '.server',
 
271
                                        'serve_git',
 
272
                                        'Git Smart server protocol over TCP. (default port: 9418)')
266
273
 
267
274
transport_server_registry.register_lazy('git-receive-pack',
268
 
    __name__ + '.server',
269
 
    'serve_git_receive_pack',
270
 
    help='Git Smart server receive pack command. (inetd mode only)')
 
275
                                        __name__ + '.server',
 
276
                                        'serve_git_receive_pack',
 
277
                                        help='Git Smart server receive pack command. (inetd mode only)')
271
278
transport_server_registry.register_lazy('git-upload-pack',
272
 
    __name__ + 'git.server',
273
 
    'serve_git_upload_pack',
274
 
    help='Git Smart server upload pack command. (inetd mode only)')
 
279
                                        __name__ + 'git.server',
 
280
                                        'serve_git_upload_pack',
 
281
                                        help='Git Smart server upload pack command. (inetd mode only)')
275
282
 
276
283
from ..repository import (
277
284
    format_registry as repository_format_registry,
278
285
    network_format_registry as repository_network_format_registry,
279
286
    )
280
287
repository_network_format_registry.register_lazy(b'git',
281
 
    __name__ + '.repository', 'GitRepositoryFormat')
 
288
                                                 __name__ + '.repository', 'GitRepositoryFormat')
282
289
 
283
290
register_extra_lazy_repository_format = getattr(repository_format_registry,
284
 
    "register_extra_lazy")
 
291
                                                "register_extra_lazy")
285
292
register_extra_lazy_repository_format(__name__ + '.repository',
286
 
    'GitRepositoryFormat')
 
293
                                      'GitRepositoryFormat')
287
294
 
288
295
from ..branch import (
289
296
    network_format_registry as branch_network_format_registry,
290
297
    )
291
298
branch_network_format_registry.register_lazy(b'git',
292
 
    __name__ + '.branch', 'LocalGitBranchFormat')
 
299
                                             __name__ + '.branch', 'LocalGitBranchFormat')
293
300
 
294
301
 
295
302
from ..branch import (
314
321
    )
315
322
 
316
323
controldir_network_format_registry.register_lazy(b'git',
317
 
    __name__ + ".dir", "GitControlDirFormat")
 
324
                                                 __name__ + ".dir", "GitControlDirFormat")
318
325
 
319
326
 
320
327
try:
322
329
except ImportError:
323
330
    from ..diff import format_registry as diff_format_registry
324
331
    diff_format_registry.register_lazy('git', __name__ + '.send',
325
 
        'GitDiffTree', 'Git am-style diff format')
 
332
                                       'GitDiffTree', 'Git am-style diff format')
326
333
 
327
334
    from ..send import (
328
335
        format_registry as send_format_registry,
342
349
        topic_registry,
343
350
        )
344
351
    topic_registry.register_lazy('git', __name__ + '.help', 'help_git',
345
 
        'Using Bazaar with Git')
 
352
                                 'Using Bazaar with Git')
346
353
 
347
354
    from ..foreign import (
348
355
        foreign_vcs_registry,
349
356
        )
350
357
    foreign_vcs_registry.register_lazy("git",
351
 
        __name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
 
358
                                       __name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
352
359
else:
353
360
    register_lazy("breezy.diff", "format_registry",
354
 
        'git', __name__ + '.send', 'GitDiffTree',
355
 
        'Git am-style diff format')
 
361
                  'git', __name__ + '.send', 'GitDiffTree',
 
362
                  'Git am-style diff format')
356
363
    register_lazy("breezy.send", "format_registry",
357
 
        'git', __name__ + '.send', 'send_git',
358
 
        'Git am-style diff format')
 
364
                  'git', __name__ + '.send', 'send_git',
 
365
                  'Git am-style diff format')
359
366
    register_lazy('breezy.directory_service', 'directories', 'github:',
360
 
            __name__ + '.directory', 'GitHubDirectory',
361
 
            'GitHub directory.')
 
367
                  __name__ + '.directory', 'GitHubDirectory',
 
368
                  'GitHub directory.')
362
369
    register_lazy('breezy.directory_service', 'directories',
363
 
            'git@github.com:', __name__ + '.directory',
364
 
            'GitHubDirectory', 'GitHub directory.')
 
370
                  'git@github.com:', __name__ + '.directory',
 
371
                  'GitHubDirectory', 'GitHub directory.')
365
372
    register_lazy('breezy.help_topics', 'topic_registry',
366
 
            'git', __name__ + '.help', 'help_git',
367
 
            'Using Bazaar with Git')
 
373
                  'git', __name__ + '.help', 'help_git',
 
374
                  'Using Bazaar with Git')
368
375
    register_lazy('breezy.foreign', 'foreign_vcs_registry', "git",
369
 
        __name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
 
376
                  __name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
 
377
 
370
378
 
371
379
def update_git_cache(repository, revid):
372
380
    """Update the git cache after a local commit."""
373
381
    if getattr(repository, "_git", None) is not None:
374
 
        return # No need to update cache for git repositories
 
382
        return  # No need to update cache for git repositories
375
383
 
376
384
    if not repository.control_transport.has("git"):
377
 
        return # No existing cache, don't bother updating
 
385
        return  # No existing cache, don't bother updating
378
386
    try:
379
387
        lazy_check_versions()
380
388
    except bzr_errors.DependencyNotPresent as e:
381
389
        # dulwich is probably missing. silently ignore
382
390
        trace.mutter("not updating git map for %r: %s",
383
 
            repository, e)
 
391
                     repository, e)
384
392
 
385
393
    from .object_store import BazaarObjectStore
386
394
    store = BazaarObjectStore(repository)
404
412
 
405
413
 
406
414
def post_commit_update_cache(local_branch, master_branch, old_revno, old_revid,
407
 
        new_revno, new_revid):
 
415
                             new_revno, new_revid):
408
416
    if local_branch is not None:
409
417
        update_git_cache(local_branch.repository, new_revid)
410
418
    update_git_cache(master_branch.repository, new_revid)
417
425
        return None
418
426
    from .server import git_http_hook
419
427
    return git_http_hook(branch, environ['REQUEST_METHOD'],
420
 
        environ['PATH_INFO'])
 
428
                         environ['PATH_INFO'])
 
429
 
421
430
 
422
431
install_lazy_named_hook("breezy.branch",
423
 
    "Branch.hooks", "post_commit", post_commit_update_cache,
424
 
    "git cache")
 
432
                        "Branch.hooks", "post_commit", post_commit_update_cache,
 
433
                        "git cache")
425
434
install_lazy_named_hook("breezy.plugins.loggerhead.apps.branch",
426
 
    "BranchWSGIApp.hooks", "controller",
427
 
    loggerhead_git_hook, "git support")
 
435
                        "BranchWSGIApp.hooks", "controller",
 
436
                        loggerhead_git_hook, "git support")
428
437
 
429
438
 
430
439
from ..config import (
442
451
This enables support for fetching Git packs over HTTP in Loggerhead.
443
452
'''))
444
453
 
 
454
 
445
455
def test_suite():
446
456
    from . import tests
447
457
    return tests.test_suite()