/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.235 by Jelmer Vernooij
Depend on newer dulwich.
1
# Copyright (C) 2006-2009 Canonical Ltd
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
2
0.200.1 by Robert Collins
Commit initial content.
3
# Authors: Robert Collins <robert.collins@canonical.com>
0.200.184 by Jelmer Vernooij
Update authors: line.
4
#          Jelmer Vernooij <jelmer@samba.org>
5
#          John Carr <john.carr@unrouted.co.uk>
0.200.1 by Robert Collins
Commit initial content.
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21
22
"""A GIT branch and repository format implementation for bzr."""
23
0.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
24
import os
25
import sys
26
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
27
import bzrlib
28
import bzrlib.api
0.200.292 by Jelmer Vernooij
Fix formatting.
29
from bzrlib import (
30
    bzrdir,
31
    errors as bzr_errors,
32
    )
33
from bzrlib.foreign import (
34
    foreign_vcs_registry,
35
    )
36
from bzrlib.lockable_files import (
37
    TransportLock,
38
    )
39
from bzrlib.transport import (
40
    register_lazy_transport,
0.200.308 by Jelmer Vernooij
Register git protocols.
41
    register_transport_proto,
0.200.292 by Jelmer Vernooij
Fix formatting.
42
    )
43
from bzrlib.commands import (
44
    plugin_cmds,
45
    )
46
from bzrlib.trace import (
47
    warning,
48
    )
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
49
from bzrlib.version_info_formats.format_rio import (
50
    RioVersionInfoBuilder,
51
    )
52
0.200.192 by Jelmer Vernooij
use system-provided dulwich, remove own copy.
53
0.200.263 by Jelmer Vernooij
Start working on 0.2.0.
54
# versions ending in 'exp' mean experimental mappings
55
# versions ending in 'dev' mean development version
56
# versions ending in 'final' mean release (well tested, etc)
57
version_info = (0, 2, 0, 'dev', 0)
58
59
if version_info[3] == 'final':
60
    version_string = '%d.%d.%d' % version_info[:3]
61
else:
62
    version_string = '%d.%d.%d%s%d' % version_info
63
__version__ = version_string
64
0.200.235 by Jelmer Vernooij
Depend on newer dulwich.
65
MINIMUM_DULWICH_VERSION = (0, 1, 1)
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
66
COMPATIBLE_BZR_VERSIONS = [(1, 15, 0)]
0.200.192 by Jelmer Vernooij
use system-provided dulwich, remove own copy.
67
0.224.1 by Alexander Belchenko
bzr.exe support: allow import of dulwich from _lib subdirectory
68
if getattr(sys, "frozen", None):
69
    # allow import additional libs from ./_lib for bzr.exe only
70
    sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
71
0.200.200 by Jelmer Vernooij
Register lazily where possible.
72
_versions_checked = False
73
def lazy_check_versions():
74
    global _versions_checked
75
    if _versions_checked:
76
        return
77
    _versions_checked = True
78
    try:
79
        from dulwich import __version__ as dulwich_version
80
    except ImportError:
0.200.215 by Jelmer Vernooij
Merge improvements for running with bzr.exe.
81
        raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
0.200.200 by Jelmer Vernooij
Register lazily where possible.
82
    else:
83
        if dulwich_version < MINIMUM_DULWICH_VERSION:
0.200.215 by Jelmer Vernooij
Merge improvements for running with bzr.exe.
84
            raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
85
86
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
87
0.200.200 by Jelmer Vernooij
Register lazily where possible.
88
bzrdir.format_registry.register_lazy('git', 
89
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
90
    help='GIT repository.', native=False, experimental=True,
91
    )
0.200.204 by Jelmer Vernooij
Support bzr 1.11.
92
0.200.292 by Jelmer Vernooij
Fix formatting.
93
from bzrlib.revisionspec import revspec_registry
94
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
95
    "RevisionSpec_git")
0.200.200 by Jelmer Vernooij
Register lazily where possible.
96
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
97
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
98
class GitBzrDirFormat(bzrdir.BzrDirFormat):
99
    _lock_class = TransportLock
100
101
    def is_supported(self):
102
        return True
103
104
105
class LocalGitBzrDirFormat(GitBzrDirFormat):
106
    """The .git directory control format."""
107
108
    @classmethod
109
    def _known_formats(self):
110
        return set([LocalGitBzrDirFormat()])
111
112
    def open(self, transport, _found=None):
113
        """Open this directory.
114
115
        """
116
        import dulwich as git
117
        # we dont grok readonly - git isn't integrated with transport.
118
        url = transport.base
119
        if url.startswith('readonly+'):
120
            url = url[len('readonly+'):]
121
122
        try:
123
            gitrepo = git.repo.Repo(transport.local_abspath("."))
0.200.203 by Jelmer Vernooij
Fix imports.
124
        except bzr_errors.NotLocalUrl:
125
            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.
126
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
127
        lockfiles = GitLockableFiles(transport, GitLock())
128
        return LocalGitDir(transport, lockfiles, gitrepo, self)
129
130
    @classmethod
131
    def probe_transport(klass, transport):
132
        """Our format is present if the transport ends in '.not/'."""
133
        from bzrlib.transport.local import LocalTransport
134
135
        if not isinstance(transport, LocalTransport):
0.200.203 by Jelmer Vernooij
Fix imports.
136
            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.
137
138
        # This should quickly filter out most things that are not 
139
        # git repositories, saving us the trouble from loading dulwich.
140
        if not transport.has(".git") and not transport.has("objects"):
0.200.203 by Jelmer Vernooij
Fix imports.
141
            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.
142
143
        import dulwich as git
144
        format = klass()
145
        try:
146
            format.open(transport)
147
            return format
148
        except git.errors.NotGitRepository, e:
0.200.203 by Jelmer Vernooij
Fix imports.
149
            raise bzr_errors.NotBranchError(path=transport.base)
150
        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.
151
152
    def get_format_description(self):
153
        return "Local Git Repository"
154
155
    def get_format_string(self):
156
        return "Local Git Repository"
157
158
    def initialize_on_transport(self, transport):
159
        from bzrlib.transport.local import LocalTransport
160
161
        if not isinstance(transport, LocalTransport):
162
            raise NotImplementedError(self.initialize, 
163
                "Can't create Git Repositories/branches on "
164
                "non-local transports")
165
166
        from dulwich.repo import Repo
167
        Repo.create(transport.local_abspath(".")) 
168
        return self.open(transport)
169
170
    def is_supported(self):
171
        return True
172
173
174
class RemoteGitBzrDirFormat(GitBzrDirFormat):
175
    """The .git directory control format."""
176
177
    @classmethod
178
    def _known_formats(self):
179
        return set([RemoteGitBzrDirFormat()])
180
181
    def open(self, transport, _found=None):
182
        """Open this directory.
183
184
        """
0.200.321 by Jelmer Vernooij
Make remote repository access a bit lazier.
185
        # we dont grok readonly - git isn't integrated with transport.
186
        url = transport.base
187
        if url.startswith('readonly+'):
188
            url = url[len('readonly+'):]
189
        if (not url.startswith("git://") and 
190
            not url.startswith("git+")):
191
            raise bzr_errors.NotBranchError(transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
192
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
193
        if not isinstance(transport, GitSmartTransport):
0.200.203 by Jelmer Vernooij
Fix imports.
194
            raise bzr_errors.NotBranchError(transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
195
        from bzrlib.plugins.git.dir import GitLockableFiles, GitLock
196
        lockfiles = GitLockableFiles(transport, GitLock())
197
        return RemoteGitDir(transport, lockfiles, self)
198
199
    @classmethod
200
    def probe_transport(klass, transport):
201
        """Our format is present if the transport ends in '.not/'."""
0.200.321 by Jelmer Vernooij
Make remote repository access a bit lazier.
202
        url = transport.base
203
        if url.startswith('readonly+'):
204
            url = url[len('readonly+'):]
205
        if (not url.startswith("git://") and 
206
            not url.startswith("git+")):
207
            raise bzr_errors.NotBranchError(transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
208
        # little ugly, but works
209
        format = klass()
210
        from bzrlib.plugins.git.remote import GitSmartTransport
211
        if not isinstance(transport, GitSmartTransport):
0.200.203 by Jelmer Vernooij
Fix imports.
212
            raise bzr_errors.NotBranchError(transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
213
        # The only way to know a path exists and contains a valid repository 
214
        # is to do a request against it:
215
        try:
216
            transport.fetch_pack(lambda x: [], None, lambda x: None, 
217
                                 lambda x: mutter("git: %s" % x))
218
        except errors.git_errors.GitProtocolError:
0.200.203 by Jelmer Vernooij
Fix imports.
219
            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.
220
        else:
221
            return format
0.200.203 by Jelmer Vernooij
Fix imports.
222
        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.
223
224
    def get_format_description(self):
225
        return "Remote Git Repository"
226
227
    def get_format_string(self):
228
        return "Remote Git Repository"
229
230
    def initialize_on_transport(self, transport):
0.200.203 by Jelmer Vernooij
Fix imports.
231
        raise bzr_errors.UninitializableFormat(self)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
232
233
234
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
235
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
236
0.200.308 by Jelmer Vernooij
Register git protocols.
237
register_transport_proto('git://', 
238
        help="Access using the Git smart server protocol.")
239
register_transport_proto('git+ssh://', 
240
        help="Access using the Git smart server protocol over SSH.")
241
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
242
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
0.200.307 by Jelmer Vernooij
Support git+ssh.
243
                        'TCPGitSmartTransport')
244
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
245
                        'SSHGitSmartTransport')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
246
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
247
foreign_vcs_registry.register_lazy("git", 
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
248
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
0.208.5 by Jelmer Vernooij
Add log show function for git.
249
0.200.206 by Jelmer Vernooij
Move commands to a separate python module and register them lazily.
250
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
251
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
0.200.177 by Jelmer Vernooij
Add git-import command.
252
0.200.341 by Jelmer Vernooij
Add stanza with git commit info in 'bzr version-info'
253
def update_stanza(rev, stanza):
254
    mapping = getattr(rev, "mapping", None)
255
    if mapping is not None and mapping.revid_prefix.startswith("git-"):
256
        stanza.add("git-commit", rev.foreign_revid)
257
258
259
RioVersionInfoBuilder.hooks.install_named_hook('revision',
260
    update_stanza, None)
261
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
262
def get_rich_root_format(stacked=False):
263
    if stacked:
264
        return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
265
    else:
0.200.266 by Jelmer Vernooij
Use default-rich-root if possible.
266
        return bzrdir.format_registry.make_bzrdir("default-rich-root")
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
267
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
268
def test_suite():
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
269
    from bzrlib.plugins.git import tests
270
    return tests.test_suite()