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