from io import BytesIO, BufferedReader
import dulwich
import select
+import shlex
import socket
import subprocess
import sys
"""
if determine_wants is None:
determine_wants = target.object_store.determine_wants_all
+
f, commit, abort = target.object_store.add_pack()
try:
result = self.fetch_pack(
TraditionalGitClient.__init__(self, *args, **kwargs)
def _connect(self, cmd, path):
+ if type(cmd) is not bytes:
+ raise TypeError(path)
+ if type(path) is not bytes:
+ raise TypeError(path)
sockaddrs = socket.getaddrinfo(
self._host, self._port, socket.AF_UNSPEC, socket.SOCK_STREAM)
s = None
report_activity=self._report_activity)
if path.startswith(b"/~"):
path = path[1:]
- proto.send_cmd(b'git-' + cmd, path, b'host=' + self._host)
+ # TODO(jelmer): Alternative to ascii?
+ proto.send_cmd(b'git-' + cmd, path, b'host=' + self._host.encode('ascii'))
return proto, lambda: _fileno_can_read(s)
git_command = None
def _connect(self, service, path):
+ if type(service) is not bytes:
+ raise TypeError(path)
+ if type(path) is not bytes:
+ raise TypeError(path)
import subprocess
if self.git_command is None:
git_command = find_git_command()
"""SSH vendor that shells out to the local 'ssh' command."""
def run_command(self, host, command, username=None, port=None):
- if type(command) is not list:
+ if (type(command) is not list or
+ not all([isinstance(b, bytes) for b in command])):
raise TypeError(command)
+
import subprocess
#FIXME: This has no way to deal with passwords..
args = ['ssh', '-x']
def run_command(self, host, command, username=None, port=None,
progress_stderr=None):
- if type(command) is not list:
+ if (type(command) is not list or
+ not all([isinstance(b, bytes) for b in command])):
raise TypeError(command)
# Paramiko needs an explicit port. None is not valid
if port is None:
channel = client.get_transport().open_session()
# Run commands
- channel.exec_command(*command)
+ channel.exec_command(subprocess.list2cmdline(command))
return ParamikoWrapper(
client, channel, progress_stderr=progress_stderr)
self.alternative_paths = {}
def _get_cmd_path(self, cmd):
- cmd = cmd.decode('ascii')
- return self.alternative_paths.get(cmd, 'git-' + cmd)
+ cmd = self.alternative_paths.get(cmd, b'git-' + cmd)
+ assert isinstance(cmd, bytes)
+ if sys.version_info[:2] <= (2, 6):
+ return shlex.split(cmd)
+ else:
+ # TODO(jelmer): Don't decode/encode here
+ return [x.encode('ascii') for x in shlex.split(cmd.decode('ascii'))]
def _connect(self, cmd, path):
- if path.startswith("/~"):
+ if type(cmd) is not bytes:
+ raise TypeError(path)
+ if type(path) is not bytes:
+ raise TypeError(path)
+ if path.startswith(b"/~"):
path = path[1:]
+ argv = self._get_cmd_path(cmd) + [path]
con = get_ssh_vendor().run_command(
- self.host, [self._get_cmd_path(cmd), path],
- port=self.port, username=self.username)
+ self.host, argv, port=self.port, username=self.username)
return (Protocol(con.read, con.write, con.close,
report_activity=self._report_activity),
con.can_read)