42
41
from bzrlib.plugins.git.branch import (
46
from bzrlib.plugins.git.dir import (
52
44
from bzrlib.plugins.git.errors import (
53
45
GitSmartRemoteNotSupported,
48
from bzrlib.plugins.git.dir import (
56
51
from bzrlib.plugins.git.mapping import (
170
164
ret = self._client
171
165
self._client = None
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)
177
class BzrGitSSHGitClient(dulwich.client.SSHGitClient):
179
def __init__(self, *args, **kwargs):
180
super(BzrGitSSHGitClient, self).__init__(*args, **kwargs)
181
self._read_buffer = ""
184
if self._read_buffer != "":
186
self._read_buffer = self._read(1)
187
return (self._read_buffer != "")
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))
196
ret += self._io_object[0].read(count - len(ret))
199
def _write(self, data):
200
if self._io_kind == "socket":
201
self._io_object.send(data)
203
self._io_object[1].write(data)
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)
219
171
class SSHGitSmartTransport(GitSmartTransport):
221
173
_scheme = 'git+ssh'
231
183
self._client = None
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
257
return self.control_url
259
207
def _branch_name_to_ref(self, name, default=None):
260
208
return branch_name_to_ref(name, default=default)
262
210
def open_repository(self):
263
211
return RemoteGitRepository(self, self._lockfiles)
265
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=False):
213
def _open_branch(self, name=None, ignore_fallbacks=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)
316
class RemoteGitControlDirFormat(GitControlDirFormat):
317
"""The .git directory control format."""
319
supports_workingtrees = False
322
def _known_formats(self):
323
return set([RemoteGitControlDirFormat()])
325
def open(self, transport, _found=None):
326
"""Open this directory.
329
# we dont grok readonly - git isn't integrated with transport.
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)
340
def get_format_description(self):
341
return "Remote Git Repository"
343
def initialize_on_transport(self, transport):
344
raise UninitializableFormat(self)
347
265
class RemoteGitRepository(GitRepository):
349
267
def __init__(self, gitdir, lockfiles):
408
322
return mapping.revision_id_foreign_to_bzr(foreign_revid)
411
class RemoteGitTagDict(GitTags):
414
return self.repository.get_refs()
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):
327
def __init__(self, branch):
329
self.repository = branch.repository
331
def get_tag_dict(self):
333
for k, v in extract_tags(self.repository.get_refs()).iteritems():
334
tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
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,
435
return self.control_url
438
def control_url(self):
441
349
def revision_history(self):
442
350
raise GitSmartRemoteNotSupported()