summaryrefslogtreecommitdiffstats
path: root/git_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'git_config.py')
-rw-r--r--git_config.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/git_config.py b/git_config.py
index 9ddb2edc..ed5a44a4 100644
--- a/git_config.py
+++ b/git_config.py
@@ -16,7 +16,8 @@
16import os 16import os
17import re 17import re
18import sys 18import sys
19from error import GitError 19from urllib2 import urlopen, HTTPError
20from error import GitError, UploadError
20from git_command import GitCommand 21from git_command import GitCommand
21 22
22R_HEADS = 'refs/heads/' 23R_HEADS = 'refs/heads/'
@@ -261,6 +262,45 @@ class Remote(object):
261 self.projectname = self._Get('projectname') 262 self.projectname = self._Get('projectname')
262 self.fetch = map(lambda x: RefSpec.FromString(x), 263 self.fetch = map(lambda x: RefSpec.FromString(x),
263 self._Get('fetch', all=True)) 264 self._Get('fetch', all=True))
265 self._review_protocol = None
266
267 @property
268 def ReviewProtocol(self):
269 if self._review_protocol is None:
270 if self.review is None:
271 return None
272
273 u = self.review
274 if not u.startswith('http:') and not u.startswith('https:'):
275 u = 'http://%s' % u
276 if not u.endswith('/'):
277 u += '/'
278 u += 'ssh_info'
279
280 try:
281 info = urlopen(u).read()
282 if info == 'NOT_AVAILABLE':
283 raise UploadError('Upload over ssh unavailable')
284
285 self._review_protocol = 'ssh'
286 self._review_host = info.split(" ")[0]
287 self._review_port = info.split(" ")[1]
288
289 except HTTPError, e:
290 if e.code == 404:
291 self._review_protocol = 'http-post'
292 else:
293 raise UploadError('Cannot guess Gerrit version')
294 return self._review_protocol
295
296 def SshReviewUrl(self, userEmail):
297 if self.ReviewProtocol != 'ssh':
298 return None
299 return 'ssh://%s@%s:%s/%s' % (
300 userEmail.split("@")[0],
301 self._review_host,
302 self._review_port,
303 self.projectname)
264 304
265 def ToLocal(self, rev): 305 def ToLocal(self, rev):
266 """Convert a remote revision string to something we have locally. 306 """Convert a remote revision string to something we have locally.