/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

More tests for sha maps, fix cache misses in tdb.

Show diffs side-by-side

added added

removed removed

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