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