diff options
author | Shawn O. Pearce <sop@google.com> | 2009-01-05 16:18:58 -0800 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-01-05 16:34:27 -0800 |
commit | b54a392c9a267a06058b663377282c9dcec6878e (patch) | |
tree | 556c81394730f0d52b23a8a79fe302e29b923916 /git_config.py | |
parent | 21f73854006d5e989b5ba6b58e6da198212f2e4b (diff) | |
download | git-repo-b54a392c9a267a06058b663377282c9dcec6878e.tar.gz |
Support Gerrit2's ssh:// based uploadv1.5
In Gerrit2 uploads are sent over "git push ssh://...", as this
is a more efficient transport and is easier to code from external
scripts and/or direct command line usage by an end-user.
Gerrit1's HTTP POST based format is assumed if the review server
does not have the /ssh_info URL available on it.
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'git_config.py')
-rw-r--r-- | git_config.py | 42 |
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 @@ | |||
16 | import os | 16 | import os |
17 | import re | 17 | import re |
18 | import sys | 18 | import sys |
19 | from error import GitError | 19 | from urllib2 import urlopen, HTTPError |
20 | from error import GitError, UploadError | ||
20 | from git_command import GitCommand | 21 | from git_command import GitCommand |
21 | 22 | ||
22 | R_HEADS = 'refs/heads/' | 23 | R_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. |