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