/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

Create cache dir if it doesn't exist yet.

Show diffs side-by-side

added added

removed removed

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