/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
7286.1.1 by Jelmer Vernooij
Bump minimum dulwich version to 0.19.11.
30
dulwich_minimum_version = (0, 19, 11)
6883.23.1 by Jelmer Vernooij
bundle brz-git plugin.
31
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
32
from .. import (  # noqa: F401
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.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
36
    version_info,
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.15.6 by Jelmer Vernooij
Merge trunk.
66
        raise brz_errors.DependencyNotPresent(
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
67
            "dulwich",
68
            "bzr-git: Please install dulwich, https://www.dulwich.io/")
0.200.200 by Jelmer Vernooij
Register lazily where possible.
69
    else:
0.200.583 by Jelmer Vernooij
Add plugin api info.
70
        if dulwich_version < dulwich_minimum_version:
7143.15.6 by Jelmer Vernooij
Merge trunk.
71
            raise brz_errors.DependencyNotPresent(
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
72
                "dulwich",
73
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
74
                dulwich_minimum_version)
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
75
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
76
77
_versions_checked = False
7143.15.2 by Jelmer Vernooij
Run autopep8.
78
79
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
80
def lazy_check_versions():
81
    global _versions_checked
82
    if _versions_checked:
83
        return
84
    import_dulwich()
85
    _versions_checked = True
86
7143.15.2 by Jelmer Vernooij
Run autopep8.
87
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
88
format_registry.register_lazy(
89
    'git', __name__ + ".dir", "LocalGitControlDirFormat",
90
    help='GIT repository.', native=False, experimental=False)
0.200.204 by Jelmer Vernooij
Support bzr 1.11.
91
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
92
format_registry.register_lazy(
93
    'git-bare', __name__ + ".dir", "BareLocalGitControlDirFormat",
94
    help='Bare GIT repository (no working tree).', native=False,
95
    experimental=False)
0.200.1032 by Jelmer Vernooij
Support bare repositories.
96
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
97
from ..revisionspec import (RevisionSpec_dwim, revspec_registry)
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
98
revspec_registry.register_lazy("git:", __name__ + ".revspec",
7143.15.2 by Jelmer Vernooij
Run autopep8.
99
                               "RevisionSpec_git")
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
100
RevisionSpec_dwim.append_possible_lazy_revspec(
0.200.1649 by Jelmer Vernooij
Fix imports.
101
    __name__ + ".revspec", "RevisionSpec_git")
0.200.645 by Jelmer Vernooij
Support DWIM git: revspecs.
102
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
103
0.200.1014 by Jelmer Vernooij
Fix tests.
104
class LocalGitProber(Prober):
105
106
    def probe_transport(self, transport):
0.200.720 by Jelmer Vernooij
Avoid loading bzr-git/dulwich when not necessary.
107
        try:
0.268.1 by Jelmer Vernooij
Fix probing of http repositories when pycurl is used.
108
            external_url = transport.external_url()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
109
        except brz_errors.InProcessTransport:
110
            raise brz_errors.NotBranchError(path=transport.base)
0.268.1 by Jelmer Vernooij
Fix probing of http repositories when pycurl is used.
111
        if (external_url.startswith("http:") or
7143.15.2 by Jelmer Vernooij
Run autopep8.
112
                external_url.startswith("https:")):
0.268.1 by Jelmer Vernooij
Fix probing of http repositories when pycurl is used.
113
            # Already handled by RemoteGitProber
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
114
            raise brz_errors.NotBranchError(path=transport.base)
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
115
        from .. import urlutils
0.200.730 by Jelmer Vernooij
Don't claim control directories can be accessed directly, always open the
116
        if urlutils.split(transport.base)[1] == ".git":
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
117
            raise brz_errors.NotBranchError(path=transport.base)
0.398.1 by Jelmer Vernooij
Support reading .git files.
118
        if not transport.has_any(['objects', '.git/objects', '.git']):
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
119
            raise brz_errors.NotBranchError(path=transport.base)
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
120
        lazy_check_versions()
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
121
        from .dir import (
0.200.1387 by Jelmer Vernooij
Avoid using HEAD.
122
            BareLocalGitControlDirFormat,
123
            LocalGitControlDirFormat,
124
            )
0.398.1 by Jelmer Vernooij
Support reading .git files.
125
        if transport.has_any(['.git/objects', '.git']):
0.200.1387 by Jelmer Vernooij
Avoid using HEAD.
126
            return LocalGitControlDirFormat()
127
        if transport.has('info') and transport.has('objects'):
128
            return BareLocalGitControlDirFormat()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
129
        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.
130
0.200.1139 by Jelmer Vernooij
Prober.known_formats is a class method.
131
    @classmethod
132
    def known_formats(cls):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
133
        from .dir import (
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
134
            BareLocalGitControlDirFormat,
135
            LocalGitControlDirFormat,
136
            )
6973.12.9 by Jelmer Vernooij
More fixes.
137
        return [BareLocalGitControlDirFormat(), LocalGitControlDirFormat()]
0.200.1032 by Jelmer Vernooij
Support bare repositories.
138
139
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
140
def user_agent_for_github():
141
    # GitHub requires we lie. https://github.com/dulwich/dulwich/issues/562
142
    return "git/Breezy/%s" % breezy_version
143
144
0.200.1014 by Jelmer Vernooij
Fix tests.
145
class RemoteGitProber(Prober):
146
0.200.1334 by Jelmer Vernooij
Detect smart servers.
147
    def probe_http_transport(self, transport):
7268.10.4 by Jelmer Vernooij
Add note about imports.
148
        # This function intentionally doesn't use any of the support code under
149
        # breezy.git, since it's called for every repository that's
150
        # accessed over HTTP, whether it's Git, Bzr or something else.
151
        # Importing Dulwich and the other support code adds unnecessray slowdowns.
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
152
        from .. import urlutils
7143.15.2 by Jelmer Vernooij
Run autopep8.
153
        base_url, _ = urlutils.split_segment_parameters(
154
            transport.external_url())
7268.10.1 by Jelmer Vernooij
Strip username from URL.
155
        url = urlutils.URL.from_string(base_url)
156
        url.user = url.quoted_user = None
157
        url.password = url.quoted_password = None
158
        url = urlutils.join(str(url), "info/refs") + "?service=git-upload-pack"
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
159
        from ..transport.http import Request
7096.1.2 by Jelmer Vernooij
Fix redirection handling for git.
160
        headers = {"Content-Type": "application/x-git-upload-pack-request",
161
                   "Accept": "application/x-git-upload-pack-result",
162
                   }
7143.15.2 by Jelmer Vernooij
Run autopep8.
163
        (scheme, user, password, host, port,
7296.2.2 by Jelmer Vernooij
Add a urllib3-like interface.
164
         path) = urlutils.parse_url(url)
6973.11.6 by Jelmer Vernooij
Fix more http tests.
165
        if host == "github.com":
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
166
            # GitHub requires we lie.
167
            # https://github.com/dulwich/dulwich/issues/562
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
168
            req.add_header("User-Agent", user_agent_for_github())
6973.11.6 by Jelmer Vernooij
Fix more http tests.
169
        elif host == "bazaar.launchpad.net":
0.368.1 by Jelmer Vernooij
Work around bazaar.launchpad.net incorrectly responding to Git requests.
170
            # Don't attempt Git probes against bazaar.launchpad.net; pad.lv/1744830
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
171
            raise brz_errors.NotBranchError(transport.base)
7296.2.2 by Jelmer Vernooij
Add a urllib3-like interface.
172
        resp = transport.request('GET', url, headers=headers)
173
        if resp.status in (404, 405):
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
174
            raise brz_errors.NotBranchError(transport.base)
7296.2.2 by Jelmer Vernooij
Add a urllib3-like interface.
175
        else:
176
            raise errors.InvalidHttpResponse(
177
                url, 'Unable to handle http code %d' % resp.status)
178
0.200.1726 by Jelmer Vernooij
Use urllib exclusively.
179
        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.
180
        ct = headers.get("Content-Type")
0.200.1405 by Jelmer Vernooij
Add i18n support.
181
        if ct is None:
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
182
            raise brz_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
183
        if ct.startswith("application/x-git"):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
184
            from .remote import RemoteGitControlDirFormat
0.200.1334 by Jelmer Vernooij
Detect smart servers.
185
            return RemoteGitControlDirFormat()
186
        else:
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
187
            from .dir import (
0.200.1334 by Jelmer Vernooij
Detect smart servers.
188
                BareLocalGitControlDirFormat,
189
                )
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
190
            ret = BareLocalGitControlDirFormat()
0.200.1726 by Jelmer Vernooij
Use urllib exclusively.
191
            ret._refs_text = resp.read()
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
192
            return ret
0.200.1334 by Jelmer Vernooij
Detect smart servers.
193
0.200.1014 by Jelmer Vernooij
Fix tests.
194
    def probe_transport(self, transport):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
195
        try:
196
            external_url = transport.external_url()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
197
        except brz_errors.InProcessTransport:
198
            raise brz_errors.NotBranchError(path=transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
199
200
        if (external_url.startswith("http:") or
7143.15.2 by Jelmer Vernooij
Run autopep8.
201
                external_url.startswith("https:")):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
202
            return self.probe_http_transport(transport)
203
204
        if (not external_url.startswith("git://") and
7143.15.2 by Jelmer Vernooij
Run autopep8.
205
                not external_url.startswith("git+")):
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
206
            raise brz_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
207
0.200.1014 by Jelmer Vernooij
Fix tests.
208
        # little ugly, but works
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
209
        from .remote import (
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
210
            GitSmartTransport,
211
            RemoteGitControlDirFormat,
212
            )
0.200.1334 by Jelmer Vernooij
Detect smart servers.
213
        if isinstance(transport, GitSmartTransport):
214
            return RemoteGitControlDirFormat()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
215
        raise brz_errors.NotBranchError(path=transport.base)
0.200.1014 by Jelmer Vernooij
Fix tests.
216
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
217
    @classmethod
0.200.1139 by Jelmer Vernooij
Prober.known_formats is a class method.
218
    def known_formats(cls):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
219
        from .remote import RemoteGitControlDirFormat
6973.12.9 by Jelmer Vernooij
More fixes.
220
        return [RemoteGitControlDirFormat()]
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
221
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
222
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
223
ControlDirFormat.register_prober(LocalGitProber)
0.200.1556 by Jelmer Vernooij
Add 'github:' directory service.
224
ControlDirFormat._server_probers.append(RemoteGitProber)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
225
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
226
register_transport_proto(
227
    'git://', help="Access using the Git smart server protocol.")
228
register_transport_proto(
229
    'git+ssh://',
230
    help="Access using the Git smart server protocol over SSH.")
0.200.308 by Jelmer Vernooij
Register git protocols.
231
0.200.1645 by Jelmer Vernooij
Use __name__.
232
register_lazy_transport("git://", __name__ + '.remote',
0.200.307 by Jelmer Vernooij
Support git+ssh.
233
                        'TCPGitSmartTransport')
0.200.1645 by Jelmer Vernooij
Use __name__.
234
register_lazy_transport("git+ssh://", __name__ + '.remote',
0.200.307 by Jelmer Vernooij
Support git+ssh.
235
                        'SSHGitSmartTransport')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
236
0.208.5 by Jelmer Vernooij
Add log show function for git.
237
0.200.1645 by Jelmer Vernooij
Use __name__.
238
plugin_cmds.register_lazy("cmd_git_import", [], __name__ + ".commands")
0.200.674 by Jelmer Vernooij
Fix formatting.
239
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
240
                          __name__ + ".commands")
0.200.1645 by Jelmer Vernooij
Use __name__.
241
plugin_cmds.register_lazy("cmd_git_refs", [], __name__ + ".commands")
242
plugin_cmds.register_lazy("cmd_git_apply", [], __name__ + ".commands")
0.277.6 by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command.
243
plugin_cmds.register_lazy("cmd_git_push_pristine_tar_deltas",
7143.15.2 by Jelmer Vernooij
Run autopep8.
244
                          ['git-push-pristine-tar', 'git-push-pristine'],
245
                          __name__ + ".commands")
246
0.200.177 by Jelmer Vernooij
Add git-import command.
247
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
248
def extract_git_foreign_revid(rev):
249
    try:
250
        foreign_revid = rev.foreign_revid
251
    except AttributeError:
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
252
        from .mapping import mapping_registry
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
253
        foreign_revid, mapping = \
254
            mapping_registry.parse_revision_id(rev.revision_id)
255
        return foreign_revid
256
    else:
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
257
        from .mapping import foreign_vcs_git
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
258
        if rev.mapping.vcs == foreign_vcs_git:
259
            return foreign_revid
260
        else:
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
261
            raise brz_errors.InvalidRevisionId(rev.revision_id, None)
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
262
263
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
264
def update_stanza(rev, stanza):
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
265
    try:
266
        git_commit = extract_git_foreign_revid(rev)
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
267
    except brz_errors.InvalidRevisionId:
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
268
        pass
269
    else:
270
        stanza.add("git-commit", git_commit)
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
271
7143.15.2 by Jelmer Vernooij
Run autopep8.
272
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
273
from ..hooks import install_lazy_named_hook
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
274
install_lazy_named_hook(
275
    "breezy.version_info_formats.format_rio",
276
    "RioVersionInfoBuilder.hooks", "revision", update_stanza,
277
    "git commits")
278
279
transport_server_registry.register_lazy(
280
    'git', __name__ + '.server', 'serve_git',
281
    'Git Smart server protocol over TCP. (default port: 9418)')
282
283
transport_server_registry.register_lazy(
284
    'git-receive-pack', __name__ + '.server',
285
    'serve_git_receive_pack',
286
    help='Git Smart server receive pack command. (inetd mode only)')
287
transport_server_registry.register_lazy(
288
    'git-upload-pack', __name__ + 'git.server',
289
    'serve_git_upload_pack',
290
    help='Git Smart server upload pack command. (inetd mode only)')
0.200.531 by Jelmer Vernooij
Support 'bzr serve --git'.
291
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
292
from ..repository import (
0.200.1083 by Jelmer Vernooij
Register repository format.
293
    format_registry as repository_format_registry,
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
294
    network_format_registry as repository_network_format_registry,
295
    )
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
296
repository_network_format_registry.register_lazy(
297
    b'git', __name__ + '.repository', 'GitRepositoryFormat')
0.200.536 by Jelmer Vernooij
Implement network name.
298
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
299
register_extra_lazy_repository_format = getattr(repository_format_registry,
7143.15.2 by Jelmer Vernooij
Run autopep8.
300
                                                "register_extra_lazy")
0.200.1645 by Jelmer Vernooij
Use __name__.
301
register_extra_lazy_repository_format(__name__ + '.repository',
7143.15.2 by Jelmer Vernooij
Run autopep8.
302
                                      'GitRepositoryFormat')
0.200.1083 by Jelmer Vernooij
Register repository format.
303
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
304
from ..branch import (
0.200.1127 by Jelmer Vernooij
Register branch format network name.
305
    network_format_registry as branch_network_format_registry,
306
    )
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
307
branch_network_format_registry.register_lazy(
308
    b'git', __name__ + '.branch', 'LocalGitBranchFormat')
0.295.1 by Jelmer Vernooij
Split up branch formats.
309
0.200.1127 by Jelmer Vernooij
Register branch format network name.
310
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
311
from ..branch import (
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
312
    format_registry as branch_format_registry,
313
    )
314
branch_format_registry.register_extra_lazy(
0.200.1645 by Jelmer Vernooij
Use __name__.
315
    __name__ + '.branch',
0.295.1 by Jelmer Vernooij
Split up branch formats.
316
    'LocalGitBranchFormat',
317
    )
318
branch_format_registry.register_extra_lazy(
319
    __name__ + '.remote',
320
    'RemoteGitBranchFormat',
321
    )
322
0.200.1090 by Jelmer Vernooij
Register branch format for testing.
323
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
324
from ..workingtree import (
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
325
    format_registry as workingtree_format_registry,
326
    )
327
workingtree_format_registry.register_extra_lazy(
0.200.1645 by Jelmer Vernooij
Use __name__.
328
    __name__ + '.workingtree',
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
329
    'GitWorkingTreeFormat',
330
    )
0.200.1093 by Jelmer Vernooij
Register working tree format for testing.
331
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
332
controldir_network_format_registry.register_lazy(
333
    b'git', __name__ + ".dir", "GitControlDirFormat")
0.200.536 by Jelmer Vernooij
Implement network name.
334
0.276.1 by Jelmer Vernooij
Use register_lazy.
335
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
336
from ..diff import format_registry as diff_format_registry
7143.16.10 by Jelmer Vernooij
Fix E128.
337
diff_format_registry.register_lazy(
338
    'git', __name__ + '.send',
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
339
    'GitDiffTree', 'Git am-style diff format')
340
341
from ..send import (
342
    format_registry as send_format_registry,
343
    )
344
send_format_registry.register_lazy('git', __name__ + '.send',
345
                                   'send_git', 'Git am-style diff format')
346
347
from ..directory_service import directories
348
directories.register_lazy('github:', __name__ + '.directory',
349
                          'GitHubDirectory',
350
                          'GitHub directory.')
351
directories.register_lazy('git@github.com:', __name__ + '.directory',
352
                          'GitHubDirectory',
353
                          'GitHub directory.')
354
355
from ..help_topics import (
356
    topic_registry,
357
    )
7143.16.10 by Jelmer Vernooij
Fix E128.
358
topic_registry.register_lazy(
359
    'git', __name__ + '.help', 'help_git', 'Using Bazaar with Git')
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
360
361
from ..foreign import (
362
    foreign_vcs_registry,
363
    )
7143.16.10 by Jelmer Vernooij
Fix E128.
364
foreign_vcs_registry.register_lazy(
365
    "git", __name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
366
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
367
368
def update_git_cache(repository, revid):
369
    """Update the git cache after a local commit."""
370
    if getattr(repository, "_git", None) is not None:
7143.15.2 by Jelmer Vernooij
Run autopep8.
371
        return  # No need to update cache for git repositories
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
372
373
    if not repository.control_transport.has("git"):
7143.15.2 by Jelmer Vernooij
Run autopep8.
374
        return  # No existing cache, don't bother updating
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
375
    try:
376
        lazy_check_versions()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
377
    except brz_errors.DependencyNotPresent as e:
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
378
        # dulwich is probably missing. silently ignore
379
        trace.mutter("not updating git map for %r: %s",
7143.15.2 by Jelmer Vernooij
Run autopep8.
380
                     repository, e)
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
381
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
382
    from .object_store import BazaarObjectStore
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
383
    store = BazaarObjectStore(repository)
0.200.1788 by Jelmer Vernooij
Use context managers.
384
    with store.lock_write():
0.200.1583 by Jelmer Vernooij
Use config stacks.
385
        try:
386
            parent_revisions = set(repository.get_parent_map([revid])[revid])
387
        except KeyError:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
388
            # Isn't this a bit odd - how can a revision that was just committed
389
            # be missing?
0.200.1583 by Jelmer Vernooij
Use config stacks.
390
            return
0.200.1319 by Jelmer Vernooij
Only update git cache during post-commit if parents are already in the cache.
391
        missing_revisions = store._missing_revisions(parent_revisions)
392
        if not missing_revisions:
6962.1.1 by Jelmer Vernooij
Fix handling cache updates in bzr-based index formats.
393
            store._cache.idmap.start_write_group()
394
            try:
395
                # Only update if the cache was up to date previously
396
                store._update_sha_map_revision(revid)
397
            except BaseException:
398
                store._cache.idmap.abort_write_group()
399
                raise
400
            else:
401
                store._cache.idmap.commit_write_group()
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
402
403
404
def post_commit_update_cache(local_branch, master_branch, old_revno, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
405
                             new_revno, new_revid):
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
406
    if local_branch is not None:
407
        update_git_cache(local_branch.repository, new_revid)
408
    update_git_cache(master_branch.repository, new_revid)
409
410
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
411
def loggerhead_git_hook(branch_app, environ):
412
    branch = branch_app.branch
0.200.1583 by Jelmer Vernooij
Use config stacks.
413
    config_stack = branch.get_config_stack()
414
    if config_stack.get('http_git'):
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
415
        return None
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
416
    from .server import git_http_hook
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
417
    return git_http_hook(branch, environ['REQUEST_METHOD'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
418
                         environ['PATH_INFO'])
419
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
420
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
421
install_lazy_named_hook("breezy.branch",
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
422
                        "Branch.hooks", "post_commit",
423
                        post_commit_update_cache, "git cache")
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
424
install_lazy_named_hook("breezy.plugins.loggerhead.apps.branch",
7143.15.2 by Jelmer Vernooij
Run autopep8.
425
                        "BranchWSGIApp.hooks", "controller",
426
                        loggerhead_git_hook, "git support")
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
427
428
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
429
from ..config import (
0.200.1583 by Jelmer Vernooij
Use config stacks.
430
    option_registry,
431
    Option,
432
    bool_from_store,
433
    )
434
435
option_registry.register(
436
    Option('git.http',
437
           default=None, from_unicode=bool_from_store, invalid='warning',
438
           help='''\
439
Allow fetching of Git packs over HTTP.
440
441
This enables support for fetching Git packs over HTTP in Loggerhead.
442
'''))
443
7143.15.2 by Jelmer Vernooij
Run autopep8.
444
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
445
def test_suite():
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
446
    from . import tests
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
447
    return tests.test_suite()