/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 remote.py

Avoid NotImplementedError.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from bzrlib import (
18
18
    config,
19
19
    debug,
20
 
    tag,
21
20
    trace,
22
21
    ui,
23
22
    urlutils,
27
26
    InvalidRevisionId,
28
27
    NoSuchFile,
29
28
    NoSuchRevision,
 
29
    NotBranchError,
30
30
    NotLocalUrl,
 
31
    UninitializableFormat,
31
32
    )
32
33
from bzrlib.transport import (
33
34
    Transport,
40
41
 
41
42
from bzrlib.plugins.git.branch import (
42
43
    GitBranch,
 
44
    GitTags,
 
45
    )
 
46
from bzrlib.plugins.git.dir import (
 
47
    GitControlDirFormat,
 
48
    GitDir,
 
49
    GitLockableFiles,
 
50
    GitLock,
43
51
    )
44
52
from bzrlib.plugins.git.errors import (
45
53
    GitSmartRemoteNotSupported,
46
54
    NoSuchRef,
47
55
    )
48
 
from bzrlib.plugins.git.dir import (
49
 
    GitDir,
50
 
    )
51
56
from bzrlib.plugins.git.mapping import (
52
57
    mapping_registry,
53
58
    )
65
70
    )
66
71
from dulwich.pack import (
67
72
    Pack,
68
 
    ThinPackData,
 
73
    PackData,
69
74
    )
70
75
import os
71
76
import tempfile
97
102
    return (host, port, username, path)
98
103
 
99
104
 
 
105
def parse_git_error(url, message):
 
106
    """Parse a remote git server error and return a bzr exception.
 
107
 
 
108
    :param url: URL of the remote repository
 
109
    :param message: Message sent by the remote git server
 
110
    """
 
111
    message = str(message).strip()
 
112
    if message.startswith("Could not find Repository "):
 
113
        return NotBranchError(url, message)
 
114
    # Don't know, just return it to the user as-is
 
115
    return BzrError(message)
 
116
 
 
117
 
100
118
class GitSmartTransport(Transport):
101
119
 
102
120
    def __init__(self, url, _client=None):
129
147
            return client.fetch_pack(self._get_path(), determine_wants,
130
148
                graph_walker, pack_data, progress)
131
149
        except GitProtocolError, e:
132
 
            raise BzrError(e)
 
150
            raise parse_git_error(self.external_url(), e)
133
151
 
134
152
    def send_pack(self, get_changed_refs, generate_pack_contents):
135
153
        client = self._get_client(thin_packs=False)
137
155
            return client.send_pack(self._get_path(), get_changed_refs,
138
156
                generate_pack_contents)
139
157
        except GitProtocolError, e:
140
 
            raise BzrError(e)
 
158
            raise parse_git_error(self.external_url(), e)
141
159
 
142
160
    def get(self, path):
143
161
        raise NoSuchFile(path)
204
222
        self._lockfiles = lockfiles
205
223
        self._mode_check_done = None
206
224
 
207
 
    def _branch_name_to_ref(self, name, default=None):
208
 
        return branch_name_to_ref(name, default=default)
 
225
    @property
 
226
    def user_url(self):
 
227
        return self.control_url
 
228
 
 
229
    @property
 
230
    def user_transport(self):
 
231
        return self.root_transport
209
232
 
210
233
    def open_repository(self):
211
234
        return RemoteGitRepository(self, self._lockfiles)
212
235
 
213
 
    def _open_branch(self, name=None, ignore_fallbacks=False, 
214
 
                    unsupported=False):
 
236
    def open_branch(self, name=None, unsupported=False,
 
237
            ignore_fallbacks=False):
215
238
        repo = self.open_repository()
216
 
        refname = self._branch_name_to_ref(name)
 
239
        refname = self._get_selected_ref(name)
217
240
        return RemoteGitBranch(self, repo, refname, self._lockfiles)
218
241
 
219
242
    def open_workingtree(self, recommend_upgrade=False):
235
258
    @property
236
259
    def data(self):
237
260
        if self._data is None:
238
 
            self._data = ThinPackData(self.resolve_ext_ref, self._data_path)
 
261
            self._data = PackData(self._data_path)
239
262
        return self._data
240
263
 
241
264
    @property
262
285
            os.remove(self._data_path)
263
286
 
264
287
 
 
288
class RemoteGitControlDirFormat(GitControlDirFormat):
 
289
    """The .git directory control format."""
 
290
 
 
291
    supports_workingtrees = False
 
292
 
 
293
    @classmethod
 
294
    def _known_formats(self):
 
295
        return set([RemoteGitControlDirFormat()])
 
296
 
 
297
    def open(self, transport, _found=None):
 
298
        """Open this directory.
 
299
 
 
300
        """
 
301
        # we dont grok readonly - git isn't integrated with transport.
 
302
        url = transport.base
 
303
        if url.startswith('readonly+'):
 
304
            url = url[len('readonly+'):]
 
305
        if (not url.startswith("git://") and not url.startswith("git+")):
 
306
            raise NotBranchError(transport.base)
 
307
        if not isinstance(transport, GitSmartTransport):
 
308
            raise NotBranchError(transport.base)
 
309
        lockfiles = GitLockableFiles(transport, GitLock())
 
310
        return RemoteGitDir(transport, lockfiles, self)
 
311
 
 
312
    def get_format_description(self):
 
313
        return "Remote Git Repository"
 
314
 
 
315
    def initialize_on_transport(self, transport):
 
316
        raise UninitializableFormat(self)
 
317
 
 
318
 
265
319
class RemoteGitRepository(GitRepository):
266
320
 
267
321
    def __init__(self, gitdir, lockfiles):
269
323
        self._refs = None
270
324
 
271
325
    @property
272
 
    def inventories(self):
273
 
        raise GitSmartRemoteNotSupported()
274
 
 
275
 
    @property
276
 
    def revisions(self):
277
 
        raise GitSmartRemoteNotSupported()
278
 
 
279
 
    @property
280
 
    def texts(self):
 
326
    def user_url(self):
 
327
        return self.control_url
 
328
 
 
329
    def get_parent_map(self, revids):
281
330
        raise GitSmartRemoteNotSupported()
282
331
 
283
332
    def get_refs(self):
298
347
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
299
348
                      progress=None):
300
349
        fd, path = tempfile.mkstemp(suffix=".pack")
301
 
        self.fetch_pack(determine_wants, graph_walker,
302
 
            lambda x: os.write(fd, x), progress)
303
 
        os.close(fd)
 
350
        try:
 
351
            self.fetch_pack(determine_wants, graph_walker,
 
352
                lambda x: os.write(fd, x), progress)
 
353
        finally:
 
354
            os.close(fd)
304
355
        if os.path.getsize(path) == 0:
305
356
            return EmptyObjectStoreIterator()
306
357
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
322
373
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
323
374
 
324
375
 
325
 
class RemoteGitTagDict(tag.BasicTags):
326
 
 
327
 
    def __init__(self, branch):
328
 
        self.branch = branch
329
 
        self.repository = branch.repository
330
 
 
331
 
    def get_tag_dict(self):
332
 
        tags = {}
333
 
        for k, v in extract_tags(self.repository.get_refs()).iteritems():
334
 
            tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
335
 
        return tags
 
376
class RemoteGitTagDict(GitTags):
 
377
 
 
378
    def get_refs(self):
 
379
        return self.repository.get_refs()
 
380
 
 
381
    def _iter_tag_refs(self, refs):
 
382
        for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
 
383
            yield (k, peeled, unpeeled,
 
384
                  self.branch.mapping.revision_id_foreign_to_bzr(peeled))
336
385
 
337
386
    def set_tag(self, name, revid):
338
387
        # FIXME: Not supported yet, should do a push of a new ref
346
395
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
347
396
                lockfiles)
348
397
 
 
398
    def last_revision_info(self):
 
399
        raise GitSmartRemoteNotSupported()
 
400
 
 
401
    @property
 
402
    def user_url(self):
 
403
        return self.control_url
 
404
 
 
405
    @property
 
406
    def control_url(self):
 
407
        return self.base
 
408
 
349
409
    def revision_history(self):
350
410
        raise GitSmartRemoteNotSupported()
351
411
 
365
425
        if self._sha is not None:
366
426
            return self._sha
367
427
        heads = self.repository.get_refs()
368
 
        name = self.bzrdir._branch_name_to_ref(self.name, "HEAD")
 
428
        name = branch_name_to_ref(self.name, "HEAD")
369
429
        if name in heads:
370
430
            self._sha = heads[name]
371
431
        else: