mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Only lookup review server '/ssh_info' once per repo process
If the user has multiple projects to upload changes to, and they are all going to the same review server, we only need to query the '/ssh_info' data once. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
722acefdc4
commit
146fe902b7
@ -24,6 +24,8 @@ R_HEADS = 'refs/heads/'
|
|||||||
R_TAGS = 'refs/tags/'
|
R_TAGS = 'refs/tags/'
|
||||||
ID_RE = re.compile('^[0-9a-f]{40}$')
|
ID_RE = re.compile('^[0-9a-f]{40}$')
|
||||||
|
|
||||||
|
REVIEW_CACHE = dict()
|
||||||
|
|
||||||
def IsId(rev):
|
def IsId(rev):
|
||||||
return ID_RE.match(rev)
|
return ID_RE.match(rev)
|
||||||
|
|
||||||
@ -280,25 +282,37 @@ class Remote(object):
|
|||||||
u += '/'
|
u += '/'
|
||||||
u += 'ssh_info'
|
u += 'ssh_info'
|
||||||
|
|
||||||
try:
|
if u in REVIEW_CACHE:
|
||||||
info = urlopen(u).read()
|
info = REVIEW_CACHE[u]
|
||||||
if info == 'NOT_AVAILABLE':
|
self._review_protocol = info[0]
|
||||||
raise UploadError('Upload over ssh unavailable')
|
self._review_host = info[1]
|
||||||
if '<' in info:
|
self._review_port = info[2]
|
||||||
# Assume the server gave us some sort of HTML
|
else:
|
||||||
# response back, like maybe a login page.
|
try:
|
||||||
#
|
info = urlopen(u).read()
|
||||||
raise UploadError('Cannot read %s:\n%s' % (u, info))
|
if info == 'NOT_AVAILABLE':
|
||||||
|
raise UploadError('Upload over ssh unavailable')
|
||||||
|
if '<' in info:
|
||||||
|
# Assume the server gave us some sort of HTML
|
||||||
|
# response back, like maybe a login page.
|
||||||
|
#
|
||||||
|
raise UploadError('Cannot read %s:\n%s' % (u, info))
|
||||||
|
|
||||||
self._review_protocol = 'ssh'
|
self._review_protocol = 'ssh'
|
||||||
self._review_host = info.split(" ")[0]
|
self._review_host = info.split(" ")[0]
|
||||||
self._review_port = info.split(" ")[1]
|
self._review_port = info.split(" ")[1]
|
||||||
|
except HTTPError, e:
|
||||||
|
if e.code == 404:
|
||||||
|
self._review_protocol = 'http-post'
|
||||||
|
self._review_host = None
|
||||||
|
self._review_port = None
|
||||||
|
else:
|
||||||
|
raise UploadError('Cannot guess Gerrit version')
|
||||||
|
|
||||||
except HTTPError, e:
|
REVIEW_CACHE[u] = (
|
||||||
if e.code == 404:
|
self._review_protocol,
|
||||||
self._review_protocol = 'http-post'
|
self._review_host,
|
||||||
else:
|
self._review_port)
|
||||||
raise UploadError('Cannot guess Gerrit version')
|
|
||||||
return self._review_protocol
|
return self._review_protocol
|
||||||
|
|
||||||
def SshReviewUrl(self, userEmail):
|
def SshReviewUrl(self, userEmail):
|
||||||
|
Loading…
Reference in New Issue
Block a user