/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

Handle non-ascii characters in filenames.

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):
74
72
    # allow import additional libs from ./_lib for bzr.exe only
75
 
    sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
 
73
    sys.path.append(os.path.normpath(
 
74
        os.path.join(os.path.dirname(__file__), '_lib')))
76
75
 
77
76
_versions_checked = False
78
77
def lazy_check_versions():
83
82
    try:
84
83
        from dulwich import __version__ as dulwich_version
85
84
    except ImportError:
86
 
        raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
 
85
        raise bzr_errors.DependencyNotPresent("dulwich",
 
86
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
87
87
    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)
 
88
        if dulwich_version < dulwich_minimum_version:
 
89
            raise bzr_errors.DependencyNotPresent("dulwich",
 
90
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
 
91
                    dulwich_minimum_version)
90
92
 
91
 
bzrdir.format_registry.register_lazy('git', 
 
93
bzrdir.format_registry.register_lazy('git',
92
94
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
93
95
    help='GIT repository.', native=False, experimental=True,
94
96
    )
95
97
 
96
98
from bzrlib.revisionspec import revspec_registry
97
 
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
 
99
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
98
100
    "RevisionSpec_git")
99
101
 
 
102
try:
 
103
    from bzrlib.revisionspec import dwim_revspecs
 
104
except ImportError:
 
105
    pass
 
106
else:
 
107
    from bzrlib.plugins.git.revspec import RevisionSpec_git
 
108
    dwim_revspecs.append(RevisionSpec_git)
 
109
 
100
110
 
101
111
class GitBzrDirFormat(bzrdir.BzrDirFormat):
 
112
 
102
113
    _lock_class = TransportLock
103
114
 
 
115
    colocated_branches = True
 
116
 
 
117
    def __eq__(self, other):
 
118
        return type(self) == type(other)
 
119
 
104
120
    def is_supported(self):
105
121
        return True
106
122
 
119
135
        """Open this directory.
120
136
 
121
137
        """
122
 
        import dulwich as git
123
 
        # we dont grok readonly - git isn't integrated with 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)
 
138
        lazy_check_versions()
 
139
        from bzrlib.plugins.git.transportgit import TransportRepo
 
140
        gitrepo = TransportRepo(transport)
132
141
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
133
142
        lockfiles = GitLockableFiles(transport, GitLock())
134
143
        return LocalGitDir(transport, lockfiles, gitrepo, self)
135
144
 
136
145
    @classmethod
137
146
    def probe_transport(klass, transport):
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
 
147
        try:
 
148
            if not transport.has_any(['info/refs', '.git/branches',
 
149
                                      'branches']):
 
150
                raise bzr_errors.NotBranchError(path=transport.base)
 
151
        except bzr_errors.NoSuchFile:
 
152
            raise bzr_errors.NotBranchError(path=transport.base)
 
153
        from bzrlib import urlutils
 
154
        if urlutils.split(transport.base)[1] == ".git":
 
155
            raise bzr_errors.NotBranchError(path=transport.base)
 
156
        lazy_check_versions()
 
157
        import dulwich
150
158
        format = klass()
151
159
        try:
152
160
            format.open(transport)
153
161
            return format
154
 
        except git.errors.NotGitRepository, e:
 
162
        except dulwich.errors.NotGitRepository, e:
155
163
            raise bzr_errors.NotBranchError(path=transport.base)
156
164
        raise bzr_errors.NotBranchError(path=transport.base)
157
165
 
165
173
        from bzrlib.transport.local import LocalTransport
166
174
 
167
175
        if not isinstance(transport, LocalTransport):
168
 
            raise NotImplementedError(self.initialize, 
 
176
            raise NotImplementedError(self.initialize,
169
177
                "Can't create Git Repositories/branches on "
170
178
                "non-local transports")
171
 
 
 
179
        lazy_check_versions()
172
180
        from dulwich.repo import Repo
173
 
        Repo.create(transport.local_abspath(".").encode(osutils._fs_enc)) 
 
181
        Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
174
182
        return self.open(transport)
175
183
 
176
184
    def is_supported(self):
192
200
        url = transport.base
193
201
        if url.startswith('readonly+'):
194
202
            url = url[len('readonly+'):]
195
 
        if (not url.startswith("git://") and 
196
 
            not url.startswith("git+")):
 
203
        if (not url.startswith("git://") and not url.startswith("git+")):
197
204
            raise bzr_errors.NotBranchError(transport.base)
198
205
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
199
206
        if not isinstance(transport, GitSmartTransport):
208
215
        url = transport.base
209
216
        if url.startswith('readonly+'):
210
217
            url = url[len('readonly+'):]
211
 
        if (not url.startswith("git://") and 
212
 
            not url.startswith("git+")):
 
218
        if (not url.startswith("git://") and not url.startswith("git+")):
213
219
            raise bzr_errors.NotBranchError(transport.base)
214
220
        # little ugly, but works
215
221
        format = klass()
231
237
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
232
238
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
233
239
 
234
 
register_transport_proto('git://', 
 
240
register_transport_proto('git://',
235
241
        help="Access using the Git smart server protocol.")
236
 
register_transport_proto('git+ssh://', 
 
242
register_transport_proto('git+ssh://',
237
243
        help="Access using the Git smart server protocol over SSH.")
238
244
 
239
245
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
241
247
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
242
248
                        'SSHGitSmartTransport')
243
249
 
244
 
foreign_vcs_registry.register_lazy("git", 
 
250
foreign_vcs_registry.register_lazy("git",
245
251
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
246
252
 
247
253
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
248
 
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"], 
 
254
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
249
255
    "bzrlib.plugins.git.commands")
 
256
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
 
257
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
250
258
 
251
259
def update_stanza(rev, stanza):
252
260
    mapping = getattr(rev, "mapping", None)
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)')
271
 
 
272
 
 
273
 
from bzrlib.repository import network_format_registry as repository_network_format_registry
274
 
repository_network_format_registry.register_lazy('git', 
 
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 (
 
278
    network_format_registry as repository_network_format_registry,
 
279
    )
 
280
repository_network_format_registry.register_lazy('git',
275
281
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
276
282
 
277
 
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
 
283
from bzrlib.bzrdir import (
 
284
    network_format_registry as bzrdir_network_format_registry,
 
285
    )
278
286
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
279
287
 
 
288
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
289
                                   'send_git', 'Git am-style diff format')
280
290
 
281
 
def get_rich_root_format(stacked=False):
282
 
    if stacked:
283
 
        return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
284
 
    else:
285
 
        return bzrdir.format_registry.make_bzrdir("default-rich-root")
 
291
try:
 
292
    from bzrlib.diff import format_registry as diff_format_registry
 
293
except ImportError:
 
294
    pass
 
295
else:
 
296
    diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
297
        'GitDiffTree', 'Git am-style diff format')
286
298
 
287
299
def test_suite():
288
300
    from bzrlib.plugins.git import tests