/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.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
24
import os
25
import sys
26
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
27
import bzrlib
28
import bzrlib.api
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
29
0.200.587 by Jelmer Vernooij
Put plugin info in separate file.
30
from info import (
0.200.583 by Jelmer Vernooij
Add plugin api info.
31
    bzr_compatible_versions,
32
    bzr_plugin_version as version_info,
33
    dulwich_minimum_version,
34
    )
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
35
36
if version_info[3] == 'final':
37
    version_string = '%d.%d.%d' % version_info[:3]
38
else:
39
    version_string = '%d.%d.%d%s%d' % version_info
40
__version__ = version_string
41
0.200.583 by Jelmer Vernooij
Add plugin api info.
42
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.
43
0.200.1406 by Jelmer Vernooij
Import gettext.
44
try:
45
    from bzrlib.i18n import load_plugin_translations
46
except ImportError: # No translations for bzr < 2.5
47
    gettext = lambda x: x
48
else:
49
    translation = load_plugin_translations("bzr-git")
50
    gettext = translation.gettext
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
51
0.200.292 by Jelmer Vernooij
Fix formatting.
52
from bzrlib import (
53
    errors as bzr_errors,
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
54
    trace,
0.200.292 by Jelmer Vernooij
Fix formatting.
55
    )
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
56
57
from bzrlib.controldir import (
58
    ControlDirFormat,
59
    Prober,
60
    format_registry,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
61
    network_format_registry as controldir_network_format_registry,
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
62
    )
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
63
0.200.292 by Jelmer Vernooij
Fix formatting.
64
from bzrlib.foreign import (
65
    foreign_vcs_registry,
66
    )
0.200.1011 by Jelmer Vernooij
Add some basic documentation in 'bzr help git'.
67
from bzrlib.help_topics import (
68
    topic_registry,
69
    )
0.200.292 by Jelmer Vernooij
Fix formatting.
70
from bzrlib.transport import (
71
    register_lazy_transport,
0.200.308 by Jelmer Vernooij
Register git protocols.
72
    register_transport_proto,
0.200.292 by Jelmer Vernooij
Fix formatting.
73
    )
74
from bzrlib.commands import (
75
    plugin_cmds,
76
    )
0.238.1 by Lukas Lalinsky, Jelmer Vernooij
Import initial work on 'bzr send --format=git' based on luks' patch for bzr-svn.
77
from bzrlib.send import (
78
    format_registry as send_format_registry,
0.200.292 by Jelmer Vernooij
Fix formatting.
79
    )
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
80
0.200.192 by Jelmer Vernooij
use system-provided dulwich, remove own copy.
81
0.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
82
if getattr(sys, "frozen", None):
83
    # allow import additional libs from ./_lib for bzr.exe only
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
84
    sys.path.append(os.path.normpath(
85
        os.path.join(os.path.dirname(__file__), '_lib')))
0.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
86
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
87
88
def import_dulwich():
0.200.200 by Jelmer Vernooij
Register lazily where possible.
89
    try:
90
        from dulwich import __version__ as dulwich_version
91
    except ImportError:
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
92
        raise bzr_errors.DependencyNotPresent("dulwich",
93
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
0.200.200 by Jelmer Vernooij
Register lazily where possible.
94
    else:
0.200.583 by Jelmer Vernooij
Add plugin api info.
95
        if dulwich_version < dulwich_minimum_version:
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
96
            raise bzr_errors.DependencyNotPresent("dulwich",
97
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
98
                    dulwich_minimum_version)
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
99
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
100
101
_versions_checked = False
102
def lazy_check_versions():
103
    global _versions_checked
104
    if _versions_checked:
105
        return
106
    import_dulwich()
107
    _versions_checked = True
108
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
109
format_registry.register_lazy('git',
0.200.1141 by Jelmer Vernooij
Use transports in git-import.
110
    "bzrlib.plugins.git.dir", "LocalGitControlDirFormat",
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
111
    help='GIT repository.', native=False, experimental=False,
0.200.200 by Jelmer Vernooij
Register lazily where possible.
112
    )
0.200.204 by Jelmer Vernooij
Support bzr 1.11.
113
0.200.1032 by Jelmer Vernooij
Support bare repositories.
114
format_registry.register_lazy('git-bare',
0.200.1141 by Jelmer Vernooij
Use transports in git-import.
115
    "bzrlib.plugins.git.dir", "BareLocalGitControlDirFormat",
0.200.1032 by Jelmer Vernooij
Support bare repositories.
116
    help='Bare GIT repository (no working tree).', native=False,
117
    experimental=False,
118
    )
119
0.200.292 by Jelmer Vernooij
Fix formatting.
120
from bzrlib.revisionspec import revspec_registry
0.200.674 by Jelmer Vernooij
Fix formatting.
121
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
0.200.292 by Jelmer Vernooij
Fix formatting.
122
    "RevisionSpec_git")
0.200.200 by Jelmer Vernooij
Register lazily where possible.
123
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
124
from bzrlib.revisionspec import dwim_revspecs, RevisionSpec_dwim
125
if getattr(RevisionSpec_dwim, "append_possible_lazy_revspec", None):
126
    RevisionSpec_dwim.append_possible_lazy_revspec(
127
        "bzrlib.plugins.git.revspec", "RevisionSpec_git")
128
else: # bzr < 2.4
129
    from bzrlib.plugins.git.revspec import RevisionSpec_git
130
    dwim_revspecs.append(RevisionSpec_git)
0.200.645 by Jelmer Vernooij
Support DWIM git: revspecs.
131
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
132
0.200.1014 by Jelmer Vernooij
Fix tests.
133
class LocalGitProber(Prober):
134
135
    def probe_transport(self, transport):
0.200.720 by Jelmer Vernooij
Avoid loading bzr-git/dulwich when not necessary.
136
        try:
0.268.1 by Jelmer Vernooij
Fix probing of http repositories when pycurl is used.
137
            external_url = transport.external_url()
138
        except bzr_errors.InProcessTransport:
139
            raise bzr_errors.NotBranchError(path=transport.base)
140
        if (external_url.startswith("http:") or
141
            external_url.startswith("https:")):
142
            # Already handled by RemoteGitProber
143
            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
144
        from bzrlib import urlutils
145
        if urlutils.split(transport.base)[1] == ".git":
146
            raise bzr_errors.NotBranchError(path=transport.base)
0.200.1387 by Jelmer Vernooij
Avoid using HEAD.
147
        if not transport.has_any(['objects', '.git/objects']):
148
            raise bzr_errors.NotBranchError(path=transport.base)
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
149
        lazy_check_versions()
0.200.1387 by Jelmer Vernooij
Avoid using HEAD.
150
        from bzrlib.plugins.git.dir import (
151
            BareLocalGitControlDirFormat,
152
            LocalGitControlDirFormat,
153
            )
154
        if transport.has_any(['.git/objects']):
155
            return LocalGitControlDirFormat()
156
        if transport.has('info') and transport.has('objects'):
157
            return BareLocalGitControlDirFormat()
0.200.1399 by Jelmer Vernooij
In prober, always return or raise NotBranchError.
158
        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.
159
0.200.1139 by Jelmer Vernooij
Prober.known_formats is a class method.
160
    @classmethod
161
    def known_formats(cls):
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
162
        from bzrlib.plugins.git.dir import (
163
            BareLocalGitControlDirFormat,
164
            LocalGitControlDirFormat,
165
            )
166
        return set([BareLocalGitControlDirFormat(), LocalGitControlDirFormat()])
0.200.1032 by Jelmer Vernooij
Support bare repositories.
167
168
0.200.1014 by Jelmer Vernooij
Fix tests.
169
class RemoteGitProber(Prober):
170
0.200.1334 by Jelmer Vernooij
Detect smart servers.
171
    def probe_http_transport(self, transport):
172
        from bzrlib import urlutils
173
        url = urlutils.join(transport.external_url(), "info/refs") + "?service=git-upload-pack"
174
        from bzrlib.transport.http._urllib import HttpTransport_urllib, Request
175
        if isinstance(transport, HttpTransport_urllib):
176
            req = Request('GET', url, accepted_errors=[200, 403, 404, 405],
177
                          headers={"Content-Type": "application/x-git-upload-pack-request"})
178
            req.follow_redirections = True
179
            resp = transport._perform(req)
0.200.1471 by Jelmer Vernooij
ignore 405 replies when probing.
180
            if resp.code in (404, 405):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
181
                raise bzr_errors.NotBranchError(transport.base)
182
            headers = resp.headers
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
183
            refs_text = resp.read()
0.200.1334 by Jelmer Vernooij
Detect smart servers.
184
        else:
185
            try:
186
                from bzrlib.transport.http._pycurl import PyCurlTransport
187
            except bzr_errors.DependencyNotPresent:
188
                raise bzr_errors.NotBranchError(transport.base)
189
            else:
190
                import pycurl
191
                from cStringIO import StringIO
192
                if isinstance(transport, PyCurlTransport):
193
                    conn = transport._get_curl()
194
                    conn.setopt(pycurl.URL, url)
0.200.1445 by Jelmer Vernooij
Follow redirects for pycurl, too.
195
                    conn.setopt(pycurl.FOLLOWLOCATION, 1)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
196
                    transport._set_curl_options(conn)
197
                    conn.setopt(pycurl.HTTPGET, 1)
198
                    header = StringIO()
199
                    data = StringIO()
200
                    conn.setopt(pycurl.HEADERFUNCTION, header.write)
201
                    conn.setopt(pycurl.WRITEFUNCTION, data.write)
202
                    transport._curl_perform(conn, header,
203
                        ["Content-Type: application/x-git-upload-pack-request"])
204
                    code = conn.getinfo(pycurl.HTTP_CODE)
0.200.1471 by Jelmer Vernooij
ignore 405 replies when probing.
205
                    if code in (404, 405):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
206
                        raise bzr_errors.NotBranchError(transport.base)
0.268.1 by Jelmer Vernooij
Fix probing of http repositories when pycurl is used.
207
                    if code != 200:
208
                        raise bzr_errors.InvalidHttpResponse(transport._path,
209
                            str(code))
0.200.1334 by Jelmer Vernooij
Detect smart servers.
210
                    headers = transport._parse_headers(header)
211
                else:
212
                    raise bzr_errors.NotBranchError(transport.base)
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
213
                refs_text = data.getvalue()
0.200.1334 by Jelmer Vernooij
Detect smart servers.
214
        ct = headers.getheader("Content-Type")
0.200.1405 by Jelmer Vernooij
Add i18n support.
215
        if ct is None:
216
            raise bzr_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
217
        if ct.startswith("application/x-git"):
218
            from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
219
            return RemoteGitControlDirFormat()
220
        else:
221
            from bzrlib.plugins.git.dir import (
222
                BareLocalGitControlDirFormat,
223
                )
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
224
            ret = BareLocalGitControlDirFormat()
225
            ret._refs_text = refs_text
226
            return ret
0.200.1334 by Jelmer Vernooij
Detect smart servers.
227
0.200.1014 by Jelmer Vernooij
Fix tests.
228
    def probe_transport(self, transport):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
229
        try:
230
            external_url = transport.external_url()
231
        except bzr_errors.InProcessTransport:
232
            raise bzr_errors.NotBranchError(path=transport.base)
233
234
        if (external_url.startswith("http:") or
235
            external_url.startswith("https:")):
236
            return self.probe_http_transport(transport)
237
238
        if (not external_url.startswith("git://") and
239
            not external_url.startswith("git+")):
0.200.1014 by Jelmer Vernooij
Fix tests.
240
            raise bzr_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
241
0.200.1014 by Jelmer Vernooij
Fix tests.
242
        # little ugly, but works
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
243
        from bzrlib.plugins.git.remote import (
244
            GitSmartTransport,
245
            RemoteGitControlDirFormat,
246
            )
0.200.1334 by Jelmer Vernooij
Detect smart servers.
247
        if isinstance(transport, GitSmartTransport):
248
            return RemoteGitControlDirFormat()
249
        raise bzr_errors.NotBranchError(path=transport.base)
0.200.1014 by Jelmer Vernooij
Fix tests.
250
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
251
    @classmethod
0.200.1139 by Jelmer Vernooij
Prober.known_formats is a class method.
252
    def known_formats(cls):
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
253
        from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
254
        return set([RemoteGitControlDirFormat()])
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
255
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
256
0.200.1138 by Jelmer Vernooij
Support new Prober.known_formats() API.
257
if not getattr(Prober, "known_formats", None): # bzr < 2.4
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
258
    from bzrlib.plugins.git.dir import (
259
        LocalGitControlDirFormat, BareLocalGitControlDirFormat,
260
        )
261
    from bzrlib.plugins.git.remote import RemoteGitControlDirFormat
262
    ControlDirFormat.register_format(LocalGitControlDirFormat())
263
    ControlDirFormat.register_format(BareLocalGitControlDirFormat())
264
    ControlDirFormat.register_format(RemoteGitControlDirFormat())
0.200.1194 by Jelmer Vernooij
Use get_file_revision.
265
    # Provide RevisionTree.get_file_revision, so various parts of bzr-svn
266
    # can avoid inventories.
267
    from bzrlib.revisiontree import RevisionTree
268
    def get_file_revision(tree, file_id, path=None):
269
        return tree.inventory[file_id].revision
270
    RevisionTree.get_file_revision = get_file_revision
271
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
272
ControlDirFormat.register_prober(LocalGitProber)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
273
ControlDirFormat._server_probers.insert(0, RemoteGitProber)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
274
0.200.674 by Jelmer Vernooij
Fix formatting.
275
register_transport_proto('git://',
0.200.308 by Jelmer Vernooij
Register git protocols.
276
        help="Access using the Git smart server protocol.")
0.200.674 by Jelmer Vernooij
Fix formatting.
277
register_transport_proto('git+ssh://',
0.200.308 by Jelmer Vernooij
Register git protocols.
278
        help="Access using the Git smart server protocol over SSH.")
279
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
280
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
0.200.307 by Jelmer Vernooij
Support git+ssh.
281
                        'TCPGitSmartTransport')
282
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
283
                        'SSHGitSmartTransport')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
284
0.200.674 by Jelmer Vernooij
Fix formatting.
285
foreign_vcs_registry.register_lazy("git",
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
286
    "bzrlib.plugins.git.mapping", "foreign_vcs_git", "Stupid content tracker")
0.208.5 by Jelmer Vernooij
Add log show function for git.
287
0.200.206 by Jelmer Vernooij
Move commands to a separate python module and register them lazily.
288
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
0.200.674 by Jelmer Vernooij
Fix formatting.
289
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.
290
    "bzrlib.plugins.git.commands")
0.200.873 by Jelmer Vernooij
Add convenience command for accessing virtual git refs.
291
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
0.200.895 by Jelmer Vernooij
Add initial work on git-apply.
292
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
0.200.177 by Jelmer Vernooij
Add git-import command.
293
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
294
def extract_git_foreign_revid(rev):
295
    try:
296
        foreign_revid = rev.foreign_revid
297
    except AttributeError:
298
        from bzrlib.plugins.git.mapping import mapping_registry
299
        foreign_revid, mapping = \
300
            mapping_registry.parse_revision_id(rev.revision_id)
301
        return foreign_revid
302
    else:
303
        from bzrlib.plugins.git.mapping import foreign_vcs_git
304
        if rev.mapping.vcs == foreign_vcs_git:
305
            return foreign_revid
306
        else:
307
            raise bzr_errors.InvalidRevisionId(rev.revision_id, None)
308
309
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
310
def update_stanza(rev, stanza):
311
    mapping = getattr(rev, "mapping", None)
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
312
    try:
313
        git_commit = extract_git_foreign_revid(rev)
314
    except bzr_errors.InvalidRevisionId:
315
        pass
316
    else:
317
        stanza.add("git-commit", git_commit)
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
318
0.200.1088 by Jelmer Vernooij
When possible, lazily load hook points from version_info_format.format_rio.
319
try:
320
    from bzrlib.hooks import install_lazy_named_hook
321
except ImportError: # Compatibility with bzr < 2.4
322
    from bzrlib.version_info_formats.format_rio import (
323
        RioVersionInfoBuilder,
324
        )
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
325
    RioVersionInfoBuilder.hooks.install_named_hook('revision', update_stanza,
0.200.1088 by Jelmer Vernooij
When possible, lazily load hook points from version_info_format.format_rio.
326
        "git commits")
327
else:
328
    install_lazy_named_hook("bzrlib.version_info_formats.format_rio",
329
        "RioVersionInfoBuilder.hooks", "revision", update_stanza,
330
        "git commits")
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
331
0.200.531 by Jelmer Vernooij
Support 'bzr serve --git'.
332
0.239.6 by Jelmer Vernooij
Remove pre-1.15 incompatible code.
333
from bzrlib.transport import transport_server_registry
334
transport_server_registry.register_lazy('git',
0.200.674 by Jelmer Vernooij
Fix formatting.
335
    'bzrlib.plugins.git.server',
0.239.6 by Jelmer Vernooij
Remove pre-1.15 incompatible code.
336
    'serve_git',
337
    'Git Smart server protocol over TCP. (default port: 9418)')
0.200.531 by Jelmer Vernooij
Support 'bzr serve --git'.
338
339
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
340
from bzrlib.repository import (
0.200.1083 by Jelmer Vernooij
Register repository format.
341
    format_registry as repository_format_registry,
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
342
    network_format_registry as repository_network_format_registry,
343
    )
0.200.674 by Jelmer Vernooij
Fix formatting.
344
repository_network_format_registry.register_lazy('git',
0.200.536 by Jelmer Vernooij
Implement network name.
345
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
346
0.200.1024 by Jelmer Vernooij
Cope with network_format_registry moving.
347
try:
0.200.1083 by Jelmer Vernooij
Register repository format.
348
    register_extra_lazy_repository_format = getattr(repository_format_registry,
349
        "register_extra_lazy")
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
350
except AttributeError: # bzr < 2.4
0.200.1083 by Jelmer Vernooij
Register repository format.
351
    pass
352
else:
353
    register_extra_lazy_repository_format('bzrlib.plugins.git.repository',
354
        'GitRepositoryFormat')
355
0.200.1127 by Jelmer Vernooij
Register branch format network name.
356
from bzrlib.branch import (
357
    network_format_registry as branch_network_format_registry,
358
    )
359
branch_network_format_registry.register_lazy('git',
360
    'bzrlib.plugins.git.branch', 'GitBranchFormat')
361
0.200.1083 by Jelmer Vernooij
Register repository format.
362
try:
0.200.1090 by Jelmer Vernooij
Register branch format for testing.
363
    from bzrlib.branch import (
364
        format_registry as branch_format_registry,
365
        )
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
366
except ImportError: # bzr < 2.4
0.200.1090 by Jelmer Vernooij
Register branch format for testing.
367
    pass
368
else:
369
    branch_format_registry.register_extra_lazy(
370
        'bzrlib.plugins.git.branch',
371
        'GitBranchFormat',
372
        )
373
374
try:
0.200.1093 by Jelmer Vernooij
Register working tree format for testing.
375
    from bzrlib.workingtree import (
376
        format_registry as workingtree_format_registry,
377
        )
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
378
except ImportError: # bzr < 2.4
0.200.1093 by Jelmer Vernooij
Register working tree format for testing.
379
    pass
380
else:
381
    workingtree_format_registry.register_extra_lazy(
382
        'bzrlib.plugins.git.workingtree',
383
        'GitWorkingTreeFormat',
384
        )
385
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
386
controldir_network_format_registry.register_lazy('git',
387
    "bzrlib.plugins.git.dir", "GitControlDirFormat")
0.200.536 by Jelmer Vernooij
Implement network name.
388
0.238.1 by Lukas Lalinsky, Jelmer Vernooij
Import initial work on 'bzr send --format=git' based on luks' patch for bzr-svn.
389
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
390
                                   'send_git', 'Git am-style diff format')
391
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
392
topic_registry.register_lazy('git', 'bzrlib.plugins.git.help', 'help_git',
393
    'Using Bazaar with Git')
0.200.1011 by Jelmer Vernooij
Add some basic documentation in 'bzr help git'.
394
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
395
from bzrlib.diff import format_registry as diff_format_registry
396
diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
397
    'GitDiffTree', 'Git am-style diff format')
0.200.870 by Jelmer Vernooij
Support git-specific bzr diff option.
398
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
399
400
def update_git_cache(repository, revid):
401
    """Update the git cache after a local commit."""
402
    if getattr(repository, "_git", None) is not None:
403
        return # No need to update cache for git repositories
404
405
    if not repository.control_transport.has("git"):
406
        return # No existing cache, don't bother updating
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
407
    try:
408
        lazy_check_versions()
409
    except bzr_errors.DependencyNotPresent, e:
410
        # dulwich is probably missing. silently ignore
411
        trace.mutter("not updating git map for %r: %s",
412
            repository, e)
413
414
    from bzrlib.plugins.git.object_store import BazaarObjectStore
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
415
    store = BazaarObjectStore(repository)
416
    store.lock_write()
417
    try:
0.200.1319 by Jelmer Vernooij
Only update git cache during post-commit if parents are already in the cache.
418
        parent_revisions = set(repository.get_parent_map([revid])[revid])
419
        missing_revisions = store._missing_revisions(parent_revisions)
420
        if not missing_revisions:
421
            # Only update if the cache was up to date previously
422
            store._update_sha_map_revision(revid)
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
423
    finally:
424
        store.unlock()
425
426
427
def post_commit_update_cache(local_branch, master_branch, old_revno, old_revid,
428
        new_revno, new_revid):
429
    if local_branch is not None:
430
        update_git_cache(local_branch.repository, new_revid)
431
    update_git_cache(master_branch.repository, new_revid)
432
433
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
434
def loggerhead_git_hook(branch_app, environ):
435
    branch = branch_app.branch
436
    if branch.get_config().get_user_option('http_git') != 'True':
437
        return None
438
    from bzrlib.plugins.git.server import git_http_hook
439
    return git_http_hook(branch, environ['REQUEST_METHOD'],
440
        environ['PATH_INFO'])
441
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
442
try:
443
    from bzrlib.hooks import install_lazy_named_hook
444
except ImportError: # Compatibility with bzr < 2.4
445
    pass
446
else:
447
    install_lazy_named_hook("bzrlib.branch",
448
        "Branch.hooks", "post_commit", post_commit_update_cache,
449
        "git cache")
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
450
    install_lazy_named_hook("bzrlib.plugins.loggerhead.apps.branch",
451
        "BranchWSGIApp.hooks", "controller",
452
        loggerhead_git_hook, "git support")
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
453
454
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
455
def test_suite():
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
456
    from bzrlib.plugins.git import tests
457
    return tests.test_suite()