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,6 +282,12 @@ class Remote(object):
|
|||||||
u += '/'
|
u += '/'
|
||||||
u += 'ssh_info'
|
u += 'ssh_info'
|
||||||
|
|
||||||
|
if u in REVIEW_CACHE:
|
||||||
|
info = REVIEW_CACHE[u]
|
||||||
|
self._review_protocol = info[0]
|
||||||
|
self._review_host = info[1]
|
||||||
|
self._review_port = info[2]
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
info = urlopen(u).read()
|
info = urlopen(u).read()
|
||||||
if info == 'NOT_AVAILABLE':
|
if info == 'NOT_AVAILABLE':
|
||||||
@ -293,12 +301,18 @@ class Remote(object):
|
|||||||
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:
|
except HTTPError, e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
self._review_protocol = 'http-post'
|
self._review_protocol = 'http-post'
|
||||||
|
self._review_host = None
|
||||||
|
self._review_port = None
|
||||||
else:
|
else:
|
||||||
raise UploadError('Cannot guess Gerrit version')
|
raise UploadError('Cannot guess Gerrit version')
|
||||||
|
|
||||||
|
REVIEW_CACHE[u] = (
|
||||||
|
self._review_protocol,
|
||||||
|
self._review_host,
|
||||||
|
self._review_port)
|
||||||
return self._review_protocol
|
return self._review_protocol
|
||||||
|
|
||||||
def SshReviewUrl(self, userEmail):
|
def SshReviewUrl(self, userEmail):
|
||||||
|
Loading…
Reference in New Issue
Block a user