From 896d5dffd313a2ad91fd8bee750241a6512b25dc Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 21 Apr 2009 14:51:04 -0700 Subject: [PATCH] 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 --- git_config.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/git_config.py b/git_config.py index 163b0809..53b52c85 100644 --- a/git_config.py +++ b/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):