/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 __init__.py

Remove segment parameters for http smart transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
"""A GIT branch and repository format implementation for bzr."""
23
23
 
 
24
from __future__ import absolute_import
 
25
 
24
26
import os
25
27
import sys
26
28
 
27
29
import bzrlib
28
30
import bzrlib.api
29
31
 
30
 
from info import (
 
32
from bzrlib.plugins.git.info import (
31
33
    bzr_compatible_versions,
32
34
    bzr_plugin_version as version_info,
33
35
    dulwich_minimum_version,
41
43
 
42
44
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
43
45
 
 
46
try:
 
47
    from bzrlib.i18n import load_plugin_translations
 
48
except ImportError: # No translations for bzr < 2.5
 
49
    gettext = lambda x: x
 
50
else:
 
51
    translation = load_plugin_translations("bzr-git")
 
52
    gettext = translation.gettext
44
53
 
45
54
from bzrlib import (
46
55
    errors as bzr_errors,
47
 
    osutils,
48
 
    )
49
 
try:
50
 
    from bzrlib.controldir import (
51
 
        ControlDirFormat,
52
 
        ControlDir,
53
 
        Prober,
54
 
        format_registry,
55
 
        )
56
 
except ImportError:
57
 
    # bzr < 2.3
58
 
    from bzrlib.bzrdir import (
59
 
        BzrDirFormat,
60
 
        BzrDir,
61
 
        format_registry,
62
 
        )
63
 
    ControlDir = BzrDir
64
 
    ControlDirFormat = BzrDirFormat
65
 
    Prober = object
66
 
    has_controldir = False
67
 
else:
68
 
    has_controldir = True
 
56
    trace,
 
57
    )
 
58
 
 
59
from bzrlib.controldir import (
 
60
    ControlDirFormat,
 
61
    Prober,
 
62
    format_registry,
 
63
    network_format_registry as controldir_network_format_registry,
 
64
    )
69
65
 
70
66
from bzrlib.foreign import (
71
67
    foreign_vcs_registry,
73
69
from bzrlib.help_topics import (
74
70
    topic_registry,
75
71
    )
76
 
from bzrlib.lockable_files import (
77
 
    TransportLock,
78
 
    )
79
72
from bzrlib.transport import (
80
73
    register_lazy_transport,
81
74
    register_transport_proto,
83
76
from bzrlib.commands import (
84
77
    plugin_cmds,
85
78
    )
86
 
from bzrlib.version_info_formats.format_rio import (
87
 
    RioVersionInfoBuilder,
88
 
    )
89
79
from bzrlib.send import (
90
80
    format_registry as send_format_registry,
91
81
    )
133
123
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
134
124
    "RevisionSpec_git")
135
125
 
136
 
try:
137
 
    from bzrlib.revisionspec import dwim_revspecs
138
 
except ImportError:
139
 
    pass
140
 
else:
 
126
from bzrlib.revisionspec import dwim_revspecs, RevisionSpec_dwim
 
127
if getattr(RevisionSpec_dwim, "append_possible_lazy_revspec", None):
 
128
    RevisionSpec_dwim.append_possible_lazy_revspec(
 
129
        "bzrlib.plugins.git.revspec", "RevisionSpec_git")
 
130
else: # bzr < 2.4
141
131
    from bzrlib.plugins.git.revspec import RevisionSpec_git
142
132
    dwim_revspecs.append(RevisionSpec_git)
143
133
 
144
134
 
145
 
class GitControlDirFormat(ControlDirFormat):
146
 
 
147
 
    _lock_class = TransportLock
148
 
 
149
 
    colocated_branches = True
150
 
 
151
 
    def __eq__(self, other):
152
 
        return type(self) == type(other)
153
 
 
154
 
    def is_supported(self):
155
 
        return True
156
 
 
157
 
    def network_name(self):
158
 
        return "git"
159
 
 
160
 
 
161
135
class LocalGitProber(Prober):
162
136
 
163
137
    def probe_transport(self, transport):
164
138
        try:
165
 
            if not transport.has_any(['info/refs', '.git/branches',
166
 
                                      'branches']):
167
 
                raise bzr_errors.NotBranchError(path=transport.base)
168
 
        except bzr_errors.NoSuchFile:
 
139
            external_url = transport.external_url()
 
140
        except bzr_errors.InProcessTransport:
 
141
            raise bzr_errors.NotBranchError(path=transport.base)
 
142
        if (external_url.startswith("http:") or
 
143
            external_url.startswith("https:")):
 
144
            # Already handled by RemoteGitProber
169
145
            raise bzr_errors.NotBranchError(path=transport.base)
170
146
        from bzrlib import urlutils
171
147
        if urlutils.split(transport.base)[1] == ".git":
172
148
            raise bzr_errors.NotBranchError(path=transport.base)
 
149
        if not transport.has_any(['objects', '.git/objects']):
 
150
            raise bzr_errors.NotBranchError(path=transport.base)
173
151
        lazy_check_versions()
174
 
        import dulwich
175
 
        from bzrlib.plugins.git.transportgit import TransportRepo
176
 
        try:
177
 
            gitrepo = TransportRepo(transport)
178
 
        except dulwich.errors.NotGitRepository, e:
179
 
            raise bzr_errors.NotBranchError(path=transport.base)
 
152
        from bzrlib.plugins.git.dir import (
 
153
            BareLocalGitControlDirFormat,
 
154
            LocalGitControlDirFormat,
 
155
            )
 
156
        if transport.has_any(['.git/objects']):
 
157
            return LocalGitControlDirFormat()
 
158
        if transport.has('info') and transport.has('objects'):
 
159
            return BareLocalGitControlDirFormat()
 
160
        raise bzr_errors.NotBranchError(path=transport.base)
 
161
 
 
162
    @classmethod
 
163
    def known_formats(cls):
 
164
        from bzrlib.plugins.git.dir import (
 
165
            BareLocalGitControlDirFormat,
 
166
            LocalGitControlDirFormat,
 
167
            )
 
168
        return set([BareLocalGitControlDirFormat(), LocalGitControlDirFormat()])
 
169
 
 
170
 
 
171
class RemoteGitProber(Prober):
 
172
 
 
173
    def probe_http_transport(self, transport):
 
174
        from bzrlib import urlutils
 
175
        base_url, _ = urlutils.split_segment_parameters(transport.external_url())
 
176
        url = urlutils.join(base_url, "info/refs") + "?service=git-upload-pack"
 
177
        from bzrlib.transport.http._urllib import HttpTransport_urllib, Request
 
178
        if isinstance(transport, HttpTransport_urllib):
 
179
            req = Request('GET', url, accepted_errors=[200, 403, 404, 405],
 
180
                          headers={"Content-Type": "application/x-git-upload-pack-request"})
 
181
            req.follow_redirections = True
 
182
            resp = transport._perform(req)
 
183
            if resp.code in (404, 405):
 
184
                raise bzr_errors.NotBranchError(transport.base)
 
185
            headers = resp.headers
 
186
            refs_text = resp.read()
180
187
        else:
181
 
            if gitrepo.bare:
182
 
                return BareLocalGitControlDirFormat()
 
188
            try:
 
189
                from bzrlib.transport.http._pycurl import PyCurlTransport
 
190
            except bzr_errors.DependencyNotPresent:
 
191
                raise bzr_errors.NotBranchError(transport.base)
183
192
            else:
184
 
                return LocalGitControlDirFormat()
185
 
 
186
 
 
187
 
class LocalGitControlDirFormat(GitControlDirFormat):
188
 
    """The .git directory control format."""
189
 
 
190
 
    bare = False
191
 
 
192
 
    @classmethod
193
 
    def _known_formats(self):
194
 
        return set([LocalGitControlDirFormat()])
195
 
 
196
 
    def open(self, transport, _found=None):
197
 
        """Open this directory.
198
 
 
199
 
        """
200
 
        lazy_check_versions()
201
 
        from bzrlib.plugins.git.transportgit import TransportRepo
202
 
        gitrepo = TransportRepo(transport)
203
 
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
204
 
        lockfiles = GitLockableFiles(transport, GitLock())
205
 
        return LocalGitDir(transport, lockfiles, gitrepo, self)
206
 
 
207
 
    @classmethod
208
 
    def probe_transport(klass, transport):
209
 
        prober = LocalGitProber()
210
 
        return prober.probe_transport(transport)
211
 
 
212
 
    def get_format_description(self):
213
 
        return "Local Git Repository"
214
 
 
215
 
    def initialize_on_transport(self, transport):
216
 
        from bzrlib.transport.local import LocalTransport
217
 
 
218
 
        if not isinstance(transport, LocalTransport):
219
 
            raise NotImplementedError(self.initialize,
220
 
                "Can't create Git Repositories/branches on "
221
 
                "non-local transports")
222
 
        lazy_check_versions()
223
 
        from dulwich.repo import Repo
224
 
        Repo.init(transport.local_abspath(".").encode(osutils._fs_enc),
225
 
            bare=self.bare)
226
 
        return self.open(transport)
227
 
 
228
 
    def is_supported(self):
229
 
        return True
230
 
 
231
 
 
232
 
class BareLocalGitControlDirFormat(LocalGitControlDirFormat):
233
 
 
234
 
    bare = True
235
 
    supports_workingtrees = False
236
 
 
237
 
    @classmethod
238
 
    def _known_formats(self):
239
 
        return set([RemoteGitControlDirFormat()])
240
 
 
241
 
    def get_format_description(self):
242
 
        return "Local Git Repository (bare)"
243
 
 
244
 
 
245
 
class RemoteGitProber(Prober):
 
193
                import pycurl
 
194
                from cStringIO import StringIO
 
195
                if isinstance(transport, PyCurlTransport):
 
196
                    conn = transport._get_curl()
 
197
                    conn.setopt(pycurl.URL, url)
 
198
                    conn.setopt(pycurl.FOLLOWLOCATION, 1)
 
199
                    transport._set_curl_options(conn)
 
200
                    conn.setopt(pycurl.HTTPGET, 1)
 
201
                    header = StringIO()
 
202
                    data = StringIO()
 
203
                    conn.setopt(pycurl.HEADERFUNCTION, header.write)
 
204
                    conn.setopt(pycurl.WRITEFUNCTION, data.write)
 
205
                    transport._curl_perform(conn, header,
 
206
                        ["Content-Type: application/x-git-upload-pack-request"])
 
207
                    code = conn.getinfo(pycurl.HTTP_CODE)
 
208
                    if code in (404, 405):
 
209
                        raise bzr_errors.NotBranchError(transport.base)
 
210
                    if code != 200:
 
211
                        raise bzr_errors.InvalidHttpResponse(transport._path,
 
212
                            str(code))
 
213
                    headers = transport._parse_headers(header)
 
214
                else:
 
215
                    raise bzr_errors.NotBranchError(transport.base)
 
216
                refs_text = data.getvalue()
 
217
        ct = headers.getheader("Content-Type")
 
218
        if ct is None:
 
219
            raise bzr_errors.NotBranchError(transport.base)
 
220
        if ct.startswith("application/x-git"):
 
221
            from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
 
222
            return RemoteGitControlDirFormat()
 
223
        else:
 
224
            from bzrlib.plugins.git.dir import (
 
225
                BareLocalGitControlDirFormat,
 
226
                )
 
227
            ret = BareLocalGitControlDirFormat()
 
228
            ret._refs_text = refs_text
 
229
            return ret
246
230
 
247
231
    def probe_transport(self, transport):
248
 
        url = transport.base
249
 
        if url.startswith('readonly+'):
250
 
            url = url[len('readonly+'):]
251
 
        if (not url.startswith("git://") and not url.startswith("git+")):
 
232
        try:
 
233
            external_url = transport.external_url()
 
234
        except bzr_errors.InProcessTransport:
 
235
            raise bzr_errors.NotBranchError(path=transport.base)
 
236
 
 
237
        if (external_url.startswith("http:") or
 
238
            external_url.startswith("https:")):
 
239
            return self.probe_http_transport(transport)
 
240
 
 
241
        if (not external_url.startswith("git://") and
 
242
            not external_url.startswith("git+")):
252
243
            raise bzr_errors.NotBranchError(transport.base)
 
244
 
253
245
        # little ugly, but works
254
 
        from bzrlib.plugins.git.remote import GitSmartTransport
255
 
        if not isinstance(transport, GitSmartTransport):
256
 
            raise bzr_errors.NotBranchError(transport.base)
257
 
        return RemoteGitControlDirFormat()
258
 
 
259
 
 
260
 
 
261
 
class RemoteGitControlDirFormat(GitControlDirFormat):
262
 
    """The .git directory control format."""
263
 
 
264
 
    supports_workingtrees = False
 
246
        from bzrlib.plugins.git.remote import (
 
247
            GitSmartTransport,
 
248
            RemoteGitControlDirFormat,
 
249
            )
 
250
        if isinstance(transport, GitSmartTransport):
 
251
            return RemoteGitControlDirFormat()
 
252
        raise bzr_errors.NotBranchError(path=transport.base)
265
253
 
266
254
    @classmethod
267
 
    def _known_formats(self):
 
255
    def known_formats(cls):
 
256
        from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
268
257
        return set([RemoteGitControlDirFormat()])
269
258
 
270
 
    def open(self, transport, _found=None):
271
 
        """Open this directory.
272
 
 
273
 
        """
274
 
        # we dont grok readonly - git isn't integrated with transport.
275
 
        url = transport.base
276
 
        if url.startswith('readonly+'):
277
 
            url = url[len('readonly+'):]
278
 
        if (not url.startswith("git://") and not url.startswith("git+")):
279
 
            raise bzr_errors.NotBranchError(transport.base)
280
 
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
281
 
        if not isinstance(transport, GitSmartTransport):
282
 
            raise bzr_errors.NotBranchError(transport.base)
283
 
        from bzrlib.plugins.git.dir import GitLockableFiles, GitLock
284
 
        lockfiles = GitLockableFiles(transport, GitLock())
285
 
        return RemoteGitDir(transport, lockfiles, self)
286
 
 
287
 
    @classmethod
288
 
    def probe_transport(klass, transport):
289
 
        """Our format is present if the transport ends in '.not/'."""
290
 
        prober = RemoteGitProber()
291
 
        return prober.probe_transport(transport)
292
 
 
293
 
    def get_format_description(self):
294
 
        return "Remote Git Repository"
295
 
 
296
 
    def initialize_on_transport(self, transport):
297
 
        raise bzr_errors.UninitializableFormat(self)
298
 
 
299
 
 
300
 
if has_controldir:
 
259
 
 
260
if not getattr(Prober, "known_formats", None): # bzr < 2.4
 
261
    from bzrlib.plugins.git.dir import (
 
262
        LocalGitControlDirFormat, BareLocalGitControlDirFormat,
 
263
        )
 
264
    from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
301
265
    ControlDirFormat.register_format(LocalGitControlDirFormat())
302
266
    ControlDirFormat.register_format(BareLocalGitControlDirFormat())
303
267
    ControlDirFormat.register_format(RemoteGitControlDirFormat())
304
 
    ControlDirFormat.register_prober(LocalGitProber)
305
 
    ControlDirFormat.register_prober(RemoteGitProber)
306
 
else:
307
 
    ControlDirFormat.register_control_format(LocalGitControlDirFormat)
308
 
    ControlDirFormat.register_control_format(BareLocalGitControlDirFormat)
309
 
    ControlDirFormat.register_control_format(RemoteGitControlDirFormat)
 
268
    # Provide RevisionTree.get_file_revision, so various parts of bzr-svn
 
269
    # can avoid inventories.
 
270
    from bzrlib.revisiontree import RevisionTree
 
271
    def get_file_revision(tree, file_id, path=None):
 
272
        return tree.inventory[file_id].revision
 
273
    RevisionTree.get_file_revision = get_file_revision
 
274
 
 
275
ControlDirFormat.register_prober(LocalGitProber)
 
276
ControlDirFormat._server_probers.insert(0, RemoteGitProber)
310
277
 
311
278
register_transport_proto('git://',
312
279
        help="Access using the Git smart server protocol.")
319
286
                        'SSHGitSmartTransport')
320
287
 
321
288
foreign_vcs_registry.register_lazy("git",
322
 
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
 
289
    "bzrlib.plugins.git.mapping", "foreign_vcs_git", "Stupid content tracker")
323
290
 
324
291
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
325
292
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
327
294
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
328
295
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
329
296
 
 
297
def extract_git_foreign_revid(rev):
 
298
    try:
 
299
        foreign_revid = rev.foreign_revid
 
300
    except AttributeError:
 
301
        from bzrlib.plugins.git.mapping import mapping_registry
 
302
        foreign_revid, mapping = \
 
303
            mapping_registry.parse_revision_id(rev.revision_id)
 
304
        return foreign_revid
 
305
    else:
 
306
        from bzrlib.plugins.git.mapping import foreign_vcs_git
 
307
        if rev.mapping.vcs == foreign_vcs_git:
 
308
            return foreign_revid
 
309
        else:
 
310
            raise bzr_errors.InvalidRevisionId(rev.revision_id, None)
 
311
 
 
312
 
330
313
def update_stanza(rev, stanza):
331
314
    mapping = getattr(rev, "mapping", None)
332
 
    if mapping is not None and mapping.revid_prefix.startswith("git-"):
333
 
        stanza.add("git-commit", rev.foreign_revid)
334
 
 
335
 
 
336
 
rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
337
 
if rio_hooks is not None:
338
 
    rio_hooks.install_named_hook('revision', update_stanza, None)
 
315
    try:
 
316
        git_commit = extract_git_foreign_revid(rev)
 
317
    except bzr_errors.InvalidRevisionId:
 
318
        pass
 
319
    else:
 
320
        stanza.add("git-commit", git_commit)
 
321
 
 
322
try:
 
323
    from bzrlib.hooks import install_lazy_named_hook
 
324
except ImportError: # Compatibility with bzr < 2.4
 
325
    from bzrlib.version_info_formats.format_rio import (
 
326
        RioVersionInfoBuilder,
 
327
        )
 
328
    RioVersionInfoBuilder.hooks.install_named_hook('revision', update_stanza,
 
329
        "git commits")
 
330
else:
 
331
    install_lazy_named_hook("bzrlib.version_info_formats.format_rio",
 
332
        "RioVersionInfoBuilder.hooks", "revision", update_stanza,
 
333
        "git commits")
339
334
 
340
335
 
341
336
from bzrlib.transport import transport_server_registry
344
339
    'serve_git',
345
340
    'Git Smart server protocol over TCP. (default port: 9418)')
346
341
 
 
342
transport_server_registry.register_lazy('git-receive-pack',
 
343
    'bzrlib.plugins.git.server',
 
344
    'serve_git_receive_pack',
 
345
    help='Git Smart server receive pack command (inetd mode only)')
 
346
transport_server_registry.register_lazy('git-upload-pack',
 
347
    'bzrlib.plugins.git.server',
 
348
    'serve_git_upload_pack',
 
349
    help='Git Smart server upload pack command (inetd mode only)')
347
350
 
348
351
from bzrlib.repository import (
 
352
    format_registry as repository_format_registry,
349
353
    network_format_registry as repository_network_format_registry,
350
354
    )
351
355
repository_network_format_registry.register_lazy('git',
352
356
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
353
357
 
354
358
try:
355
 
    from bzrlib.controldir import (
356
 
        network_format_registry as controldir_network_format_registry,
357
 
        )
358
 
except ImportError:
359
 
    from bzrlib.bzrdir import (
360
 
        network_format_registry as controldir_network_format_registry,
361
 
        )
362
 
controldir_network_format_registry.register('git', GitControlDirFormat)
 
359
    register_extra_lazy_repository_format = getattr(repository_format_registry,
 
360
        "register_extra_lazy")
 
361
except AttributeError: # bzr < 2.4
 
362
    pass
 
363
else:
 
364
    register_extra_lazy_repository_format('bzrlib.plugins.git.repository',
 
365
        'GitRepositoryFormat')
 
366
 
 
367
from bzrlib.branch import (
 
368
    network_format_registry as branch_network_format_registry,
 
369
    )
 
370
branch_network_format_registry.register_lazy('git',
 
371
    'bzrlib.plugins.git.branch', 'GitBranchFormat')
 
372
 
 
373
try:
 
374
    from bzrlib.branch import (
 
375
        format_registry as branch_format_registry,
 
376
        )
 
377
except ImportError: # bzr < 2.4
 
378
    pass
 
379
else:
 
380
    branch_format_registry.register_extra_lazy(
 
381
        'bzrlib.plugins.git.branch',
 
382
        'GitBranchFormat',
 
383
        )
 
384
 
 
385
try:
 
386
    from bzrlib.workingtree import (
 
387
        format_registry as workingtree_format_registry,
 
388
        )
 
389
except ImportError: # bzr < 2.4
 
390
    pass
 
391
else:
 
392
    workingtree_format_registry.register_extra_lazy(
 
393
        'bzrlib.plugins.git.workingtree',
 
394
        'GitWorkingTreeFormat',
 
395
        )
 
396
 
 
397
controldir_network_format_registry.register_lazy('git',
 
398
    "bzrlib.plugins.git.dir", "GitControlDirFormat")
363
399
 
364
400
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
365
401
                                   'send_git', 'Git am-style diff format')
366
402
 
367
 
topic_registry.register_lazy('git',
368
 
                             'bzrlib.plugins.git.help',
369
 
                             'help_git', 'Using Bazaar with Git')
 
403
topic_registry.register_lazy('git', 'bzrlib.plugins.git.help', 'help_git',
 
404
    'Using Bazaar with Git')
 
405
 
 
406
from bzrlib.diff import format_registry as diff_format_registry
 
407
diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
408
    'GitDiffTree', 'Git am-style diff format')
 
409
 
 
410
 
 
411
def update_git_cache(repository, revid):
 
412
    """Update the git cache after a local commit."""
 
413
    if getattr(repository, "_git", None) is not None:
 
414
        return # No need to update cache for git repositories
 
415
 
 
416
    if not repository.control_transport.has("git"):
 
417
        return # No existing cache, don't bother updating
 
418
    try:
 
419
        lazy_check_versions()
 
420
    except bzr_errors.DependencyNotPresent, e:
 
421
        # dulwich is probably missing. silently ignore
 
422
        trace.mutter("not updating git map for %r: %s",
 
423
            repository, e)
 
424
 
 
425
    from bzrlib.plugins.git.object_store import BazaarObjectStore
 
426
    store = BazaarObjectStore(repository)
 
427
    store.lock_write()
 
428
    try:
 
429
        parent_revisions = set(repository.get_parent_map([revid])[revid])
 
430
        missing_revisions = store._missing_revisions(parent_revisions)
 
431
        if not missing_revisions:
 
432
            # Only update if the cache was up to date previously
 
433
            store._update_sha_map_revision(revid)
 
434
    finally:
 
435
        store.unlock()
 
436
 
 
437
 
 
438
def post_commit_update_cache(local_branch, master_branch, old_revno, old_revid,
 
439
        new_revno, new_revid):
 
440
    if local_branch is not None:
 
441
        update_git_cache(local_branch.repository, new_revid)
 
442
    update_git_cache(master_branch.repository, new_revid)
 
443
 
 
444
 
 
445
def loggerhead_git_hook(branch_app, environ):
 
446
    from bzrlib.config import GlobalConfig
 
447
    branch = branch_app.branch
 
448
    if GlobalConfig().get_user_option('http_git') != 'True':
 
449
        return None
 
450
    from bzrlib.plugins.git.server import git_http_hook
 
451
    return git_http_hook(branch, environ['REQUEST_METHOD'],
 
452
        environ['PATH_INFO'])
370
453
 
371
454
try:
372
 
    from bzrlib.diff import format_registry as diff_format_registry
373
 
except ImportError:
 
455
    from bzrlib.hooks import install_lazy_named_hook
 
456
except ImportError: # Compatibility with bzr < 2.4
374
457
    pass
375
458
else:
376
 
    diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
377
 
        'GitDiffTree', 'Git am-style diff format')
 
459
    install_lazy_named_hook("bzrlib.branch",
 
460
        "Branch.hooks", "post_commit", post_commit_update_cache,
 
461
        "git cache")
 
462
    install_lazy_named_hook("bzrlib.plugins.loggerhead.apps.branch",
 
463
        "BranchWSGIApp.hooks", "controller",
 
464
        loggerhead_git_hook, "git support")
 
465
 
378
466
 
379
467
def test_suite():
380
468
    from bzrlib.plugins.git import tests