/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

Fix regression in git-import.

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