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 /project.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 'project.py')
-rw-r--r-- | project.py | 73 |
1 files changed, 50 insertions, 23 deletions
@@ -46,6 +46,8 @@ def _info(fmt, *args): | |||
46 | def not_rev(r): | 46 | def not_rev(r): |
47 | return '^' + r | 47 | return '^' + r |
48 | 48 | ||
49 | def sq(r): | ||
50 | return "'" + r.replace("'", "'\''") + "'" | ||
49 | 51 | ||
50 | hook_list = None | 52 | hook_list = None |
51 | def repo_hooks(): | 53 | def repo_hooks(): |
@@ -475,33 +477,58 @@ class Project(object): | |||
475 | if not dest_branch.startswith(R_HEADS): | 477 | if not dest_branch.startswith(R_HEADS): |
476 | dest_branch = R_HEADS + dest_branch | 478 | dest_branch = R_HEADS + dest_branch |
477 | 479 | ||
478 | base_list = [] | ||
479 | for name, id in self._allrefs.iteritems(): | ||
480 | if branch.remote.WritesTo(name): | ||
481 | base_list.append(not_rev(name)) | ||
482 | if not base_list: | ||
483 | raise GitError('no base refs, cannot upload %s' % branch.name) | ||
484 | |||
485 | if not branch.remote.projectname: | 480 | if not branch.remote.projectname: |
486 | branch.remote.projectname = self.name | 481 | branch.remote.projectname = self.name |
487 | branch.remote.Save() | 482 | branch.remote.Save() |
488 | 483 | ||
489 | print >>sys.stderr, '' | 484 | if branch.remote.ReviewProtocol == 'http-post': |
490 | _info("Uploading %s to %s:", branch.name, self.name) | 485 | base_list = [] |
491 | try: | 486 | for name, id in self._allrefs.iteritems(): |
492 | UploadBundle(project = self, | 487 | if branch.remote.WritesTo(name): |
493 | server = branch.remote.review, | 488 | base_list.append(not_rev(name)) |
494 | email = self.UserEmail, | 489 | if not base_list: |
495 | dest_project = branch.remote.projectname, | 490 | raise GitError('no base refs, cannot upload %s' % branch.name) |
496 | dest_branch = dest_branch, | 491 | |
497 | src_branch = R_HEADS + branch.name, | 492 | print >>sys.stderr, '' |
498 | bases = base_list, | 493 | _info("Uploading %s to %s:", branch.name, self.name) |
499 | people = people, | 494 | try: |
500 | replace_changes = replace_changes) | 495 | UploadBundle(project = self, |
501 | except proto_client.ClientLoginError: | 496 | server = branch.remote.review, |
502 | raise UploadError('Login failure') | 497 | email = self.UserEmail, |
503 | except urllib2.HTTPError, e: | 498 | dest_project = branch.remote.projectname, |
504 | raise UploadError('HTTP error %d' % e.code) | 499 | dest_branch = dest_branch, |
500 | src_branch = R_HEADS + branch.name, | ||
501 | bases = base_list, | ||
502 | people = people, | ||
503 | replace_changes = replace_changes) | ||
504 | except proto_client.ClientLoginError: | ||
505 | raise UploadError('Login failure') | ||
506 | except urllib2.HTTPError, e: | ||
507 | raise UploadError('HTTP error %d' % e.code) | ||
508 | |||
509 | elif branch.remote.ReviewProtocol == 'ssh': | ||
510 | if dest_branch.startswith(R_HEADS): | ||
511 | dest_branch = dest_branch[len(R_HEADS):] | ||
512 | |||
513 | rp = ['gerrit receive-pack'] | ||
514 | for e in people[0]: | ||
515 | rp.append('--reviewer=%s' % sq(e)) | ||
516 | for e in people[1]: | ||
517 | rp.append('--cc=%s' % sq(e)) | ||
518 | |||
519 | cmd = ['push'] | ||
520 | cmd.append('--receive-pack=%s' % " ".join(rp)) | ||
521 | cmd.append(branch.remote.SshReviewUrl(self.UserEmail)) | ||
522 | cmd.append('%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch)) | ||
523 | if replace_changes: | ||
524 | for change_id,commit_id in replace_changes.iteritems(): | ||
525 | cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id)) | ||
526 | if GitCommand(self, cmd, bare = True).Wait() != 0: | ||
527 | raise UploadError('Upload failed') | ||
528 | |||
529 | else: | ||
530 | raise UploadError('Unsupported protocol %s' \ | ||
531 | % branch.remote.review) | ||
505 | 532 | ||
506 | msg = "posted to %s for %s" % (branch.remote.review, dest_branch) | 533 | msg = "posted to %s for %s" % (branch.remote.review, dest_branch) |
507 | self.bare_git.UpdateRef(R_PUB + branch.name, | 534 | self.bare_git.UpdateRef(R_PUB + branch.name, |