Переглянути джерело

Fix UnboundLocalError: local variable 'port' when using SSH

If the SSH URL doesn't contain a port number, but uses the ssh://
or git+ssh:// syntax we raised a Python runtime error due to the
'port' local variable not being assigned a value.  Default it to
the IANA assigned port for SSH, 22.

Signed-off-by: Shawn O. Pearce <sop@google.com>
Shawn O. Pearce 17 роки тому
батько
коміт
896d5dffd3
1 змінених файлів з 4 додано та 5 видалено
  1. 4 5
      git_config.py

+ 4 - 5
git_config.py

@@ -337,12 +337,9 @@ class RefSpec(object):
 _ssh_cache = {}
 _ssh_master = True
 
-def _open_ssh(host, port=None):
+def _open_ssh(host, port):
   global _ssh_master
 
-  if port is None:
-    port = 22
-
   key = '%s:%s' % (host, port)
   if key in _ssh_cache:
     return True
@@ -397,6 +394,8 @@ def _preconnect(url):
     host = m.group(2)
     if ':' in host:
       host, port = host.split(':')
+    else:
+      port = 22
     if scheme in ('ssh', 'git+ssh', 'ssh+git'):
       return _open_ssh(host, port)
     return False
@@ -404,7 +403,7 @@ def _preconnect(url):
   m = URI_SCP.match(url)
   if m:
     host = m.group(1)
-    return _open_ssh(host)
+    return _open_ssh(host, 22)
 
 
 class Remote(object):