/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 tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        )
63
63
    ControlDir = BzrDir
64
64
    ControlDirFormat = BzrDirFormat
 
65
    Prober = object
65
66
    has_controldir = False
66
67
else:
67
68
    has_controldir = True
151
152
        return "git"
152
153
 
153
154
 
154
 
class LocalGitControlDirFormat(GitControlDirFormat):
155
 
    """The .git directory control format."""
156
 
 
157
 
    @classmethod
158
 
    def _known_formats(self):
159
 
        return set([LocalGitControlDirFormat()])
160
 
 
161
 
    def open(self, transport, _found=None):
162
 
        """Open this directory.
163
 
 
164
 
        """
165
 
        lazy_check_versions()
166
 
        from bzrlib.plugins.git.transportgit import TransportRepo
167
 
        gitrepo = TransportRepo(transport)
168
 
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
169
 
        lockfiles = GitLockableFiles(transport, GitLock())
170
 
        return LocalGitDir(transport, lockfiles, gitrepo, self)
171
 
 
172
 
    @classmethod
173
 
    def probe_transport(klass, transport):
 
155
class LocalGitProber(Prober):
 
156
 
 
157
    def probe_transport(self, transport):
174
158
        try:
175
159
            if not transport.has_any(['info/refs', '.git/branches',
176
160
                                      'branches']):
182
166
            raise bzr_errors.NotBranchError(path=transport.base)
183
167
        lazy_check_versions()
184
168
        import dulwich
185
 
        format = klass()
 
169
        format = LocalGitControlDirFormat()
186
170
        try:
187
171
            format.open(transport)
188
172
            return format
190
174
            raise bzr_errors.NotBranchError(path=transport.base)
191
175
        raise bzr_errors.NotBranchError(path=transport.base)
192
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
 
193
201
    def get_format_description(self):
194
202
        return "Local Git Repository"
195
203
 
212
220
        return True
213
221
 
214
222
 
 
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 = klass()
 
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
 
215
240
class RemoteGitControlDirFormat(GitControlDirFormat):
216
241
    """The .git directory control format."""
217
242
 
239
264
    @classmethod
240
265
    def probe_transport(klass, transport):
241
266
        """Our format is present if the transport ends in '.not/'."""
242
 
        url = transport.base
243
 
        if url.startswith('readonly+'):
244
 
            url = url[len('readonly+'):]
245
 
        if (not url.startswith("git://") and not url.startswith("git+")):
246
 
            raise bzr_errors.NotBranchError(transport.base)
247
 
        # little ugly, but works
248
 
        format = klass()
249
 
        from bzrlib.plugins.git.remote import GitSmartTransport
250
 
        if not isinstance(transport, GitSmartTransport):
251
 
            raise bzr_errors.NotBranchError(transport.base)
252
 
        return format
 
267
        prober = RemoteGitProber()
 
268
        return prober.probe_transport(transport)
253
269
 
254
270
    def get_format_description(self):
255
271
        return "Remote Git Repository"
261
277
        raise bzr_errors.UninitializableFormat(self)
262
278
 
263
279
 
264
 
ControlDirFormat.register_control_format(LocalGitControlDirFormat)
265
 
ControlDirFormat.register_control_format(RemoteGitControlDirFormat)
 
280
if has_controldir:
 
281
    ControlDirFormat.register_format(LocalGitControlDirFormat)
 
282
    ControlDirFormat.register_format(RemoteGitControlDirFormat)
 
283
    ControlDirFormat.register_prober(LocalGitProber)
 
284
    ControlDirFormat.register_prober(RemoteGitProber)
 
285
else:
 
286
    ControlDirFormat.register_control_format(LocalGitControlDirFormat)
 
287
    ControlDirFormat.register_control_format(RemoteGitControlDirFormat)
266
288
 
267
289
register_transport_proto('git://',
268
290
        help="Access using the Git smart server protocol.")