/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

More work on roundtrip push support.

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,
20
21
    trace,
21
22
    ui,
22
23
    urlutils,
26
27
    InvalidRevisionId,
27
28
    NoSuchFile,
28
29
    NoSuchRevision,
29
 
    NotBranchError,
30
30
    NotLocalUrl,
31
 
    UninitializableFormat,
32
31
    )
33
32
from bzrlib.transport import (
34
33
    Transport,
41
40
 
42
41
from bzrlib.plugins.git.branch import (
43
42
    GitBranch,
44
 
    GitTags,
45
 
    )
46
 
from bzrlib.plugins.git.dir import (
47
 
    GitControlDirFormat,
48
 
    GitDir,
49
 
    GitLockableFiles,
50
 
    GitLock,
51
43
    )
52
44
from bzrlib.plugins.git.errors import (
53
45
    GitSmartRemoteNotSupported,
54
46
    NoSuchRef,
55
47
    )
 
48
from bzrlib.plugins.git.dir import (
 
49
    GitDir,
 
50
    )
56
51
from bzrlib.plugins.git.mapping import (
57
52
    mapping_registry,
58
53
    )
70
65
    )
71
66
from dulwich.pack import (
72
67
    Pack,
73
 
    PackData,
 
68
    ThinPackData,
74
69
    )
75
70
import os
76
71
import tempfile
102
97
    return (host, port, username, path)
103
98
 
104
99
 
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
 
 
118
100
class GitSmartTransport(Transport):
119
101
 
120
102
    def __init__(self, url, _client=None):
147
129
            return client.fetch_pack(self._get_path(), determine_wants,
148
130
                graph_walker, pack_data, progress)
149
131
        except GitProtocolError, e:
150
 
            raise parse_git_error(self.external_url(), e)
 
132
            raise BzrError(e)
151
133
 
152
134
    def send_pack(self, get_changed_refs, generate_pack_contents):
153
135
        client = self._get_client(thin_packs=False)
155
137
            return client.send_pack(self._get_path(), get_changed_refs,
156
138
                generate_pack_contents)
157
139
        except GitProtocolError, e:
158
 
            raise parse_git_error(self.external_url(), e)
 
140
            raise BzrError(e)
159
141
 
160
142
    def get(self, path):
161
143
        raise NoSuchFile(path)
222
204
        self._lockfiles = lockfiles
223
205
        self._mode_check_done = None
224
206
 
225
 
    @property
226
 
    def user_url(self):
227
 
        return self.control_url
228
 
 
229
207
    def _branch_name_to_ref(self, name, default=None):
230
208
        return branch_name_to_ref(name, default=default)
231
209
 
232
210
    def open_repository(self):
233
211
        return RemoteGitRepository(self, self._lockfiles)
234
212
 
235
 
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=False):
 
213
    def _open_branch(self, name=None, ignore_fallbacks=False, 
 
214
                    unsupported=False):
236
215
        repo = self.open_repository()
237
216
        refname = self._branch_name_to_ref(name)
238
217
        return RemoteGitBranch(self, repo, refname, self._lockfiles)
256
235
    @property
257
236
    def data(self):
258
237
        if self._data is None:
259
 
            self._data = PackData(self._data_path)
 
238
            self._data = ThinPackData(self.resolve_ext_ref, self._data_path)
260
239
        return self._data
261
240
 
262
241
    @property
283
262
            os.remove(self._data_path)
284
263
 
285
264
 
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
 
 
317
265
class RemoteGitRepository(GitRepository):
318
266
 
319
267
    def __init__(self, gitdir, lockfiles):
321
269
        self._refs = None
322
270
 
323
271
    @property
324
 
    def user_url(self):
325
 
        return self.control_url
326
 
 
327
 
    def get_parent_map(self, revids):
 
272
    def inventories(self):
 
273
        raise GitSmartRemoteNotSupported()
 
274
 
 
275
    @property
 
276
    def revisions(self):
 
277
        raise GitSmartRemoteNotSupported()
 
278
 
 
279
    @property
 
280
    def texts(self):
328
281
        raise GitSmartRemoteNotSupported()
329
282
 
330
283
    def get_refs(self):
345
298
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
346
299
                      progress=None):
347
300
        fd, path = tempfile.mkstemp(suffix=".pack")
348
 
        try:
349
 
            self.fetch_pack(determine_wants, graph_walker,
350
 
                lambda x: os.write(fd, x), progress)
351
 
        finally:
352
 
            os.close(fd)
 
301
        self.fetch_pack(determine_wants, graph_walker,
 
302
            lambda x: os.write(fd, x), progress)
 
303
        os.close(fd)
353
304
        if os.path.getsize(path) == 0:
354
305
            return EmptyObjectStoreIterator()
355
306
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
371
322
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
372
323
 
373
324
 
374
 
class RemoteGitTagDict(GitTags):
375
 
 
376
 
    def get_refs(self):
377
 
        return self.repository.get_refs()
378
 
 
379
 
    def _iter_tag_refs(self, refs):
380
 
        for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
381
 
            yield (k, peeled, unpeeled,
382
 
                  self.branch.mapping.revision_id_foreign_to_bzr(peeled))
 
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
383
336
 
384
337
    def set_tag(self, name, revid):
385
338
        # FIXME: Not supported yet, should do a push of a new ref
393
346
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
394
347
                lockfiles)
395
348
 
396
 
    @property
397
 
    def user_url(self):
398
 
        return self.control_url
399
 
 
400
 
    @property
401
 
    def control_url(self):
402
 
        return self.base
403
 
 
404
349
    def revision_history(self):
405
350
        raise GitSmartRemoteNotSupported()
406
351