/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

Fix two mistakes in 'bzr help git'.

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
    )
59
64
    branch_name_to_ref,
60
65
    )
61
66
 
62
 
import dulwich as git
 
67
import dulwich.client
63
68
from dulwich.errors import (
64
69
    GitProtocolError,
65
70
    )
67
72
    Pack,
68
73
    ThinPackData,
69
74
    )
 
75
from dulwich.protocol import Protocol
70
76
import os
71
77
import tempfile
72
78
import urllib
164
170
            ret = self._client
165
171
            self._client = None
166
172
            return ret
167
 
        return git.client.TCPGitClient(self._host, self._port,
 
173
        return dulwich.client.TCPGitClient(self._host, self._port,
168
174
            thin_packs=thin_packs, report_activity=self._report_activity)
169
175
 
170
176
 
 
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
 
171
219
class SSHGitSmartTransport(GitSmartTransport):
172
220
 
173
221
    _scheme = 'git+ssh'
183
231
            self._client = None
184
232
            return ret
185
233
        location_config = config.LocationConfig(self.base)
186
 
        client = git.client.SSHGitClient(self._host, self._port, self._username,
 
234
        client = BzrGitSSHGitClient(self._host, self._port, self._username,
187
235
            thin_packs=thin_packs, report_activity=self._report_activity)
188
236
        # Set up alternate pack program paths
189
237
        upload_pack = location_config.get_user_option('git_upload_pack')
204
252
        self._lockfiles = lockfiles
205
253
        self._mode_check_done = None
206
254
 
 
255
    @property
 
256
    def user_url(self):
 
257
        return self.control_url
 
258
 
207
259
    def _branch_name_to_ref(self, name, default=None):
208
260
        return branch_name_to_ref(name, default=default)
209
261
 
210
262
    def open_repository(self):
211
263
        return RemoteGitRepository(self, self._lockfiles)
212
264
 
213
 
    def _open_branch(self, name=None, ignore_fallbacks=False, 
214
 
                    unsupported=False):
 
265
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=False):
215
266
        repo = self.open_repository()
216
267
        refname = self._branch_name_to_ref(name)
217
268
        return RemoteGitBranch(self, repo, refname, self._lockfiles)
262
313
            os.remove(self._data_path)
263
314
 
264
315
 
 
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
 
265
347
class RemoteGitRepository(GitRepository):
266
348
 
267
349
    def __init__(self, gitdir, lockfiles):
269
351
        self._refs = None
270
352
 
271
353
    @property
 
354
    def user_url(self):
 
355
        return self.control_url
 
356
 
 
357
    @property
272
358
    def inventories(self):
273
359
        raise GitSmartRemoteNotSupported()
274
360
 
322
408
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
323
409
 
324
410
 
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
 
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))
336
420
 
337
421
    def set_tag(self, name, revid):
338
422
        # FIXME: Not supported yet, should do a push of a new ref
346
430
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
347
431
                lockfiles)
348
432
 
 
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
 
349
441
    def revision_history(self):
350
442
        raise GitSmartRemoteNotSupported()
351
443