/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.235 by Jelmer Vernooij
Depend on newer dulwich.
1
# Copyright (C) 2006-2009 Canonical Ltd
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
2
0.200.1 by Robert Collins
Commit initial content.
3
# Authors: Robert Collins <robert.collins@canonical.com>
0.200.184 by Jelmer Vernooij
Update authors: line.
4
#          Jelmer Vernooij <jelmer@samba.org>
5
#          John Carr <john.carr@unrouted.co.uk>
0.200.1 by Robert Collins
Commit initial content.
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21
22
"""A GIT branch and repository format implementation for bzr."""
23
0.200.1528 by Jelmer Vernooij
Use absolute_import in __init__.
24
from __future__ import absolute_import
25
0.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
26
import os
27
import sys
28
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
29
import bzrlib
30
import bzrlib.api
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
31
0.200.1528 by Jelmer Vernooij
Use absolute_import in __init__.
32
from bzrlib.plugins.git.info import (
0.200.583 by Jelmer Vernooij
Add plugin api info.
33
    bzr_compatible_versions,
34
    bzr_plugin_version as version_info,
35
    dulwich_minimum_version,
36
    )
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
37
38
if version_info[3] == 'final':
39
    version_string = '%d.%d.%d' % version_info[:3]
40
else:
41
    version_string = '%d.%d.%d%s%d' % version_info
42
__version__ = version_string
43
0.200.583 by Jelmer Vernooij
Add plugin api info.
44
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
45
0.200.1406 by Jelmer Vernooij
Import gettext.
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
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
53
0.200.292 by Jelmer Vernooij
Fix formatting.
54
from bzrlib import (
55
    errors as bzr_errors,
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
56
    trace,
0.200.292 by Jelmer Vernooij
Fix formatting.
57
    )
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
58
59
from bzrlib.controldir import (
60
    ControlDirFormat,
61
    Prober,
62
    format_registry,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
63
    network_format_registry as controldir_network_format_registry,
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
64
    )
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
65
0.200.292 by Jelmer Vernooij
Fix formatting.
66
from bzrlib.transport import (
67
    register_lazy_transport,
0.200.308 by Jelmer Vernooij
Register git protocols.
68
    register_transport_proto,
0.276.1 by Jelmer Vernooij
Use register_lazy.
69
    transport_server_registry,
0.200.292 by Jelmer Vernooij
Fix formatting.
70
    )
71
from bzrlib.commands import (
72
    plugin_cmds,
73
    )
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
74
0.200.192 by Jelmer Vernooij
use system-provided dulwich, remove own copy.
75
0.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
76
if getattr(sys, "frozen", None):
77
    # allow import additional libs from ./_lib for bzr.exe only
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
78
    sys.path.append(os.path.normpath(
79
        os.path.join(os.path.dirname(__file__), '_lib')))
0.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
80
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
81
82
def import_dulwich():
0.200.200 by Jelmer Vernooij
Register lazily where possible.
83
    try:
84
        from dulwich import __version__ as dulwich_version
85
    except ImportError:
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
86
        raise bzr_errors.DependencyNotPresent("dulwich",
87
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
0.200.200 by Jelmer Vernooij
Register lazily where possible.
88
    else:
0.200.583 by Jelmer Vernooij
Add plugin api info.
89
        if dulwich_version < dulwich_minimum_version:
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
90
            raise bzr_errors.DependencyNotPresent("dulwich",
91
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
92
                    dulwich_minimum_version)
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
93
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
94
95
_versions_checked = False
96
def lazy_check_versions():
97
    global _versions_checked
98
    if _versions_checked:
99
        return
100
    import_dulwich()
101
    _versions_checked = True
102
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
103
format_registry.register_lazy('git',
0.200.1141 by Jelmer Vernooij
Use transports in git-import.
104
    "bzrlib.plugins.git.dir", "LocalGitControlDirFormat",
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
105
    help='GIT repository.', native=False, experimental=False,
0.200.200 by Jelmer Vernooij
Register lazily where possible.
106
    )
0.200.204 by Jelmer Vernooij
Support bzr 1.11.
107
0.200.1032 by Jelmer Vernooij
Support bare repositories.
108
format_registry.register_lazy('git-bare',
0.200.1141 by Jelmer Vernooij
Use transports in git-import.
109
    "bzrlib.plugins.git.dir", "BareLocalGitControlDirFormat",
0.200.1032 by Jelmer Vernooij
Support bare repositories.
110
    help='Bare GIT repository (no working tree).', native=False,
111
    experimental=False,
112
    )
113
0.276.1 by Jelmer Vernooij
Use register_lazy.
114
from bzrlib.revisionspec import (RevisionSpec_dwim, revspec_registry)
0.200.674 by Jelmer Vernooij
Fix formatting.
115
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
0.200.292 by Jelmer Vernooij
Fix formatting.
116
    "RevisionSpec_git")
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
117
RevisionSpec_dwim.append_possible_lazy_revspec(
118
    "bzrlib.plugins.git.revspec", "RevisionSpec_git")
0.200.645 by Jelmer Vernooij
Support DWIM git: revspecs.
119
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
120
0.200.1014 by Jelmer Vernooij
Fix tests.
121
class LocalGitProber(Prober):
122
123
    def probe_transport(self, transport):
0.200.720 by Jelmer Vernooij
Avoid loading bzr-git/dulwich when not necessary.
124
        try:
0.268.1 by Jelmer Vernooij
Fix probing of http repositories when pycurl is used.
125
            external_url = transport.external_url()
126
        except bzr_errors.InProcessTransport:
127
            raise bzr_errors.NotBranchError(path=transport.base)
128
        if (external_url.startswith("http:") or
129
            external_url.startswith("https:")):
130
            # Already handled by RemoteGitProber
131
            raise bzr_errors.NotBranchError(path=transport.base)
0.200.730 by Jelmer Vernooij
Don't claim control directories can be accessed directly, always open the
132
        from bzrlib import urlutils
133
        if urlutils.split(transport.base)[1] == ".git":
134
            raise bzr_errors.NotBranchError(path=transport.base)
0.200.1387 by Jelmer Vernooij
Avoid using HEAD.
135
        if not transport.has_any(['objects', '.git/objects']):
136
            raise bzr_errors.NotBranchError(path=transport.base)
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
137
        lazy_check_versions()
0.200.1387 by Jelmer Vernooij
Avoid using HEAD.
138
        from bzrlib.plugins.git.dir import (
139
            BareLocalGitControlDirFormat,
140
            LocalGitControlDirFormat,
141
            )
142
        if transport.has_any(['.git/objects']):
143
            return LocalGitControlDirFormat()
144
        if transport.has('info') and transport.has('objects'):
145
            return BareLocalGitControlDirFormat()
0.200.1399 by Jelmer Vernooij
In prober, always return or raise NotBranchError.
146
        raise bzr_errors.NotBranchError(path=transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
147
0.200.1139 by Jelmer Vernooij
Prober.known_formats is a class method.
148
    @classmethod
149
    def known_formats(cls):
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
150
        from bzrlib.plugins.git.dir import (
151
            BareLocalGitControlDirFormat,
152
            LocalGitControlDirFormat,
153
            )
154
        return set([BareLocalGitControlDirFormat(), LocalGitControlDirFormat()])
0.200.1032 by Jelmer Vernooij
Support bare repositories.
155
156
0.200.1014 by Jelmer Vernooij
Fix tests.
157
class RemoteGitProber(Prober):
158
0.200.1334 by Jelmer Vernooij
Detect smart servers.
159
    def probe_http_transport(self, transport):
160
        from bzrlib import urlutils
0.200.1554 by Jelmer Vernooij
Fix probing over http with colocated branches.
161
        base_url, _ = urlutils.split_segment_parameters(transport.external_url())
162
        url = urlutils.join(base_url, "info/refs") + "?service=git-upload-pack"
0.200.1334 by Jelmer Vernooij
Detect smart servers.
163
        from bzrlib.transport.http._urllib import HttpTransport_urllib, Request
164
        if isinstance(transport, HttpTransport_urllib):
165
            req = Request('GET', url, accepted_errors=[200, 403, 404, 405],
166
                          headers={"Content-Type": "application/x-git-upload-pack-request"})
167
            req.follow_redirections = True
168
            resp = transport._perform(req)
0.200.1471 by Jelmer Vernooij
ignore 405 replies when probing.
169
            if resp.code in (404, 405):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
170
                raise bzr_errors.NotBranchError(transport.base)
171
            headers = resp.headers
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
172
            refs_text = resp.read()
0.200.1334 by Jelmer Vernooij
Detect smart servers.
173
        else:
174
            try:
175
                from bzrlib.transport.http._pycurl import PyCurlTransport
176
            except bzr_errors.DependencyNotPresent:
177
                raise bzr_errors.NotBranchError(transport.base)
178
            else:
179
                import pycurl
180
                from cStringIO import StringIO
181
                if isinstance(transport, PyCurlTransport):
182
                    conn = transport._get_curl()
183
                    conn.setopt(pycurl.URL, url)
0.200.1445 by Jelmer Vernooij
Follow redirects for pycurl, too.
184
                    conn.setopt(pycurl.FOLLOWLOCATION, 1)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
185
                    transport._set_curl_options(conn)
186
                    conn.setopt(pycurl.HTTPGET, 1)
187
                    header = StringIO()
188
                    data = StringIO()
189
                    conn.setopt(pycurl.HEADERFUNCTION, header.write)
190
                    conn.setopt(pycurl.WRITEFUNCTION, data.write)
191
                    transport._curl_perform(conn, header,
192
                        ["Content-Type: application/x-git-upload-pack-request"])
193
                    code = conn.getinfo(pycurl.HTTP_CODE)
0.200.1471 by Jelmer Vernooij
ignore 405 replies when probing.
194
                    if code in (404, 405):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
195
                        raise bzr_errors.NotBranchError(transport.base)
0.268.1 by Jelmer Vernooij
Fix probing of http repositories when pycurl is used.
196
                    if code != 200:
197
                        raise bzr_errors.InvalidHttpResponse(transport._path,
198
                            str(code))
0.200.1334 by Jelmer Vernooij
Detect smart servers.
199
                    headers = transport._parse_headers(header)
200
                else:
201
                    raise bzr_errors.NotBranchError(transport.base)
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
202
                refs_text = data.getvalue()
0.200.1334 by Jelmer Vernooij
Detect smart servers.
203
        ct = headers.getheader("Content-Type")
0.200.1405 by Jelmer Vernooij
Add i18n support.
204
        if ct is None:
205
            raise bzr_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
206
        if ct.startswith("application/x-git"):
207
            from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
208
            return RemoteGitControlDirFormat()
209
        else:
210
            from bzrlib.plugins.git.dir import (
211
                BareLocalGitControlDirFormat,
212
                )
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
213
            ret = BareLocalGitControlDirFormat()
214
            ret._refs_text = refs_text
215
            return ret
0.200.1334 by Jelmer Vernooij
Detect smart servers.
216
0.200.1014 by Jelmer Vernooij
Fix tests.
217
    def probe_transport(self, transport):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
218
        try:
219
            external_url = transport.external_url()
220
        except bzr_errors.InProcessTransport:
221
            raise bzr_errors.NotBranchError(path=transport.base)
222
223
        if (external_url.startswith("http:") or
224
            external_url.startswith("https:")):
225
            return self.probe_http_transport(transport)
226
227
        if (not external_url.startswith("git://") and
228
            not external_url.startswith("git+")):
0.200.1014 by Jelmer Vernooij
Fix tests.
229
            raise bzr_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
230
0.200.1014 by Jelmer Vernooij
Fix tests.
231
        # little ugly, but works
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
232
        from bzrlib.plugins.git.remote import (
233
            GitSmartTransport,
234
            RemoteGitControlDirFormat,
235
            )
0.200.1334 by Jelmer Vernooij
Detect smart servers.
236
        if isinstance(transport, GitSmartTransport):
237
            return RemoteGitControlDirFormat()
238
        raise bzr_errors.NotBranchError(path=transport.base)
0.200.1014 by Jelmer Vernooij
Fix tests.
239
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
240
    @classmethod
0.200.1139 by Jelmer Vernooij
Prober.known_formats is a class method.
241
    def known_formats(cls):
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
242
        from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
243
        return set([RemoteGitControlDirFormat()])
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
244
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
245
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
246
ControlDirFormat.register_prober(LocalGitProber)
0.200.1556 by Jelmer Vernooij
Add 'github:' directory service.
247
ControlDirFormat._server_probers.append(RemoteGitProber)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
248
0.200.674 by Jelmer Vernooij
Fix formatting.
249
register_transport_proto('git://',
0.200.308 by Jelmer Vernooij
Register git protocols.
250
        help="Access using the Git smart server protocol.")
0.200.674 by Jelmer Vernooij
Fix formatting.
251
register_transport_proto('git+ssh://',
0.200.308 by Jelmer Vernooij
Register git protocols.
252
        help="Access using the Git smart server protocol over SSH.")
253
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
254
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
0.200.307 by Jelmer Vernooij
Support git+ssh.
255
                        'TCPGitSmartTransport')
256
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
257
                        'SSHGitSmartTransport')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
258
0.208.5 by Jelmer Vernooij
Add log show function for git.
259
0.200.206 by Jelmer Vernooij
Move commands to a separate python module and register them lazily.
260
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
0.200.674 by Jelmer Vernooij
Fix formatting.
261
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
0.200.422 by Jelmer Vernooij
'bzr git-object' without arguments now prints the available git objects.
262
    "bzrlib.plugins.git.commands")
0.200.873 by Jelmer Vernooij
Add convenience command for accessing virtual git refs.
263
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
0.200.895 by Jelmer Vernooij
Add initial work on git-apply.
264
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
0.277.6 by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command.
265
plugin_cmds.register_lazy("cmd_git_push_pristine_tar_deltas",
266
        ['git-push-pristine-tar', 'git-push-pristine'],
267
    "bzrlib.plugins.git.commands")
0.200.177 by Jelmer Vernooij
Add git-import command.
268
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
269
def extract_git_foreign_revid(rev):
270
    try:
271
        foreign_revid = rev.foreign_revid
272
    except AttributeError:
273
        from bzrlib.plugins.git.mapping import mapping_registry
274
        foreign_revid, mapping = \
275
            mapping_registry.parse_revision_id(rev.revision_id)
276
        return foreign_revid
277
    else:
278
        from bzrlib.plugins.git.mapping import foreign_vcs_git
279
        if rev.mapping.vcs == foreign_vcs_git:
280
            return foreign_revid
281
        else:
282
            raise bzr_errors.InvalidRevisionId(rev.revision_id, None)
283
284
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
285
def update_stanza(rev, stanza):
286
    mapping = getattr(rev, "mapping", None)
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
287
    try:
288
        git_commit = extract_git_foreign_revid(rev)
289
    except bzr_errors.InvalidRevisionId:
290
        pass
291
    else:
292
        stanza.add("git-commit", git_commit)
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
293
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
294
from bzrlib.hooks import install_lazy_named_hook
295
install_lazy_named_hook("bzrlib.version_info_formats.format_rio",
296
    "RioVersionInfoBuilder.hooks", "revision", update_stanza,
297
    "git commits")
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
298
0.200.531 by Jelmer Vernooij
Support 'bzr serve --git'.
299
0.239.6 by Jelmer Vernooij
Remove pre-1.15 incompatible code.
300
transport_server_registry.register_lazy('git',
0.200.674 by Jelmer Vernooij
Fix formatting.
301
    'bzrlib.plugins.git.server',
0.239.6 by Jelmer Vernooij
Remove pre-1.15 incompatible code.
302
    'serve_git',
303
    'Git Smart server protocol over TCP. (default port: 9418)')
0.200.531 by Jelmer Vernooij
Support 'bzr serve --git'.
304
0.200.1496 by Jelmer Vernooij
Provide --git-receive-pack and --git-upload-pack options for 'bzr serve'.
305
transport_server_registry.register_lazy('git-receive-pack',
306
    'bzrlib.plugins.git.server',
307
    'serve_git_receive_pack',
0.200.1595 by Jelmer Vernooij
Fix formatting of option names.
308
    help='Git Smart server receive pack command. (inetd mode only)')
0.200.1496 by Jelmer Vernooij
Provide --git-receive-pack and --git-upload-pack options for 'bzr serve'.
309
transport_server_registry.register_lazy('git-upload-pack',
310
    'bzrlib.plugins.git.server',
311
    'serve_git_upload_pack',
0.200.1595 by Jelmer Vernooij
Fix formatting of option names.
312
    help='Git Smart server upload pack command. (inetd mode only)')
0.200.531 by Jelmer Vernooij
Support 'bzr serve --git'.
313
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
314
from bzrlib.repository import (
0.200.1083 by Jelmer Vernooij
Register repository format.
315
    format_registry as repository_format_registry,
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
316
    network_format_registry as repository_network_format_registry,
317
    )
0.200.674 by Jelmer Vernooij
Fix formatting.
318
repository_network_format_registry.register_lazy('git',
0.200.536 by Jelmer Vernooij
Implement network name.
319
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
320
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
321
register_extra_lazy_repository_format = getattr(repository_format_registry,
322
    "register_extra_lazy")
323
register_extra_lazy_repository_format('bzrlib.plugins.git.repository',
324
    'GitRepositoryFormat')
0.200.1083 by Jelmer Vernooij
Register repository format.
325
0.200.1127 by Jelmer Vernooij
Register branch format network name.
326
from bzrlib.branch import (
327
    network_format_registry as branch_network_format_registry,
328
    )
329
branch_network_format_registry.register_lazy('git',
330
    'bzrlib.plugins.git.branch', 'GitBranchFormat')
331
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
332
from bzrlib.branch import (
333
    format_registry as branch_format_registry,
334
    )
335
branch_format_registry.register_extra_lazy(
336
    'bzrlib.plugins.git.branch',
337
    'GitBranchFormat',
338
    )
0.200.1090 by Jelmer Vernooij
Register branch format for testing.
339
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
340
from bzrlib.workingtree import (
341
    format_registry as workingtree_format_registry,
342
    )
343
workingtree_format_registry.register_extra_lazy(
344
    'bzrlib.plugins.git.workingtree',
345
    'GitWorkingTreeFormat',
346
    )
0.200.1093 by Jelmer Vernooij
Register working tree format for testing.
347
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
348
controldir_network_format_registry.register_lazy('git',
349
    "bzrlib.plugins.git.dir", "GitControlDirFormat")
0.200.536 by Jelmer Vernooij
Implement network name.
350
0.276.1 by Jelmer Vernooij
Use register_lazy.
351
352
try:
353
    from bzrlib.registry import register_lazy
354
except ImportError:
355
    from bzrlib.diff import format_registry as diff_format_registry
356
    diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
357
        'GitDiffTree', 'Git am-style diff format')
358
359
    from bzrlib.send import (
360
        format_registry as send_format_registry,
361
        )
362
    send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
363
                                       'send_git', 'Git am-style diff format')
364
365
    from bzrlib.directory_service import directories
366
    directories.register_lazy('github:', 'bzrlib.plugins.git.directory',
367
                              'GitHubDirectory',
368
                              'GitHub directory.')
369
    directories.register_lazy('git@github.com:', 'bzrlib.plugins.git.directory',
370
                              'GitHubDirectory',
371
                              'GitHub directory.')
372
373
    from bzrlib.help_topics import (
374
        topic_registry,
375
        )
376
    topic_registry.register_lazy('git', 'bzrlib.plugins.git.help', 'help_git',
377
        'Using Bazaar with Git')
378
379
    from bzrlib.foreign import (
380
        foreign_vcs_registry,
381
        )
382
    foreign_vcs_registry.register_lazy("git",
383
        "bzrlib.plugins.git.mapping", "foreign_vcs_git", "Stupid content tracker")
384
else:
385
    register_lazy("bzrlib.diff", "format_registry",
386
        'git', 'bzrlib.plugins.git.send', 'GitDiffTree',
387
        'Git am-style diff format')
388
    register_lazy("bzrlib.send", "format_registry",
389
        'git', 'bzrlib.plugins.git.send', 'send_git',
390
        'Git am-style diff format')
391
    register_lazy('bzrlib.directory_service', 'directories', 'github:',
392
            'bzrlib.plugins.git.directory', 'GitHubDirectory',
393
            'GitHub directory.')
394
    register_lazy('bzrlib.directory_service', 'directories',
395
            'git@github.com:', 'bzrlib.plugins.git.directory',
396
            'GitHubDirectory', 'GitHub directory.')
397
    register_lazy('bzrlib.help_topics', 'topic_registry',
398
            'git', 'bzrlib.plugins.git.help', 'help_git',
399
            'Using Bazaar with Git')
400
    register_lazy('bzrlib.foreign', 'foreign_vcs_registry', "git",
401
        "bzrlib.plugins.git.mapping", "foreign_vcs_git", "Stupid content tracker")
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
402
403
def update_git_cache(repository, revid):
404
    """Update the git cache after a local commit."""
405
    if getattr(repository, "_git", None) is not None:
406
        return # No need to update cache for git repositories
407
408
    if not repository.control_transport.has("git"):
409
        return # No existing cache, don't bother updating
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
410
    try:
411
        lazy_check_versions()
412
    except bzr_errors.DependencyNotPresent, e:
413
        # dulwich is probably missing. silently ignore
414
        trace.mutter("not updating git map for %r: %s",
415
            repository, e)
416
417
    from bzrlib.plugins.git.object_store import BazaarObjectStore
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
418
    store = BazaarObjectStore(repository)
419
    store.lock_write()
420
    try:
0.200.1583 by Jelmer Vernooij
Use config stacks.
421
        try:
422
            parent_revisions = set(repository.get_parent_map([revid])[revid])
423
        except KeyError:
424
            # Isn't this a bit odd - how can a revision that was just committed be missing?
425
            return
0.200.1319 by Jelmer Vernooij
Only update git cache during post-commit if parents are already in the cache.
426
        missing_revisions = store._missing_revisions(parent_revisions)
427
        if not missing_revisions:
428
            # Only update if the cache was up to date previously
429
            store._update_sha_map_revision(revid)
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
430
    finally:
431
        store.unlock()
432
433
434
def post_commit_update_cache(local_branch, master_branch, old_revno, old_revid,
435
        new_revno, new_revid):
436
    if local_branch is not None:
437
        update_git_cache(local_branch.repository, new_revid)
438
    update_git_cache(master_branch.repository, new_revid)
439
440
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
441
def loggerhead_git_hook(branch_app, environ):
442
    branch = branch_app.branch
0.200.1583 by Jelmer Vernooij
Use config stacks.
443
    config_stack = branch.get_config_stack()
444
    if config_stack.get('http_git'):
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
445
        return None
446
    from bzrlib.plugins.git.server import git_http_hook
447
    return git_http_hook(branch, environ['REQUEST_METHOD'],
448
        environ['PATH_INFO'])
449
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
450
install_lazy_named_hook("bzrlib.branch",
451
    "Branch.hooks", "post_commit", post_commit_update_cache,
452
    "git cache")
453
install_lazy_named_hook("bzrlib.plugins.loggerhead.apps.branch",
454
    "BranchWSGIApp.hooks", "controller",
455
    loggerhead_git_hook, "git support")
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
456
457
0.200.1583 by Jelmer Vernooij
Use config stacks.
458
from bzrlib.config import (
459
    option_registry,
460
    Option,
461
    bool_from_store,
462
    )
463
464
option_registry.register(
465
    Option('git.http',
466
           default=None, from_unicode=bool_from_store, invalid='warning',
467
           help='''\
468
Allow fetching of Git packs over HTTP.
469
470
This enables support for fetching Git packs over HTTP in Loggerhead.
471
'''))
472
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
473
def test_suite():
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
474
    from bzrlib.plugins.git import tests
475
    return tests.test_suite()