File: _ssh.py

package info (click to toggle)
hg-git 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,372 kB
  • sloc: python: 8,708; sh: 185; makefile: 23
file content (43 lines) | stat: -rw-r--r-- 1,386 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import subprocess

from dulwich.client import SSHGitClient, SubprocessWrapper

from mercurial import pycompat
from mercurial.utils import procutil


class SSHVendor(object):
    """Parent class for ui-linked Vendor classes."""


def generate_ssh_vendor(ui):
    """
    Allows dulwich to use hg's ui.ssh config. The dulwich.client.get_ssh_vendor
    property should point to the return value.
    """

    class _Vendor(SSHVendor):
        def run_command(
            self, host, command, username=None, port=None, **kwargs
        ):
            assert isinstance(command, str)
            command = command.encode(SSHGitClient.DEFAULT_ENCODING)
            sshcmd = ui.config(b"ui", b"ssh", b"ssh")
            args = procutil.sshargs(
                sshcmd, pycompat.bytesurl(host), username, port
            )
            cmd = b'%s %s %s' % (sshcmd, args, procutil.shellquote(command))
            # consistent with mercurial
            ui.debug(b'running %s\n' % cmd)
            # we cannot use Mercurial's procutil.popen4() since it
            # always redirects stderr into a pipe
            proc = subprocess.Popen(
                procutil.tonativestr(cmd),
                shell=True,
                bufsize=0,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
            )
            return SubprocessWrapper(proc)

    return _Vendor