/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")
7411.1.1 by Jelmer Vernooij
Fix support for reading from a dumb git server.
183
        if ct and 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()
7413.4.1 by Jelmer Vernooij
Don't assume that if something returns a 200, it's going to be okay.
186
        elif not ct:
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
7413.4.1 by Jelmer Vernooij
Don't assume that if something returns a 200, it's going to be okay.
193
        raise brz_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
194
0.200.1014 by Jelmer Vernooij
Fix tests.
195
    def probe_transport(self, transport):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
196
        try:
197
            external_url = transport.external_url()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
198
        except brz_errors.InProcessTransport:
199
            raise brz_errors.NotBranchError(path=transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
200
201
        if (external_url.startswith("http:") or
7143.15.2 by Jelmer Vernooij
Run autopep8.
202
                external_url.startswith("https:")):
0.200.1334 by Jelmer Vernooij
Detect smart servers.
203
            return self.probe_http_transport(transport)
204
205
        if (not external_url.startswith("git://") and
7143.15.2 by Jelmer Vernooij
Run autopep8.
206
                not external_url.startswith("git+")):
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
207
            raise brz_errors.NotBranchError(transport.base)
0.200.1334 by Jelmer Vernooij
Detect smart servers.
208
0.200.1014 by Jelmer Vernooij
Fix tests.
209
        # little ugly, but works
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
210
        from .remote import (
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
211
            GitSmartTransport,
212
            RemoteGitControlDirFormat,
213
            )
0.200.1334 by Jelmer Vernooij
Detect smart servers.
214
        if isinstance(transport, GitSmartTransport):
215
            return RemoteGitControlDirFormat()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
216
        raise brz_errors.NotBranchError(path=transport.base)
0.200.1014 by Jelmer Vernooij
Fix tests.
217
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
218
    @classmethod
0.200.1139 by Jelmer Vernooij
Prober.known_formats is a class method.
219
    def known_formats(cls):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
220
        from .remote import RemoteGitControlDirFormat
6973.12.9 by Jelmer Vernooij
More fixes.
221
        return [RemoteGitControlDirFormat()]
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
222
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
223
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
224
ControlDirFormat.register_prober(LocalGitProber)
0.200.1556 by Jelmer Vernooij
Add 'github:' directory service.
225
ControlDirFormat._server_probers.append(RemoteGitProber)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
226
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
227
register_transport_proto(
228
    'git://', help="Access using the Git smart server protocol.")
229
register_transport_proto(
230
    'git+ssh://',
231
    help="Access using the Git smart server protocol over SSH.")
0.200.308 by Jelmer Vernooij
Register git protocols.
232
0.200.1645 by Jelmer Vernooij
Use __name__.
233
register_lazy_transport("git://", __name__ + '.remote',
0.200.307 by Jelmer Vernooij
Support git+ssh.
234
                        'TCPGitSmartTransport')
0.200.1645 by Jelmer Vernooij
Use __name__.
235
register_lazy_transport("git+ssh://", __name__ + '.remote',
0.200.307 by Jelmer Vernooij
Support git+ssh.
236
                        'SSHGitSmartTransport')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
237
0.208.5 by Jelmer Vernooij
Add log show function for git.
238
0.200.1645 by Jelmer Vernooij
Use __name__.
239
plugin_cmds.register_lazy("cmd_git_import", [], __name__ + ".commands")
0.200.674 by Jelmer Vernooij
Fix formatting.
240
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
241
                          __name__ + ".commands")
0.200.1645 by Jelmer Vernooij
Use __name__.
242
plugin_cmds.register_lazy("cmd_git_refs", [], __name__ + ".commands")
243
plugin_cmds.register_lazy("cmd_git_apply", [], __name__ + ".commands")
0.277.6 by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command.
244
plugin_cmds.register_lazy("cmd_git_push_pristine_tar_deltas",
7143.15.2 by Jelmer Vernooij
Run autopep8.
245
                          ['git-push-pristine-tar', 'git-push-pristine'],
246
                          __name__ + ".commands")
247
0.200.177 by Jelmer Vernooij
Add git-import command.
248
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
249
def extract_git_foreign_revid(rev):
250
    try:
251
        foreign_revid = rev.foreign_revid
252
    except AttributeError:
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
253
        from .mapping import mapping_registry
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
254
        foreign_revid, mapping = \
255
            mapping_registry.parse_revision_id(rev.revision_id)
256
        return foreign_revid
257
    else:
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
258
        from .mapping import foreign_vcs_git
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
259
        if rev.mapping.vcs == foreign_vcs_git:
260
            return foreign_revid
261
        else:
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
262
            raise brz_errors.InvalidRevisionId(rev.revision_id, None)
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
263
264
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
265
def update_stanza(rev, stanza):
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
266
    try:
267
        git_commit = extract_git_foreign_revid(rev)
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
268
    except brz_errors.InvalidRevisionId:
0.200.1262 by Jelmer Vernooij
Add extract git foreign revid.
269
        pass
270
    else:
271
        stanza.add("git-commit", git_commit)
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
272
7143.15.2 by Jelmer Vernooij
Run autopep8.
273
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
274
from ..hooks import install_lazy_named_hook
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
275
install_lazy_named_hook(
276
    "breezy.version_info_formats.format_rio",
277
    "RioVersionInfoBuilder.hooks", "revision", update_stanza,
278
    "git commits")
279
280
transport_server_registry.register_lazy(
281
    'git', __name__ + '.server', 'serve_git',
282
    'Git Smart server protocol over TCP. (default port: 9418)')
283
284
transport_server_registry.register_lazy(
285
    'git-receive-pack', __name__ + '.server',
286
    'serve_git_receive_pack',
287
    help='Git Smart server receive pack command. (inetd mode only)')
288
transport_server_registry.register_lazy(
289
    'git-upload-pack', __name__ + 'git.server',
290
    'serve_git_upload_pack',
291
    help='Git Smart server upload pack command. (inetd mode only)')
0.200.531 by Jelmer Vernooij
Support 'bzr serve --git'.
292
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
293
from ..repository import (
0.200.1083 by Jelmer Vernooij
Register repository format.
294
    format_registry as repository_format_registry,
0.200.926 by Jelmer Vernooij
Fix formatting, drop support for Bazaar < 2.0.
295
    network_format_registry as repository_network_format_registry,
296
    )
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
297
repository_network_format_registry.register_lazy(
298
    b'git', __name__ + '.repository', 'GitRepositoryFormat')
0.200.536 by Jelmer Vernooij
Implement network name.
299
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
300
register_extra_lazy_repository_format = getattr(repository_format_registry,
7143.15.2 by Jelmer Vernooij
Run autopep8.
301
                                                "register_extra_lazy")
0.200.1645 by Jelmer Vernooij
Use __name__.
302
register_extra_lazy_repository_format(__name__ + '.repository',
7143.15.2 by Jelmer Vernooij
Run autopep8.
303
                                      'GitRepositoryFormat')
0.200.1083 by Jelmer Vernooij
Register repository format.
304
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
305
from ..branch import (
0.200.1127 by Jelmer Vernooij
Register branch format network name.
306
    network_format_registry as branch_network_format_registry,
307
    )
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
308
branch_network_format_registry.register_lazy(
309
    b'git', __name__ + '.branch', 'LocalGitBranchFormat')
0.295.1 by Jelmer Vernooij
Split up branch formats.
310
0.200.1127 by Jelmer Vernooij
Register branch format network name.
311
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
312
from ..branch import (
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
313
    format_registry as branch_format_registry,
314
    )
315
branch_format_registry.register_extra_lazy(
0.200.1645 by Jelmer Vernooij
Use __name__.
316
    __name__ + '.branch',
0.295.1 by Jelmer Vernooij
Split up branch formats.
317
    'LocalGitBranchFormat',
318
    )
319
branch_format_registry.register_extra_lazy(
320
    __name__ + '.remote',
321
    'RemoteGitBranchFormat',
322
    )
323
0.200.1090 by Jelmer Vernooij
Register branch format for testing.
324
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
325
from ..workingtree import (
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
326
    format_registry as workingtree_format_registry,
327
    )
328
workingtree_format_registry.register_extra_lazy(
0.200.1645 by Jelmer Vernooij
Use __name__.
329
    __name__ + '.workingtree',
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
330
    'GitWorkingTreeFormat',
331
    )
0.200.1093 by Jelmer Vernooij
Register working tree format for testing.
332
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
333
controldir_network_format_registry.register_lazy(
334
    b'git', __name__ + ".dir", "GitControlDirFormat")
0.200.536 by Jelmer Vernooij
Implement network name.
335
0.276.1 by Jelmer Vernooij
Use register_lazy.
336
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
337
from ..diff import format_registry as diff_format_registry
7143.16.10 by Jelmer Vernooij
Fix E128.
338
diff_format_registry.register_lazy(
339
    'git', __name__ + '.send',
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
340
    'GitDiffTree', 'Git am-style diff format')
341
342
from ..send import (
343
    format_registry as send_format_registry,
344
    )
345
send_format_registry.register_lazy('git', __name__ + '.send',
346
                                   'send_git', 'Git am-style diff format')
347
348
from ..directory_service import directories
349
directories.register_lazy('github:', __name__ + '.directory',
350
                          'GitHubDirectory',
351
                          'GitHub directory.')
352
directories.register_lazy('git@github.com:', __name__ + '.directory',
353
                          'GitHubDirectory',
354
                          'GitHub directory.')
355
356
from ..help_topics import (
357
    topic_registry,
358
    )
7143.16.10 by Jelmer Vernooij
Fix E128.
359
topic_registry.register_lazy(
360
    'git', __name__ + '.help', 'help_git', 'Using Bazaar with Git')
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
361
362
from ..foreign import (
363
    foreign_vcs_registry,
364
    )
7143.16.10 by Jelmer Vernooij
Fix E128.
365
foreign_vcs_registry.register_lazy(
366
    "git", __name__ + ".mapping", "foreign_vcs_git", "Stupid content tracker")
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
367
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
368
369
def update_git_cache(repository, revid):
370
    """Update the git cache after a local commit."""
371
    if getattr(repository, "_git", None) is not None:
7143.15.2 by Jelmer Vernooij
Run autopep8.
372
        return  # No need to update cache for git repositories
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
373
374
    if not repository.control_transport.has("git"):
7143.15.2 by Jelmer Vernooij
Run autopep8.
375
        return  # No existing cache, don't bother updating
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
376
    try:
377
        lazy_check_versions()
7143.7.1 by Jelmer Vernooij
Simplify brz-git, drop imports.
378
    except brz_errors.DependencyNotPresent as e:
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
379
        # dulwich is probably missing. silently ignore
380
        trace.mutter("not updating git map for %r: %s",
7143.15.2 by Jelmer Vernooij
Run autopep8.
381
                     repository, e)
0.200.1384 by Jelmer Vernooij
Skip post commit hook when dulwich is not installed.
382
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
383
    from .object_store import BazaarObjectStore
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
384
    store = BazaarObjectStore(repository)
0.200.1788 by Jelmer Vernooij
Use context managers.
385
    with store.lock_write():
0.200.1583 by Jelmer Vernooij
Use config stacks.
386
        try:
387
            parent_revisions = set(repository.get_parent_map([revid])[revid])
388
        except KeyError:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
389
            # Isn't this a bit odd - how can a revision that was just committed
390
            # be missing?
0.200.1583 by Jelmer Vernooij
Use config stacks.
391
            return
0.200.1319 by Jelmer Vernooij
Only update git cache during post-commit if parents are already in the cache.
392
        missing_revisions = store._missing_revisions(parent_revisions)
393
        if not missing_revisions:
6962.1.1 by Jelmer Vernooij
Fix handling cache updates in bzr-based index formats.
394
            store._cache.idmap.start_write_group()
395
            try:
396
                # Only update if the cache was up to date previously
397
                store._update_sha_map_revision(revid)
398
            except BaseException:
399
                store._cache.idmap.abort_write_group()
400
                raise
401
            else:
402
                store._cache.idmap.commit_write_group()
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
403
404
405
def post_commit_update_cache(local_branch, master_branch, old_revno, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
406
                             new_revno, new_revid):
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
407
    if local_branch is not None:
408
        update_git_cache(local_branch.repository, new_revid)
409
    update_git_cache(master_branch.repository, new_revid)
410
411
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
412
def loggerhead_git_hook(branch_app, environ):
413
    branch = branch_app.branch
0.200.1583 by Jelmer Vernooij
Use config stacks.
414
    config_stack = branch.get_config_stack()
415
    if config_stack.get('http_git'):
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
416
        return None
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
417
    from .server import git_http_hook
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
418
    return git_http_hook(branch, environ['REQUEST_METHOD'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
419
                         environ['PATH_INFO'])
420
0.271.5 by Jelmer Vernooij
Hook into loggerhead.
421
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
422
install_lazy_named_hook("breezy.branch",
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
423
                        "Branch.hooks", "post_commit",
424
                        post_commit_update_cache, "git cache")
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
425
install_lazy_named_hook("breezy.plugins.loggerhead.apps.branch",
7143.15.2 by Jelmer Vernooij
Run autopep8.
426
                        "BranchWSGIApp.hooks", "controller",
427
                        loggerhead_git_hook, "git support")
0.200.1291 by Jelmer Vernooij
add hook for updating to local git cache.
428
429
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
430
from ..config import (
0.200.1583 by Jelmer Vernooij
Use config stacks.
431
    option_registry,
432
    Option,
433
    bool_from_store,
434
    )
435
436
option_registry.register(
437
    Option('git.http',
438
           default=None, from_unicode=bool_from_store, invalid='warning',
439
           help='''\
440
Allow fetching of Git packs over HTTP.
441
442
This enables support for fetching Git packs over HTTP in Loggerhead.
443
'''))
444
7143.15.2 by Jelmer Vernooij
Run autopep8.
445
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
446
def test_suite():
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
447
    from . import tests
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
448
    return tests.test_suite()