/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

recognize missing repositories

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
    )
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
 
 
225
    @property
 
226
    def user_url(self):
 
227
        return self.control_url
 
228
 
207
229
    def _branch_name_to_ref(self, name, default=None):
208
230
        return branch_name_to_ref(name, default=default)
209
231
 
210
232
    def open_repository(self):
211
233
        return RemoteGitRepository(self, self._lockfiles)
212
234
 
213
 
    def _open_branch(self, name=None, ignore_fallbacks=False, 
214
 
                    unsupported=False):
 
235
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=False):
215
236
        repo = self.open_repository()
216
237
        refname = self._branch_name_to_ref(name)
217
238
        return RemoteGitBranch(self, repo, refname, self._lockfiles)
262
283
            os.remove(self._data_path)
263
284
 
264
285
 
 
286
class RemoteGitControlDirFormat(GitControlDirFormat):
 
287
    """The .git directory control format."""
 
288
 
 
289
    supports_workingtrees = False
 
290
 
 
291
    @classmethod
 
292
    def _known_formats(self):
 
293
        return set([RemoteGitControlDirFormat()])
 
294
 
 
295
    def open(self, transport, _found=None):
 
296
        """Open this directory.
 
297
 
 
298
        """
 
299
        # we dont grok readonly - git isn't integrated with transport.
 
300
        url = transport.base
 
301
        if url.startswith('readonly+'):
 
302
            url = url[len('readonly+'):]
 
303
        if (not url.startswith("git://") and not url.startswith("git+")):
 
304
            raise NotBranchError(transport.base)
 
305
        if not isinstance(transport, GitSmartTransport):
 
306
            raise NotBranchError(transport.base)
 
307
        lockfiles = GitLockableFiles(transport, GitLock())
 
308
        return RemoteGitDir(transport, lockfiles, self)
 
309
 
 
310
    def get_format_description(self):
 
311
        return "Remote Git Repository"
 
312
 
 
313
    def initialize_on_transport(self, transport):
 
314
        raise UninitializableFormat(self)
 
315
 
 
316
 
265
317
class RemoteGitRepository(GitRepository):
266
318
 
267
319
    def __init__(self, gitdir, lockfiles):
269
321
        self._refs = None
270
322
 
271
323
    @property
 
324
    def user_url(self):
 
325
        return self.control_url
 
326
 
 
327
    @property
272
328
    def inventories(self):
273
329
        raise GitSmartRemoteNotSupported()
274
330
 
322
378
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
323
379
 
324
380
 
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
 
381
class RemoteGitTagDict(GitTags):
 
382
 
 
383
    def get_refs(self):
 
384
        return self.repository.get_refs()
 
385
 
 
386
    def _iter_tag_refs(self, refs):
 
387
        for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
 
388
            yield (k, peeled, unpeeled,
 
389
                  self.branch.mapping.revision_id_foreign_to_bzr(peeled))
336
390
 
337
391
    def set_tag(self, name, revid):
338
392
        # FIXME: Not supported yet, should do a push of a new ref
346
400
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
347
401
                lockfiles)
348
402
 
 
403
    @property
 
404
    def user_url(self):
 
405
        return self.control_url
 
406
 
 
407
    @property
 
408
    def control_url(self):
 
409
        return self.base
 
410
 
349
411
    def revision_history(self):
350
412
        raise GitSmartRemoteNotSupported()
351
413