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