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>
This commit is contained in:
Shawn O. Pearce 2009-04-21 14:51:04 -07:00
parent 9360966bd2
commit 896d5dffd3

View File

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