/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

Rename BzrDir to ControlDir.

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 (
48
 
    bzrdir,
49
46
    errors as bzr_errors,
50
47
    osutils,
51
48
    )
 
49
try:
 
50
    from bzrlib.controldir import (
 
51
        ControlDirFormat,
 
52
        ControlDir,
 
53
        format_registry,
 
54
        )
 
55
except ImportError:
 
56
    # bzr < 2.3
 
57
    from bzrlib.bzrdir import (
 
58
        BzrDirFormat,
 
59
        BzrDir,
 
60
        format_registry,
 
61
        )
 
62
    ControlDir = BzrDir
 
63
    ControlDirFormat = BzrDirFormat
 
64
 
52
65
from bzrlib.foreign import (
53
66
    foreign_vcs_registry,
54
67
    )
 
68
from bzrlib.help_topics import (
 
69
    topic_registry,
 
70
    )
55
71
from bzrlib.lockable_files import (
56
72
    TransportLock,
57
73
    )
62
78
from bzrlib.commands import (
63
79
    plugin_cmds,
64
80
    )
65
 
from bzrlib.trace import (
66
 
    warning,
67
 
    )
68
81
from bzrlib.version_info_formats.format_rio import (
69
82
    RioVersionInfoBuilder,
70
83
    )
 
84
from bzrlib.send import (
 
85
    format_registry as send_format_registry,
 
86
    )
71
87
 
72
88
 
73
89
if getattr(sys, "frozen", None):
74
90
    # 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')))
 
91
    sys.path.append(os.path.normpath(
 
92
        os.path.join(os.path.dirname(__file__), '_lib')))
 
93
 
 
94
 
 
95
def import_dulwich():
 
96
    try:
 
97
        from dulwich import __version__ as dulwich_version
 
98
    except ImportError:
 
99
        raise bzr_errors.DependencyNotPresent("dulwich",
 
100
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
 
101
    else:
 
102
        if dulwich_version < dulwich_minimum_version:
 
103
            raise bzr_errors.DependencyNotPresent("dulwich",
 
104
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
 
105
                    dulwich_minimum_version)
 
106
 
76
107
 
77
108
_versions_checked = False
78
109
def lazy_check_versions():
79
110
    global _versions_checked
80
111
    if _versions_checked:
81
112
        return
 
113
    import_dulwich()
82
114
    _versions_checked = True
83
 
    try:
84
 
        from dulwich import __version__ as dulwich_version
85
 
    except ImportError:
86
 
        raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
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)
90
115
 
91
 
bzrdir.format_registry.register_lazy('git', 
92
 
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
 
116
format_registry.register_lazy('git',
 
117
    "bzrlib.plugins.git.dir", "LocalGitControlDirFormat",
93
118
    help='GIT repository.', native=False, experimental=True,
94
119
    )
95
120
 
96
121
from bzrlib.revisionspec import revspec_registry
97
 
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
 
122
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
98
123
    "RevisionSpec_git")
99
124
 
100
 
 
101
 
class GitBzrDirFormat(bzrdir.BzrDirFormat):
 
125
try:
 
126
    from bzrlib.revisionspec import dwim_revspecs
 
127
except ImportError:
 
128
    pass
 
129
else:
 
130
    from bzrlib.plugins.git.revspec import RevisionSpec_git
 
131
    dwim_revspecs.append(RevisionSpec_git)
 
132
 
 
133
 
 
134
class GitControlDirFormat(ControlDirFormat):
 
135
 
102
136
    _lock_class = TransportLock
103
137
 
 
138
    colocated_branches = True
 
139
 
 
140
    def __eq__(self, other):
 
141
        return type(self) == type(other)
 
142
 
104
143
    def is_supported(self):
105
144
        return True
106
145
 
108
147
        return "git"
109
148
 
110
149
 
111
 
class LocalGitBzrDirFormat(GitBzrDirFormat):
 
150
class LocalGitControlDirFormat(GitControlDirFormat):
112
151
    """The .git directory control format."""
113
152
 
114
153
    @classmethod
115
154
    def _known_formats(self):
116
 
        return set([LocalGitBzrDirFormat()])
 
155
        return set([LocalGitControlDirFormat()])
117
156
 
118
157
    def open(self, transport, _found=None):
119
158
        """Open this directory.
120
159
 
121
160
        """
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)
 
161
        lazy_check_versions()
 
162
        from bzrlib.plugins.git.transportgit import TransportRepo
 
163
        gitrepo = TransportRepo(transport)
132
164
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
133
165
        lockfiles = GitLockableFiles(transport, GitLock())
134
166
        return LocalGitDir(transport, lockfiles, gitrepo, self)
135
167
 
136
168
    @classmethod
137
169
    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
 
170
        try:
 
171
            if not transport.has_any(['info/refs', '.git/branches',
 
172
                                      'branches']):
 
173
                raise bzr_errors.NotBranchError(path=transport.base)
 
174
        except bzr_errors.NoSuchFile:
 
175
            raise bzr_errors.NotBranchError(path=transport.base)
 
176
        from bzrlib import urlutils
 
177
        if urlutils.split(transport.base)[1] == ".git":
 
178
            raise bzr_errors.NotBranchError(path=transport.base)
 
179
        lazy_check_versions()
 
180
        import dulwich
150
181
        format = klass()
151
182
        try:
152
183
            format.open(transport)
153
184
            return format
154
 
        except git.errors.NotGitRepository, e:
 
185
        except dulwich.errors.NotGitRepository, e:
155
186
            raise bzr_errors.NotBranchError(path=transport.base)
156
187
        raise bzr_errors.NotBranchError(path=transport.base)
157
188
 
165
196
        from bzrlib.transport.local import LocalTransport
166
197
 
167
198
        if not isinstance(transport, LocalTransport):
168
 
            raise NotImplementedError(self.initialize, 
 
199
            raise NotImplementedError(self.initialize,
169
200
                "Can't create Git Repositories/branches on "
170
201
                "non-local transports")
171
 
 
 
202
        lazy_check_versions()
172
203
        from dulwich.repo import Repo
173
 
        Repo.create(transport.local_abspath(".").encode(osutils._fs_enc)) 
 
204
        Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
174
205
        return self.open(transport)
175
206
 
176
207
    def is_supported(self):
177
208
        return True
178
209
 
179
210
 
180
 
class RemoteGitBzrDirFormat(GitBzrDirFormat):
 
211
class RemoteGitControlDirFormat(GitControlDirFormat):
181
212
    """The .git directory control format."""
182
213
 
183
214
    @classmethod
184
215
    def _known_formats(self):
185
 
        return set([RemoteGitBzrDirFormat()])
 
216
        return set([RemoteGitControlDirFormat()])
186
217
 
187
218
    def open(self, transport, _found=None):
188
219
        """Open this directory.
192
223
        url = transport.base
193
224
        if url.startswith('readonly+'):
194
225
            url = url[len('readonly+'):]
195
 
        if (not url.startswith("git://") and 
196
 
            not url.startswith("git+")):
 
226
        if (not url.startswith("git://") and not url.startswith("git+")):
197
227
            raise bzr_errors.NotBranchError(transport.base)
198
228
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
199
229
        if not isinstance(transport, GitSmartTransport):
208
238
        url = transport.base
209
239
        if url.startswith('readonly+'):
210
240
            url = url[len('readonly+'):]
211
 
        if (not url.startswith("git://") and 
212
 
            not url.startswith("git+")):
 
241
        if (not url.startswith("git://") and not url.startswith("git+")):
213
242
            raise bzr_errors.NotBranchError(transport.base)
214
243
        # little ugly, but works
215
244
        format = klass()
228
257
        raise bzr_errors.UninitializableFormat(self)
229
258
 
230
259
 
231
 
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
232
 
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
 
260
ControlDirFormat.register_control_format(LocalGitControlDirFormat)
 
261
ControlDirFormat.register_control_format(RemoteGitControlDirFormat)
233
262
 
234
 
register_transport_proto('git://', 
 
263
register_transport_proto('git://',
235
264
        help="Access using the Git smart server protocol.")
236
 
register_transport_proto('git+ssh://', 
 
265
register_transport_proto('git+ssh://',
237
266
        help="Access using the Git smart server protocol over SSH.")
238
267
 
239
268
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
241
270
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
242
271
                        'SSHGitSmartTransport')
243
272
 
244
 
foreign_vcs_registry.register_lazy("git", 
 
273
foreign_vcs_registry.register_lazy("git",
245
274
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
246
275
 
247
276
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
248
 
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"], 
 
277
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
249
278
    "bzrlib.plugins.git.commands")
 
279
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
 
280
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
250
281
 
251
282
def update_stanza(rev, stanza):
252
283
    mapping = getattr(rev, "mapping", None)
259
290
    rio_hooks.install_named_hook('revision', update_stanza, None)
260
291
 
261
292
 
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', 
 
293
from bzrlib.transport import transport_server_registry
 
294
transport_server_registry.register_lazy('git',
 
295
    'bzrlib.plugins.git.server',
 
296
    'serve_git',
 
297
    'Git Smart server protocol over TCP. (default port: 9418)')
 
298
 
 
299
 
 
300
from bzrlib.repository import (
 
301
    network_format_registry as repository_network_format_registry,
 
302
    )
 
303
repository_network_format_registry.register_lazy('git',
275
304
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
276
305
 
277
 
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
278
 
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
279
 
 
280
 
 
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")
 
306
from bzrlib.bzrdir import (
 
307
    network_format_registry as bzrdir_network_format_registry,
 
308
    )
 
309
bzrdir_network_format_registry.register('git', GitControlDirFormat)
 
310
 
 
311
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
312
                                   'send_git', 'Git am-style diff format')
 
313
 
 
314
topic_registry.register_lazy('git',
 
315
                             'bzrlib.plugins.git.help',
 
316
                             'help_git', 'Using Bazaar with Git')
 
317
 
 
318
try:
 
319
    from bzrlib.diff import format_registry as diff_format_registry
 
320
except ImportError:
 
321
    pass
 
322
else:
 
323
    diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
324
        'GitDiffTree', 'Git am-style diff format')
286
325
 
287
326
def test_suite():
288
327
    from bzrlib.plugins.git import tests