瀏覽代碼

Do not invoke ssh with -p argument when no port has been specified.

This change allows local SSH configuration to choose the port number to
use when not explicitly set in the manifest.
Josh Guilfoyle 16 年之前
父節點
當前提交
4c0f670465
共有 1 個文件被更改,包括 12 次插入5 次删除
  1. 12 5
      git_config.py

+ 12 - 5
git_config.py

@@ -356,10 +356,14 @@ class RefSpec(object):
 _ssh_cache = {}
 _ssh_master = True
 
-def _open_ssh(host, port):
+def _open_ssh(host, port=None):
   global _ssh_master
 
-  key = '%s:%s' % (host, port)
+  if port is not None:
+    key = '%s:%s' % (host, port)
+  else:
+    key = host
+
   if key in _ssh_cache:
     return True
 
@@ -372,10 +376,13 @@ def _open_ssh(host, port):
 
   command = ['ssh',
              '-o','ControlPath %s' % _ssh_sock(),
-             '-p',str(port),
              '-M',
              '-N',
              host]
+
+  if port is not None:
+    command[3:3] = ['-p',str(port)]
+
   try:
     Trace(': %s', ' '.join(command))
     p = subprocess.Popen(command)
@@ -417,7 +424,7 @@ def _preconnect(url):
     if ':' in host:
       host, port = host.split(':')
     else:
-      port = 22
+      port = None
     if scheme in ('ssh', 'git+ssh', 'ssh+git'):
       return _open_ssh(host, port)
     return False
@@ -425,7 +432,7 @@ def _preconnect(url):
   m = URI_SCP.match(url)
   if m:
     host = m.group(1)
-    return _open_ssh(host, 22)
+    return _open_ssh(host)
 
   return False