/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to __init__.py

Partially fix pull.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2009 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
 
3
3
# Authors: Robert Collins <robert.collins@canonical.com>
4
4
#          Jelmer Vernooij <jelmer@samba.org>
26
26
 
27
27
import bzrlib
28
28
import bzrlib.api
29
 
 
30
 
from info import (
31
 
    bzr_compatible_versions,
32
 
    bzr_plugin_version as version_info,
33
 
    dulwich_minimum_version,
34
 
    )
35
 
 
36
 
if version_info[3] == 'final':
37
 
    version_string = '%d.%d.%d' % version_info[:3]
38
 
else:
39
 
    version_string = '%d.%d.%d%s%d' % version_info
40
 
__version__ = version_string
41
 
 
42
 
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
43
 
 
44
 
 
45
 
from bzrlib import (
46
 
    bzrdir,
47
 
    errors as bzr_errors,
48
 
    osutils,
49
 
    )
50
 
from bzrlib.foreign import (
51
 
    foreign_vcs_registry,
52
 
    )
53
 
from bzrlib.lockable_files import (
54
 
    TransportLock,
55
 
    )
56
 
from bzrlib.transport import (
57
 
    register_lazy_transport,
58
 
    register_transport_proto,
59
 
    )
60
 
from bzrlib.commands import (
61
 
    plugin_cmds,
62
 
    )
63
 
from bzrlib.version_info_formats.format_rio import (
64
 
    RioVersionInfoBuilder,
65
 
    )
66
 
from bzrlib.send import (
67
 
    format_registry as send_format_registry,
68
 
    )
69
 
 
 
29
from bzrlib import bzrdir, errors as bzr_errors
 
30
from bzrlib.foreign import foreign_vcs_registry
 
31
from bzrlib.lockable_files import TransportLock
 
32
from bzrlib.transport import register_lazy_transport
 
33
from bzrlib.commands import plugin_cmds
 
34
from bzrlib.trace import warning
 
35
 
 
36
MINIMUM_DULWICH_VERSION = (0, 1, 0)
 
37
COMPATIBLE_BZR_VERSIONS = [(1, 11, 0), (1, 12, 0)]
70
38
 
71
39
if getattr(sys, "frozen", None):
72
40
    # allow import additional libs from ./_lib for bzr.exe only
81
49
    try:
82
50
        from dulwich import __version__ as dulwich_version
83
51
    except ImportError:
84
 
        raise bzr_errors.DependencyNotPresent("dulwich",
85
 
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
 
52
        raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
86
53
    else:
87
 
        if dulwich_version < dulwich_minimum_version:
88
 
            raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Dulwich is too old; at least %d.%d.%d is required" % dulwich_minimum_version)
89
 
 
90
 
bzrdir.format_registry.register_lazy('git',
 
54
        if dulwich_version < MINIMUM_DULWICH_VERSION:
 
55
            raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
 
56
 
 
57
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
 
58
 
 
59
bzrdir.format_registry.register_lazy('git', 
91
60
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
92
61
    help='GIT repository.', native=False, experimental=True,
93
62
    )
94
63
 
95
 
from bzrlib.revisionspec import revspec_registry
96
 
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
97
 
    "RevisionSpec_git")
98
 
 
99
64
try:
100
 
    from bzrlib.revisionspec import dwim_revspecs
 
65
    from bzrlib.revisionspec import revspec_registry
 
66
    revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
 
67
        "RevisionSpec_git")
101
68
except ImportError:
102
 
    pass
103
 
else:
 
69
    lazy_check_versions()
 
70
    from bzrlib.revisionspec import SPEC_TYPES
104
71
    from bzrlib.plugins.git.revspec import RevisionSpec_git
105
 
    dwim_revspecs.append(RevisionSpec_git)
106
 
 
 
72
    SPEC_TYPES.append(RevisionSpec_git)
107
73
 
108
74
class GitBzrDirFormat(bzrdir.BzrDirFormat):
109
 
 
110
75
    _lock_class = TransportLock
111
76
 
112
77
    def is_supported(self):
113
78
        return True
114
79
 
115
 
    def network_name(self):
116
 
        return "git"
117
 
 
118
80
 
119
81
class LocalGitBzrDirFormat(GitBzrDirFormat):
120
82
    """The .git directory control format."""
127
89
        """Open this directory.
128
90
 
129
91
        """
130
 
        lazy_check_versions()
 
92
        import dulwich as git
131
93
        # we dont grok readonly - git isn't integrated with transport.
132
 
        from bzrlib.transport.local import LocalTransport
133
 
        if isinstance(transport, LocalTransport):
134
 
            import dulwich
135
 
            gitrepo = dulwich.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
136
 
        else:
137
 
            from bzrlib.plugins.git.transportgit import TransportRepo
138
 
            gitrepo = TransportRepo(transport)
 
94
        url = transport.base
 
95
        if url.startswith('readonly+'):
 
96
            url = url[len('readonly+'):]
 
97
 
 
98
        try:
 
99
            gitrepo = git.repo.Repo(transport.local_abspath("."))
 
100
        except bzr_errors.NotLocalUrl:
 
101
            raise bzr_errors.NotBranchError(path=transport.base)
139
102
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
140
103
        lockfiles = GitLockableFiles(transport, GitLock())
141
104
        return LocalGitDir(transport, lockfiles, gitrepo, self)
142
105
 
143
106
    @classmethod
144
107
    def probe_transport(klass, transport):
145
 
        try:
146
 
            if not (transport.has('info/refs') or 
147
 
                    transport.has('.git/branches') or 
148
 
                    transport.has('branches')):
149
 
                raise bzr_errors.NotBranchError(path=transport.base)
150
 
        except bzr_errors.NoSuchFile:
151
 
            raise bzr_errors.NotBranchError(path=transport.base)
152
 
        from bzrlib import urlutils
153
 
        if urlutils.split(transport.base)[1] == ".git":
154
 
            raise bzr_errors.NotBranchError(path=transport.base)
155
 
        lazy_check_versions()
156
 
        import dulwich
 
108
        """Our format is present if the transport ends in '.not/'."""
 
109
        from bzrlib.transport.local import LocalTransport
 
110
 
 
111
        if not isinstance(transport, LocalTransport):
 
112
            raise bzr_errors.NotBranchError(path=transport.base)
 
113
 
 
114
        # This should quickly filter out most things that are not 
 
115
        # git repositories, saving us the trouble from loading dulwich.
 
116
        if not transport.has(".git") and not transport.has("objects"):
 
117
            raise bzr_errors.NotBranchError(path=transport.base)
 
118
 
 
119
        import dulwich as git
157
120
        format = klass()
158
121
        try:
159
122
            format.open(transport)
160
123
            return format
161
 
        except dulwich.errors.NotGitRepository, e:
 
124
        except git.errors.NotGitRepository, e:
162
125
            raise bzr_errors.NotBranchError(path=transport.base)
163
126
        raise bzr_errors.NotBranchError(path=transport.base)
164
127
 
172
135
        from bzrlib.transport.local import LocalTransport
173
136
 
174
137
        if not isinstance(transport, LocalTransport):
175
 
            raise NotImplementedError(self.initialize,
 
138
            raise NotImplementedError(self.initialize, 
176
139
                "Can't create Git Repositories/branches on "
177
140
                "non-local transports")
178
 
        lazy_check_versions()
 
141
 
179
142
        from dulwich.repo import Repo
180
 
        Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
 
143
        Repo.create(transport.local_abspath(".")) 
181
144
        return self.open(transport)
182
145
 
183
146
    def is_supported(self):
195
158
        """Open this directory.
196
159
 
197
160
        """
198
 
        # we dont grok readonly - git isn't integrated with transport.
199
 
        url = transport.base
200
 
        if url.startswith('readonly+'):
201
 
            url = url[len('readonly+'):]
202
 
        if (not url.startswith("git://") and not url.startswith("git+")):
203
 
            raise bzr_errors.NotBranchError(transport.base)
204
161
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
205
162
        if not isinstance(transport, GitSmartTransport):
206
163
            raise bzr_errors.NotBranchError(transport.base)
 
164
        # we dont grok readonly - git isn't integrated with transport.
 
165
        url = transport.base
 
166
        if url.startswith('readonly+'):
 
167
            url = url[len('readonly+'):]
 
168
 
207
169
        from bzrlib.plugins.git.dir import GitLockableFiles, GitLock
208
170
        lockfiles = GitLockableFiles(transport, GitLock())
209
171
        return RemoteGitDir(transport, lockfiles, self)
211
173
    @classmethod
212
174
    def probe_transport(klass, transport):
213
175
        """Our format is present if the transport ends in '.not/'."""
214
 
        url = transport.base
215
 
        if url.startswith('readonly+'):
216
 
            url = url[len('readonly+'):]
217
 
        if (not url.startswith("git://") and not url.startswith("git+")):
218
 
            raise bzr_errors.NotBranchError(transport.base)
219
176
        # little ugly, but works
220
177
        format = klass()
221
178
        from bzrlib.plugins.git.remote import GitSmartTransport
222
179
        if not isinstance(transport, GitSmartTransport):
223
180
            raise bzr_errors.NotBranchError(transport.base)
224
 
        return format
 
181
        # The only way to know a path exists and contains a valid repository 
 
182
        # is to do a request against it:
 
183
        try:
 
184
            transport.fetch_pack(lambda x: [], None, lambda x: None, 
 
185
                                 lambda x: mutter("git: %s" % x))
 
186
        except errors.git_errors.GitProtocolError:
 
187
            raise bzr_errors.NotBranchError(path=transport.base)
 
188
        else:
 
189
            return format
 
190
        raise bzr_errors.NotBranchError(path=transport.base)
225
191
 
226
192
    def get_format_description(self):
227
193
        return "Remote Git Repository"
236
202
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
237
203
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
238
204
 
239
 
register_transport_proto('git://',
240
 
        help="Access using the Git smart server protocol.")
241
 
register_transport_proto('git+ssh://',
242
 
        help="Access using the Git smart server protocol over SSH.")
243
 
 
244
205
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
245
 
                        'TCPGitSmartTransport')
246
 
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
247
 
                        'SSHGitSmartTransport')
248
 
 
249
 
foreign_vcs_registry.register_lazy("git",
250
 
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
251
 
 
 
206
                        'GitSmartTransport')
 
207
 
 
208
foreign_vcs_registry.register_lazy("git", 
 
209
                        "bzrlib.plugins.git.mapping", 
 
210
                        "foreign_git",
 
211
                        "Stupid content tracker")
 
212
 
 
213
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
252
214
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
253
 
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
254
 
    "bzrlib.plugins.git.commands")
255
 
 
256
 
def update_stanza(rev, stanza):
257
 
    mapping = getattr(rev, "mapping", None)
258
 
    if mapping is not None and mapping.revid_prefix.startswith("git-"):
259
 
        stanza.add("git-commit", rev.foreign_revid)
260
 
 
261
 
 
262
 
rio_hooks = getattr(RioVersionInfoBuilder, "hooks", None)
263
 
if rio_hooks is not None:
264
 
    rio_hooks.install_named_hook('revision', update_stanza, None)
265
 
 
266
 
 
267
 
from bzrlib.transport import transport_server_registry
268
 
transport_server_registry.register_lazy('git',
269
 
    'bzrlib.plugins.git.server',
270
 
    'serve_git',
271
 
    'Git Smart server protocol over TCP. (default port: 9418)')
272
 
 
273
 
 
274
 
from bzrlib.repository import network_format_registry as repository_network_format_registry
275
 
repository_network_format_registry.register_lazy('git',
276
 
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
277
 
 
278
 
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
279
 
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
280
 
 
281
 
 
282
 
def get_rich_root_format(stacked=False):
283
 
    if stacked:
284
 
        return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
285
 
    else:
286
 
        return bzrdir.format_registry.make_bzrdir("default-rich-root")
287
 
 
288
 
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
289
 
                                   'send_git', 'Git am-style diff format')
290
215
 
291
216
def test_suite():
292
217
    from bzrlib.plugins.git import tests