/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

  • Committer: Jelmer Vernooij
  • Date: 2010-02-12 00:39:11 UTC
  • mto: (0.200.718 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20100212003911-hz63ctlfgsvrzrjh
Cope with has_index not existing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import bzrlib
28
28
import bzrlib.api
29
29
 
30
 
# versions ending in 'exp' mean experimental mappings
31
 
# versions ending in 'dev' mean development version
32
 
# versions ending in 'final' mean release (well tested, etc)
33
 
version_info = (0, 3, 3, 'dev', 0)
 
30
from info import (
 
31
    bzr_compatible_versions,
 
32
    bzr_plugin_version as version_info,
 
33
    dulwich_minimum_version,
 
34
    )
34
35
 
35
36
if version_info[3] == 'final':
36
37
    version_string = '%d.%d.%d' % version_info[:3]
38
39
    version_string = '%d.%d.%d%s%d' % version_info
39
40
__version__ = version_string
40
41
 
41
 
MINIMUM_DULWICH_VERSION = (0, 3, 1)
42
 
COMPATIBLE_BZR_VERSIONS = [(1, 14, 0), (1, 15, 0)]
43
 
 
44
 
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
 
42
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
45
43
 
46
44
 
47
45
from bzrlib import (
62
60
from bzrlib.commands import (
63
61
    plugin_cmds,
64
62
    )
65
 
from bzrlib.trace import (
66
 
    warning,
67
 
    )
68
63
from bzrlib.version_info_formats.format_rio import (
69
64
    RioVersionInfoBuilder,
70
65
    )
 
66
from bzrlib.send import (
 
67
    format_registry as send_format_registry,
 
68
    )
71
69
 
72
70
 
73
71
if getattr(sys, "frozen", None):
83
81
    try:
84
82
        from dulwich import __version__ as dulwich_version
85
83
    except ImportError:
86
 
        raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
 
84
        raise bzr_errors.DependencyNotPresent("dulwich",
 
85
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
87
86
    else:
88
 
        if dulwich_version < MINIMUM_DULWICH_VERSION:
89
 
            raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
 
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)
90
89
 
91
 
bzrdir.format_registry.register_lazy('git', 
 
90
bzrdir.format_registry.register_lazy('git',
92
91
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
93
92
    help='GIT repository.', native=False, experimental=True,
94
93
    )
95
94
 
96
95
from bzrlib.revisionspec import revspec_registry
97
 
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
 
96
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
98
97
    "RevisionSpec_git")
99
98
 
 
99
try:
 
100
    from bzrlib.revisionspec import dwim_revspecs
 
101
except ImportError:
 
102
    pass
 
103
else:
 
104
    from bzrlib.plugins.git.revspec import RevisionSpec_git
 
105
    dwim_revspecs.append(RevisionSpec_git)
 
106
 
100
107
 
101
108
class GitBzrDirFormat(bzrdir.BzrDirFormat):
 
109
 
102
110
    _lock_class = TransportLock
103
111
 
104
112
    def is_supported(self):
119
127
        """Open this directory.
120
128
 
121
129
        """
122
 
        import dulwich as git
 
130
        lazy_check_versions()
 
131
        import dulwich
123
132
        # we dont grok readonly - git isn't integrated with transport.
124
133
        url = transport.base
125
134
        if url.startswith('readonly+'):
126
135
            url = url[len('readonly+'):]
127
136
 
128
137
        try:
129
 
            gitrepo = git.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
 
138
            gitrepo = dulwich.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
130
139
        except bzr_errors.NotLocalUrl:
131
140
            raise bzr_errors.NotBranchError(path=transport.base)
132
141
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
141
150
        if not isinstance(transport, LocalTransport):
142
151
            raise bzr_errors.NotBranchError(path=transport.base)
143
152
 
144
 
        # This should quickly filter out most things that are not 
 
153
        # This should quickly filter out most things that are not
145
154
        # git repositories, saving us the trouble from loading dulwich.
146
155
        if not transport.has(".git") and not transport.has("objects"):
147
156
            raise bzr_errors.NotBranchError(path=transport.base)
148
157
 
149
 
        import dulwich as git
 
158
        lazy_check_versions()
 
159
        import dulwich
150
160
        format = klass()
151
161
        try:
152
162
            format.open(transport)
153
163
            return format
154
 
        except git.errors.NotGitRepository, e:
 
164
        except dulwich.errors.NotGitRepository, e:
155
165
            raise bzr_errors.NotBranchError(path=transport.base)
156
166
        raise bzr_errors.NotBranchError(path=transport.base)
157
167
 
165
175
        from bzrlib.transport.local import LocalTransport
166
176
 
167
177
        if not isinstance(transport, LocalTransport):
168
 
            raise NotImplementedError(self.initialize, 
 
178
            raise NotImplementedError(self.initialize,
169
179
                "Can't create Git Repositories/branches on "
170
180
                "non-local transports")
171
 
 
 
181
        lazy_check_versions()
172
182
        from dulwich.repo import Repo
173
 
        Repo.create(transport.local_abspath(".").encode(osutils._fs_enc)) 
 
183
        Repo.create(transport.local_abspath(".").encode(osutils._fs_enc))
174
184
        return self.open(transport)
175
185
 
176
186
    def is_supported(self):
192
202
        url = transport.base
193
203
        if url.startswith('readonly+'):
194
204
            url = url[len('readonly+'):]
195
 
        if (not url.startswith("git://") and 
196
 
            not url.startswith("git+")):
 
205
        if (not url.startswith("git://") and not url.startswith("git+")):
197
206
            raise bzr_errors.NotBranchError(transport.base)
198
207
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
199
208
        if not isinstance(transport, GitSmartTransport):
208
217
        url = transport.base
209
218
        if url.startswith('readonly+'):
210
219
            url = url[len('readonly+'):]
211
 
        if (not url.startswith("git://") and 
212
 
            not url.startswith("git+")):
 
220
        if (not url.startswith("git://") and not url.startswith("git+")):
213
221
            raise bzr_errors.NotBranchError(transport.base)
214
222
        # little ugly, but works
215
223
        format = klass()
231
239
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
232
240
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
233
241
 
234
 
register_transport_proto('git://', 
 
242
register_transport_proto('git://',
235
243
        help="Access using the Git smart server protocol.")
236
 
register_transport_proto('git+ssh://', 
 
244
register_transport_proto('git+ssh://',
237
245
        help="Access using the Git smart server protocol over SSH.")
238
246
 
239
247
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
241
249
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
242
250
                        'SSHGitSmartTransport')
243
251
 
244
 
foreign_vcs_registry.register_lazy("git", 
 
252
foreign_vcs_registry.register_lazy("git",
245
253
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
246
254
 
247
255
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
248
 
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"], 
 
256
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
249
257
    "bzrlib.plugins.git.commands")
250
258
 
251
259
def update_stanza(rev, stanza):
259
267
    rio_hooks.install_named_hook('revision', update_stanza, None)
260
268
 
261
269
 
262
 
try:
263
 
    from bzrlib.transport import transport_server_registry
264
 
except ImportError:
265
 
    pass
266
 
else:
267
 
    transport_server_registry.register_lazy('git',
268
 
        'bzrlib.plugins.git.server', 
269
 
        'serve_git',
270
 
        'Git Smart server protocol over TCP. (default port: 9418)')
 
270
from bzrlib.transport import transport_server_registry
 
271
transport_server_registry.register_lazy('git',
 
272
    'bzrlib.plugins.git.server',
 
273
    'serve_git',
 
274
    'Git Smart server protocol over TCP. (default port: 9418)')
271
275
 
272
276
 
273
277
from bzrlib.repository import network_format_registry as repository_network_format_registry
274
 
repository_network_format_registry.register_lazy('git', 
 
278
repository_network_format_registry.register_lazy('git',
275
279
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
276
280
 
277
281
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
284
288
    else:
285
289
        return bzrdir.format_registry.make_bzrdir("default-rich-root")
286
290
 
 
291
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
292
                                   'send_git', 'Git am-style diff format')
 
293
 
287
294
def test_suite():
288
295
    from bzrlib.plugins.git import tests
289
296
    return tests.test_suite()