diff options
author | Shawn O. Pearce <sop@google.com> | 2010-07-15 16:52:42 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2010-07-15 16:52:42 -0700 |
commit | a5ece0e0505324218f38af02a1fe046ca2bcc278 (patch) | |
tree | 429cbf0b23d2606737629e7fc77a4ad0b228c90a | |
parent | cc50bac8c7706082596d70756249d4964a67f281 (diff) | |
download | git-repo-a5ece0e0505324218f38af02a1fe046ca2bcc278.tar.gz |
upload -t: Automatically include local branch name
If the -t flag is given to upload, the local branch name is
automatically sent to Gerrit Code Review as the topic branch name
for the change(s). This requires the server to be Gerrit Code
Review v2.1.3-53-gd50c94e or later, which isn't widely deployed
right now, so the default is opt-out.
Change-Id: I034fcacb405b7cb909147152db427fe69dd7bcbf
Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r-- | project.py | 17 | ||||
-rw-r--r-- | subcmds/upload.py | 21 |
2 files changed, 25 insertions, 13 deletions
@@ -149,10 +149,11 @@ class ReviewableBranch(object): | |||
149 | R_HEADS + self.name, | 149 | R_HEADS + self.name, |
150 | '--') | 150 | '--') |
151 | 151 | ||
152 | def UploadForReview(self, people): | 152 | def UploadForReview(self, people, auto_topic=False): |
153 | self.project.UploadForReview(self.name, | 153 | self.project.UploadForReview(self.name, |
154 | self.replace_changes, | 154 | self.replace_changes, |
155 | people) | 155 | people, |
156 | auto_topic=auto_topic) | ||
156 | 157 | ||
157 | def GetPublishedRefs(self): | 158 | def GetPublishedRefs(self): |
158 | refs = {} | 159 | refs = {} |
@@ -555,7 +556,10 @@ class Project(object): | |||
555 | return rb | 556 | return rb |
556 | return None | 557 | return None |
557 | 558 | ||
558 | def UploadForReview(self, branch=None, replace_changes=None, people=([],[])): | 559 | def UploadForReview(self, branch=None, |
560 | replace_changes=None, | ||
561 | people=([],[]), | ||
562 | auto_topic=False): | ||
559 | """Uploads the named branch for code review. | 563 | """Uploads the named branch for code review. |
560 | """ | 564 | """ |
561 | if branch is None: | 565 | if branch is None: |
@@ -587,10 +591,15 @@ class Project(object): | |||
587 | for e in people[1]: | 591 | for e in people[1]: |
588 | rp.append('--cc=%s' % sq(e)) | 592 | rp.append('--cc=%s' % sq(e)) |
589 | 593 | ||
594 | ref_spec = '%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch) | ||
595 | if auto_topic: | ||
596 | ref_spec = ref_spec + '/' + branch.name | ||
597 | |||
590 | cmd = ['push'] | 598 | cmd = ['push'] |
591 | cmd.append('--receive-pack=%s' % " ".join(rp)) | 599 | cmd.append('--receive-pack=%s' % " ".join(rp)) |
592 | cmd.append(branch.remote.SshReviewUrl(self.UserEmail)) | 600 | cmd.append(branch.remote.SshReviewUrl(self.UserEmail)) |
593 | cmd.append('%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch)) | 601 | cmd.append(ref_spec) |
602 | |||
594 | if replace_changes: | 603 | if replace_changes: |
595 | for change_id,commit_id in replace_changes.iteritems(): | 604 | for change_id,commit_id in replace_changes.iteritems(): |
596 | cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id)) | 605 | cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id)) |
diff --git a/subcmds/upload.py b/subcmds/upload.py index 5a426113..569e31c1 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -111,6 +111,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
111 | """ | 111 | """ |
112 | 112 | ||
113 | def _Options(self, p): | 113 | def _Options(self, p): |
114 | p.add_option('-t', | ||
115 | dest='auto_topic', action='store_true', | ||
116 | help='Send local branch name to Gerrit Code Review') | ||
114 | p.add_option('--replace', | 117 | p.add_option('--replace', |
115 | dest='replace', action='store_true', | 118 | dest='replace', action='store_true', |
116 | help='Upload replacement patchesets from this branch') | 119 | help='Upload replacement patchesets from this branch') |
@@ -121,7 +124,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
121 | type='string', action='append', dest='cc', | 124 | type='string', action='append', dest='cc', |
122 | help='Also send email to these email addresses.') | 125 | help='Also send email to these email addresses.') |
123 | 126 | ||
124 | def _SingleBranch(self, branch, people): | 127 | def _SingleBranch(self, opt, branch, people): |
125 | project = branch.project | 128 | project = branch.project |
126 | name = branch.name | 129 | name = branch.name |
127 | remote = project.GetBranch(name).remote | 130 | remote = project.GetBranch(name).remote |
@@ -154,11 +157,11 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
154 | answer = _ConfirmManyUploads() | 157 | answer = _ConfirmManyUploads() |
155 | 158 | ||
156 | if answer: | 159 | if answer: |
157 | self._UploadAndReport([branch], people) | 160 | self._UploadAndReport(opt, [branch], people) |
158 | else: | 161 | else: |
159 | _die("upload aborted by user") | 162 | _die("upload aborted by user") |
160 | 163 | ||
161 | def _MultipleBranches(self, pending, people): | 164 | def _MultipleBranches(self, opt, pending, people): |
162 | projects = {} | 165 | projects = {} |
163 | branches = {} | 166 | branches = {} |
164 | 167 | ||
@@ -227,7 +230,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
227 | if not _ConfirmManyUploads(multiple_branches=True): | 230 | if not _ConfirmManyUploads(multiple_branches=True): |
228 | _die("upload aborted by user") | 231 | _die("upload aborted by user") |
229 | 232 | ||
230 | self._UploadAndReport(todo, people) | 233 | self._UploadAndReport(opt, todo, people) |
231 | 234 | ||
232 | def _AppendAutoCcList(self, branch, people): | 235 | def _AppendAutoCcList(self, branch, people): |
233 | """ | 236 | """ |
@@ -311,9 +314,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
311 | _die("upload aborted by user") | 314 | _die("upload aborted by user") |
312 | 315 | ||
313 | branch.replace_changes = to_replace | 316 | branch.replace_changes = to_replace |
314 | self._UploadAndReport([branch], people) | 317 | self._UploadAndReport(opt, [branch], people) |
315 | 318 | ||
316 | def _UploadAndReport(self, todo, original_people): | 319 | def _UploadAndReport(self, opt, todo, original_people): |
317 | have_errors = False | 320 | have_errors = False |
318 | for branch in todo: | 321 | for branch in todo: |
319 | try: | 322 | try: |
@@ -335,7 +338,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
335 | branch.error = 'User aborted' | 338 | branch.error = 'User aborted' |
336 | continue | 339 | continue |
337 | 340 | ||
338 | branch.UploadForReview(people) | 341 | branch.UploadForReview(people, auto_topic=opt.auto_topic) |
339 | branch.uploaded = True | 342 | branch.uploaded = True |
340 | except UploadError, e: | 343 | except UploadError, e: |
341 | branch.error = e | 344 | branch.error = e |
@@ -391,6 +394,6 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
391 | if not pending: | 394 | if not pending: |
392 | print >>sys.stdout, "no branches ready for upload" | 395 | print >>sys.stdout, "no branches ready for upload" |
393 | elif len(pending) == 1 and len(pending[0][1]) == 1: | 396 | elif len(pending) == 1 and len(pending[0][1]) == 1: |
394 | self._SingleBranch(pending[0][1][0], people) | 397 | self._SingleBranch(opt, pending[0][1][0], people) |
395 | else: | 398 | else: |
396 | self._MultipleBranches(pending, people) | 399 | self._MultipleBranches(opt, pending, people) |