/brz/remove-bazaar

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