/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

Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
 
45
45
from bzrlib import (
46
 
    bzrdir,
47
46
    errors as bzr_errors,
48
47
    osutils,
49
48
    )
 
49
try:
 
50
    from bzrlib.controldir import (
 
51
        ControlDirFormat,
 
52
        ControlDir,
 
53
        Prober,
 
54
        format_registry,
 
55
        )
 
56
except ImportError:
 
57
    # bzr < 2.3
 
58
    from bzrlib.bzrdir import (
 
59
        BzrDirFormat,
 
60
        BzrDir,
 
61
        format_registry,
 
62
        )
 
63
    ControlDir = BzrDir
 
64
    ControlDirFormat = BzrDirFormat
 
65
    Prober = object
 
66
    has_controldir = False
 
67
else:
 
68
    has_controldir = True
 
69
 
50
70
from bzrlib.foreign import (
51
71
    foreign_vcs_registry,
52
72
    )
 
73
from bzrlib.help_topics import (
 
74
    topic_registry,
 
75
    )
53
76
from bzrlib.lockable_files import (
54
77
    TransportLock,
55
78
    )
73
96
    sys.path.append(os.path.normpath(
74
97
        os.path.join(os.path.dirname(__file__), '_lib')))
75
98
 
76
 
_versions_checked = False
77
 
def lazy_check_versions():
78
 
    global _versions_checked
79
 
    if _versions_checked:
80
 
        return
81
 
    _versions_checked = True
 
99
 
 
100
def import_dulwich():
82
101
    try:
83
102
        from dulwich import __version__ as dulwich_version
84
103
    except ImportError:
90
109
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
91
110
                    dulwich_minimum_version)
92
111
 
93
 
bzrdir.format_registry.register_lazy('git',
94
 
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
95
 
    help='GIT repository.', native=False, experimental=True,
 
112
 
 
113
_versions_checked = False
 
114
def lazy_check_versions():
 
115
    global _versions_checked
 
116
    if _versions_checked:
 
117
        return
 
118
    import_dulwich()
 
119
    _versions_checked = True
 
120
 
 
121
format_registry.register_lazy('git',
 
122
    "bzrlib.plugins.git.dir", "LocalGitControlDirFormat",
 
123
    help='GIT repository.', native=False, experimental=False,
96
124
    )
97
125
 
98
126
from bzrlib.revisionspec import revspec_registry
108
136
    dwim_revspecs.append(RevisionSpec_git)
109
137
 
110
138
 
111
 
class GitBzrDirFormat(bzrdir.BzrDirFormat):
 
139
class GitControlDirFormat(ControlDirFormat):
112
140
 
113
141
    _lock_class = TransportLock
114
142
 
115
143
    colocated_branches = True
116
144
 
 
145
    def __eq__(self, other):
 
146
        return type(self) == type(other)
 
147
 
117
148
    def is_supported(self):
118
149
        return True
119
150
 
121
152
        return "git"
122
153
 
123
154
 
124
 
class LocalGitBzrDirFormat(GitBzrDirFormat):
125
 
    """The .git directory control format."""
126
 
 
127
 
    @classmethod
128
 
    def _known_formats(self):
129
 
        return set([LocalGitBzrDirFormat()])
130
 
 
131
 
    def open(self, transport, _found=None):
132
 
        """Open this directory.
133
 
 
134
 
        """
135
 
        lazy_check_versions()
136
 
        # we dont grok readonly - git isn't integrated with transport.
137
 
        from bzrlib.transport.local import LocalTransport
138
 
        if isinstance(transport, LocalTransport):
139
 
            import dulwich
140
 
            path = transport.local_abspath(".").encode(osutils._fs_enc)
141
 
            gitrepo = dulwich.repo.Repo(path)
142
 
        else:
143
 
            from bzrlib.plugins.git.transportgit import TransportRepo
144
 
            gitrepo = TransportRepo(transport)
145
 
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
146
 
        lockfiles = GitLockableFiles(transport, GitLock())
147
 
        return LocalGitDir(transport, lockfiles, gitrepo, self)
148
 
 
149
 
    @classmethod
150
 
    def probe_transport(klass, transport):
 
155
class LocalGitProber(Prober):
 
156
 
 
157
    def probe_transport(self, transport):
151
158
        try:
152
159
            if not transport.has_any(['info/refs', '.git/branches',
153
160
                                      'branches']):
159
166
            raise bzr_errors.NotBranchError(path=transport.base)
160
167
        lazy_check_versions()
161
168
        import dulwich
162
 
        format = klass()
 
169
        format = LocalGitControlDirFormat()
163
170
        try:
164
171
            format.open(transport)
165
172
            return format
167
174
            raise bzr_errors.NotBranchError(path=transport.base)
168
175
        raise bzr_errors.NotBranchError(path=transport.base)
169
176
 
 
177
 
 
178
class LocalGitControlDirFormat(GitControlDirFormat):
 
179
    """The .git directory control format."""
 
180
 
 
181
    @classmethod
 
182
    def _known_formats(self):
 
183
        return set([LocalGitControlDirFormat()])
 
184
 
 
185
    def open(self, transport, _found=None):
 
186
        """Open this directory.
 
187
 
 
188
        """
 
189
        lazy_check_versions()
 
190
        from bzrlib.plugins.git.transportgit import TransportRepo
 
191
        gitrepo = TransportRepo(transport)
 
192
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
 
193
        lockfiles = GitLockableFiles(transport, GitLock())
 
194
        return LocalGitDir(transport, lockfiles, gitrepo, self)
 
195
 
 
196
    @classmethod
 
197
    def probe_transport(klass, transport):
 
198
        prober = LocalGitProber()
 
199
        return prober.probe_transport(transport)
 
200
 
170
201
    def get_format_description(self):
171
202
        return "Local Git Repository"
172
203
 
189
220
        return True
190
221
 
191
222
 
192
 
class RemoteGitBzrDirFormat(GitBzrDirFormat):
 
223
class RemoteGitProber(Prober):
 
224
 
 
225
    def probe_transport(self, transport):
 
226
        url = transport.base
 
227
        if url.startswith('readonly+'):
 
228
            url = url[len('readonly+'):]
 
229
        if (not url.startswith("git://") and not url.startswith("git+")):
 
230
            raise bzr_errors.NotBranchError(transport.base)
 
231
        # little ugly, but works
 
232
        format = RemoteGitControlDirFormat()
 
233
        from bzrlib.plugins.git.remote import GitSmartTransport
 
234
        if not isinstance(transport, GitSmartTransport):
 
235
            raise bzr_errors.NotBranchError(transport.base)
 
236
        return format
 
237
 
 
238
 
 
239
 
 
240
class RemoteGitControlDirFormat(GitControlDirFormat):
193
241
    """The .git directory control format."""
194
242
 
 
243
    supports_workingtrees = False
 
244
 
195
245
    @classmethod
196
246
    def _known_formats(self):
197
 
        return set([RemoteGitBzrDirFormat()])
 
247
        return set([RemoteGitControlDirFormat()])
198
248
 
199
249
    def open(self, transport, _found=None):
200
250
        """Open this directory.
216
266
    @classmethod
217
267
    def probe_transport(klass, transport):
218
268
        """Our format is present if the transport ends in '.not/'."""
219
 
        url = transport.base
220
 
        if url.startswith('readonly+'):
221
 
            url = url[len('readonly+'):]
222
 
        if (not url.startswith("git://") and not url.startswith("git+")):
223
 
            raise bzr_errors.NotBranchError(transport.base)
224
 
        # little ugly, but works
225
 
        format = klass()
226
 
        from bzrlib.plugins.git.remote import GitSmartTransport
227
 
        if not isinstance(transport, GitSmartTransport):
228
 
            raise bzr_errors.NotBranchError(transport.base)
229
 
        return format
 
269
        prober = RemoteGitProber()
 
270
        return prober.probe_transport(transport)
230
271
 
231
272
    def get_format_description(self):
232
273
        return "Remote Git Repository"
238
279
        raise bzr_errors.UninitializableFormat(self)
239
280
 
240
281
 
241
 
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
242
 
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
 
282
if has_controldir:
 
283
    ControlDirFormat.register_format(LocalGitControlDirFormat())
 
284
    ControlDirFormat.register_format(RemoteGitControlDirFormat())
 
285
    ControlDirFormat.register_prober(LocalGitProber)
 
286
    ControlDirFormat.register_prober(RemoteGitProber)
 
287
else:
 
288
    ControlDirFormat.register_control_format(LocalGitControlDirFormat)
 
289
    ControlDirFormat.register_control_format(RemoteGitControlDirFormat)
243
290
 
244
291
register_transport_proto('git://',
245
292
        help="Access using the Git smart server protocol.")
284
331
repository_network_format_registry.register_lazy('git',
285
332
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
286
333
 
287
 
from bzrlib.bzrdir import (
288
 
    network_format_registry as bzrdir_network_format_registry,
289
 
    )
290
 
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
 
334
try:
 
335
    from bzrlib.controldir import (
 
336
        network_format_registry as controldir_network_format_registry,
 
337
        )
 
338
except ImportError:
 
339
    from bzrlib.bzrdir import (
 
340
        network_format_registry as controldir_network_format_registry,
 
341
        )
 
342
controldir_network_format_registry.register('git', GitControlDirFormat)
291
343
 
292
344
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
293
345
                                   'send_git', 'Git am-style diff format')
294
346
 
 
347
topic_registry.register_lazy('git',
 
348
                             'bzrlib.plugins.git.help',
 
349
                             'help_git', 'Using Bazaar with Git')
 
350
 
295
351
try:
296
352
    from bzrlib.diff import format_registry as diff_format_registry
297
353
except ImportError: