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