41
42
from bzrlib.plugins.git.branch import (
46
from bzrlib.plugins.git.dir import (
44
52
from bzrlib.plugins.git.errors import (
45
53
GitSmartRemoteNotSupported,
48
from bzrlib.plugins.git.dir import (
51
56
from bzrlib.plugins.git.mapping import (
164
170
ret = self._client
165
171
self._client = None
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)
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)
171
219
class SSHGitSmartTransport(GitSmartTransport):
173
221
_scheme = 'git+ssh'
183
231
self._client = None
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
257
return self.control_url
207
259
def _branch_name_to_ref(self, name, default=None):
208
260
return branch_name_to_ref(name, default=default)
210
262
def open_repository(self):
211
263
return RemoteGitRepository(self, self._lockfiles)
213
def _open_branch(self, name=None, ignore_fallbacks=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)
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)
265
347
class RemoteGitRepository(GitRepository):
267
349
def __init__(self, gitdir, lockfiles):
322
408
return mapping.revision_id_foreign_to_bzr(foreign_revid)
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)
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))
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,
435
return self.control_url
438
def control_url(self):
349
441
def revision_history(self):
350
442
raise GitSmartRemoteNotSupported()