/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
    )
64
59
    branch_name_to_ref,
65
60
    )
66
61
 
67
 
import dulwich.client
 
62
import dulwich as git
68
63
from dulwich.errors import (
69
64
    GitProtocolError,
70
65
    )
72
67
    Pack,
73
68
    ThinPackData,
74
69
    )
75
 
from dulwich.protocol import Protocol
76
70
import os
77
71
import tempfile
78
72
import urllib
170
164
            ret = self._client
171
165
            self._client = None
172
166
            return ret
173
 
        return dulwich.client.TCPGitClient(self._host, self._port,
 
167
        return git.client.TCPGitClient(self._host, self._port,
174
168
            thin_packs=thin_packs, report_activity=self._report_activity)
175
169
 
176
170
 
177
 
class BzrGitSSHGitClient(dulwich.client.SSHGitClient):
178
 
 
179
 
    def __init__(self, *args, **kwargs):
180
 
        super(BzrGitSSHGitClient, self).__init__(*args, **kwargs)
181
 
        self._read_buffer = ""
182
 
 
183
 
    def _can_read(self):
184
 
        if self._read_buffer != "":
185
 
            return True
186
 
        self._read_buffer = self._read(1)
187
 
        return (self._read_buffer != "")
188
 
 
189
 
    def _read(self, count):
190
 
        ret = self._read_buffer[:count]
191
 
        self._read_buffer = self._read_buffer[len(ret):]
192
 
        while len(ret) < count:
193
 
            if self._io_kind == "socket":
194
 
                ret += self._io_object.recv(count - len(ret))
195
 
            else:
196
 
                ret += self._io_object[0].read(count - len(ret))
197
 
        return ret
198
 
 
199
 
    def _write(self, data):
200
 
        if self._io_kind == "socket":
201
 
            self._io_object.send(data)
202
 
        else:
203
 
            self._io_object[1].write(data)
204
 
 
205
 
    def _connect(self, cmd, path):
206
 
        from bzrlib.transport import ssh as _mod_ssh
207
 
        vendor = _mod_ssh._get_ssh_vendor()
208
 
        self._ssh_connection = vendor.connect_ssh(self.username, None,
209
 
            self.host, self.port, command=[self._get_cmd_path(cmd), path])
210
 
        self._io_kind, self._io_object = self._ssh_connection.get_sock_or_pipes()
211
 
        if self._io_kind not in ("socket", "pipes"):
212
 
            raise AssertionError(
213
 
                "Unexpected io_kind %r from %r"
214
 
                % (self._io_kind, self._ssh_connection))
215
 
        return (Protocol(self._read, self._write,
216
 
            report_activity=self._report_activity), self._can_read)
217
 
 
218
 
 
219
171
class SSHGitSmartTransport(GitSmartTransport):
220
172
 
221
173
    _scheme = 'git+ssh'
231
183
            self._client = None
232
184
            return ret
233
185
        location_config = config.LocationConfig(self.base)
234
 
        client = BzrGitSSHGitClient(self._host, self._port, self._username,
 
186
        client = git.client.SSHGitClient(self._host, self._port, self._username,
235
187
            thin_packs=thin_packs, report_activity=self._report_activity)
236
188
        # Set up alternate pack program paths
237
189
        upload_pack = location_config.get_user_option('git_upload_pack')
252
204
        self._lockfiles = lockfiles
253
205
        self._mode_check_done = None
254
206
 
255
 
    @property
256
 
    def user_url(self):
257
 
        return self.control_url
258
 
 
259
207
    def _branch_name_to_ref(self, name, default=None):
260
208
        return branch_name_to_ref(name, default=default)
261
209
 
262
210
    def open_repository(self):
263
211
        return RemoteGitRepository(self, self._lockfiles)
264
212
 
265
 
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=False):
 
213
    def _open_branch(self, name=None, ignore_fallbacks=False, 
 
214
                    unsupported=False):
266
215
        repo = self.open_repository()
267
216
        refname = self._branch_name_to_ref(name)
268
217
        return RemoteGitBranch(self, repo, refname, self._lockfiles)
313
262
            os.remove(self._data_path)
314
263
 
315
264
 
316
 
class RemoteGitControlDirFormat(GitControlDirFormat):
317
 
    """The .git directory control format."""
318
 
 
319
 
    supports_workingtrees = False
320
 
 
321
 
    @classmethod
322
 
    def _known_formats(self):
323
 
        return set([RemoteGitControlDirFormat()])
324
 
 
325
 
    def open(self, transport, _found=None):
326
 
        """Open this directory.
327
 
 
328
 
        """
329
 
        # we dont grok readonly - git isn't integrated with transport.
330
 
        url = transport.base
331
 
        if url.startswith('readonly+'):
332
 
            url = url[len('readonly+'):]
333
 
        if (not url.startswith("git://") and not url.startswith("git+")):
334
 
            raise NotBranchError(transport.base)
335
 
        if not isinstance(transport, GitSmartTransport):
336
 
            raise NotBranchError(transport.base)
337
 
        lockfiles = GitLockableFiles(transport, GitLock())
338
 
        return RemoteGitDir(transport, lockfiles, self)
339
 
 
340
 
    def get_format_description(self):
341
 
        return "Remote Git Repository"
342
 
 
343
 
    def initialize_on_transport(self, transport):
344
 
        raise UninitializableFormat(self)
345
 
 
346
 
 
347
265
class RemoteGitRepository(GitRepository):
348
266
 
349
267
    def __init__(self, gitdir, lockfiles):
351
269
        self._refs = None
352
270
 
353
271
    @property
354
 
    def user_url(self):
355
 
        return self.control_url
356
 
 
357
 
    @property
358
272
    def inventories(self):
359
273
        raise GitSmartRemoteNotSupported()
360
274
 
408
322
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
409
323
 
410
324
 
411
 
class RemoteGitTagDict(GitTags):
412
 
 
413
 
    def get_refs(self):
414
 
        return self.repository.get_refs()
415
 
 
416
 
    def _iter_tag_refs(self, refs):
417
 
        for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
418
 
            yield (k, peeled, unpeeled,
419
 
                  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
420
336
 
421
337
    def set_tag(self, name, revid):
422
338
        # FIXME: Not supported yet, should do a push of a new ref
430
346
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
431
347
                lockfiles)
432
348
 
433
 
    @property
434
 
    def user_url(self):
435
 
        return self.control_url
436
 
 
437
 
    @property
438
 
    def control_url(self):
439
 
        return self.base
440
 
 
441
349
    def revision_history(self):
442
350
        raise GitSmartRemoteNotSupported()
443
351