The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 16 | from __future__ import print_function |
Ben Komalo | 08a3f68 | 2010-07-15 16:03:02 -0700 | [diff] [blame] | 17 | import copy |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 18 | import re |
| 19 | import sys |
| 20 | |
| 21 | from command import InteractiveCommand |
| 22 | from editor import Editor |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 23 | from error import HookError, UploadError |
| 24 | from project import RepoHook |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 25 | |
Dan Morrill | f0a9a1a | 2010-05-05 08:18:35 -0700 | [diff] [blame] | 26 | UNUSUAL_COMMIT_THRESHOLD = 5 |
Dan Morrill | 879a9a5 | 2010-05-04 16:56:07 -0700 | [diff] [blame] | 27 | |
| 28 | def _ConfirmManyUploads(multiple_branches=False): |
| 29 | if multiple_branches: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 30 | print('ATTENTION: One or more branches has an unusually high number' |
| 31 | 'of commits.') |
Dan Morrill | 879a9a5 | 2010-05-04 16:56:07 -0700 | [diff] [blame] | 32 | else: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 33 | print('ATTENTION: You are uploading an unusually high number of commits.') |
| 34 | print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across' |
| 35 | 'branches?)') |
Dan Morrill | 879a9a5 | 2010-05-04 16:56:07 -0700 | [diff] [blame] | 36 | answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip() |
| 37 | return answer == "yes" |
| 38 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 39 | def _die(fmt, *args): |
| 40 | msg = fmt % args |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 41 | print('error: %s' % msg, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 42 | sys.exit(1) |
| 43 | |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 44 | def _SplitEmails(values): |
| 45 | result = [] |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 46 | for value in values: |
| 47 | result.extend([s.strip() for s in value.split(',')]) |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 48 | return result |
| 49 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 50 | class Upload(InteractiveCommand): |
| 51 | common = True |
| 52 | helpSummary = "Upload changes for code review" |
David Pursehouse | 8f62fb7 | 2012-11-14 12:09:38 +0900 | [diff] [blame] | 53 | helpUsage = """ |
Ficus Kirkpatrick | a0de6e8 | 2010-10-22 13:06:47 -0700 | [diff] [blame] | 54 | %prog [--re --cc] [<project>]... |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 55 | """ |
| 56 | helpDescription = """ |
Shawn O. Pearce | 337fb9c | 2009-04-18 10:59:33 -0700 | [diff] [blame] | 57 | The '%prog' command is used to send changes to the Gerrit Code |
| 58 | Review system. It searches for topic branches in local projects |
| 59 | that have not yet been published for review. If multiple topic |
| 60 | branches are found, '%prog' opens an editor to allow the user to |
| 61 | select which branches to upload. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 62 | |
Shawn O. Pearce | 337fb9c | 2009-04-18 10:59:33 -0700 | [diff] [blame] | 63 | '%prog' searches for uploadable changes in all projects listed at |
| 64 | the command line. Projects can be specified either by name, or by |
| 65 | a relative or absolute path to the project's local directory. If no |
| 66 | projects are specified, '%prog' will search for uploadable changes |
| 67 | in all projects listed in the manifest. |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 68 | |
| 69 | If the --reviewers or --cc options are passed, those emails are |
| 70 | added to the respective list of users, and emails are sent to any |
Shawn O. Pearce | 337fb9c | 2009-04-18 10:59:33 -0700 | [diff] [blame] | 71 | new users. Users passed as --reviewers must already be registered |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 72 | with the code review system, or the upload will fail. |
Shawn O. Pearce | a6df7d2 | 2008-12-12 08:04:07 -0800 | [diff] [blame] | 73 | |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 74 | Configuration |
| 75 | ------------- |
| 76 | |
| 77 | review.URL.autoupload: |
| 78 | |
Mike Frysinger | e931127 | 2011-08-11 15:46:43 -0400 | [diff] [blame] | 79 | To disable the "Upload ... (y/N)?" prompt, you can set a per-project |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 80 | or global Git configuration option. If review.URL.autoupload is set |
| 81 | to "true" then repo will assume you always answer "y" at the prompt, |
| 82 | and will not prompt you further. If it is set to "false" then repo |
| 83 | will assume you always answer "n", and will abort. |
| 84 | |
Ben Komalo | 08a3f68 | 2010-07-15 16:03:02 -0700 | [diff] [blame] | 85 | review.URL.autocopy: |
| 86 | |
| 87 | To automatically copy a user or mailing list to all uploaded reviews, |
| 88 | you can set a per-project or global Git option to do so. Specifically, |
| 89 | review.URL.autocopy can be set to a comma separated list of reviewers |
| 90 | who you always want copied on all uploads with a non-empty --re |
| 91 | argument. |
| 92 | |
Shawn O. Pearce | 3575b8f | 2010-07-15 17:00:14 -0700 | [diff] [blame] | 93 | review.URL.username: |
| 94 | |
| 95 | Override the username used to connect to Gerrit Code Review. |
| 96 | By default the local part of the email address is used. |
| 97 | |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 98 | The URL must match the review URL listed in the manifest XML file, |
| 99 | or in the .git/config within the project. For example: |
| 100 | |
| 101 | [remote "origin"] |
| 102 | url = git://git.example.com/project.git |
| 103 | review = http://review.example.com/ |
| 104 | |
| 105 | [review "http://review.example.com/"] |
| 106 | autoupload = true |
Ben Komalo | 08a3f68 | 2010-07-15 16:03:02 -0700 | [diff] [blame] | 107 | autocopy = johndoe@company.com,my-team-alias@company.com |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 108 | |
Anthony Russello | d666e93 | 2012-06-01 00:48:22 -0400 | [diff] [blame] | 109 | review.URL.uploadtopic: |
| 110 | |
| 111 | To add a topic branch whenever uploading a commit, you can set a |
| 112 | per-project or global Git option to do so. If review.URL.uploadtopic |
| 113 | is set to "true" then repo will assume you always want the equivalent |
| 114 | of the -t option to the repo command. If unset or set to "false" then |
| 115 | repo will make use of only the command line option. |
| 116 | |
Shawn O. Pearce | 337fb9c | 2009-04-18 10:59:33 -0700 | [diff] [blame] | 117 | References |
| 118 | ---------- |
| 119 | |
| 120 | Gerrit Code Review: http://code.google.com/p/gerrit/ |
| 121 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | """ |
| 123 | |
Shawn O. Pearce | c99883f | 2008-11-11 17:12:43 -0800 | [diff] [blame] | 124 | def _Options(self, p): |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 125 | p.add_option('-t', |
| 126 | dest='auto_topic', action='store_true', |
| 127 | help='Send local branch name to Gerrit Code Review') |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 128 | p.add_option('--re', '--reviewers', |
| 129 | type='string', action='append', dest='reviewers', |
| 130 | help='Request reviews from these people.') |
| 131 | p.add_option('--cc', |
| 132 | type='string', action='append', dest='cc', |
| 133 | help='Also send email to these email addresses.') |
Mandeep Singh Baines | d6c93a2 | 2011-05-26 10:34:11 -0700 | [diff] [blame] | 134 | p.add_option('--br', |
| 135 | type='string', action='store', dest='branch', |
| 136 | help='Branch to upload.') |
Daniel Sandler | e9d6b61 | 2012-04-06 10:39:32 -0400 | [diff] [blame] | 137 | p.add_option('--cbr', '--current-branch', |
| 138 | dest='current_branch', action='store_true', |
| 139 | help='Upload current git branch.') |
Brian Harring | 435370c | 2012-07-28 15:37:04 -0700 | [diff] [blame] | 140 | p.add_option('-d', '--draft', |
| 141 | action='store_true', dest='draft', default=False, |
| 142 | help='If specified, upload as a draft.') |
Shawn O. Pearce | c99883f | 2008-11-11 17:12:43 -0800 | [diff] [blame] | 143 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 144 | # Options relating to upload hook. Note that verify and no-verify are NOT |
| 145 | # opposites of each other, which is why they store to different locations. |
| 146 | # We are using them to match 'git commit' syntax. |
| 147 | # |
| 148 | # Combinations: |
| 149 | # - no-verify=False, verify=False (DEFAULT): |
| 150 | # If stdout is a tty, can prompt about running upload hooks if needed. |
| 151 | # If user denies running hooks, the upload is cancelled. If stdout is |
| 152 | # not a tty and we would need to prompt about upload hooks, upload is |
| 153 | # cancelled. |
| 154 | # - no-verify=False, verify=True: |
| 155 | # Always run upload hooks with no prompt. |
| 156 | # - no-verify=True, verify=False: |
| 157 | # Never run upload hooks, but upload anyway (AKA bypass hooks). |
| 158 | # - no-verify=True, verify=True: |
| 159 | # Invalid |
| 160 | p.add_option('--no-verify', |
| 161 | dest='bypass_hooks', action='store_true', |
| 162 | help='Do not run the upload hook.') |
| 163 | p.add_option('--verify', |
| 164 | dest='allow_all_hooks', action='store_true', |
| 165 | help='Run the upload hook without prompting.') |
| 166 | |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 167 | def _SingleBranch(self, opt, branch, people): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 168 | project = branch.project |
| 169 | name = branch.name |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 170 | remote = project.GetBranch(name).remote |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 171 | |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 172 | key = 'review.%s.autoupload' % remote.review |
| 173 | answer = project.config.GetBoolean(key) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 174 | |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 175 | if answer is False: |
| 176 | _die("upload blocked by %s = false" % key) |
| 177 | |
| 178 | if answer is None: |
Shawn O. Pearce | 66bdd46 | 2009-04-17 18:47:22 -0700 | [diff] [blame] | 179 | date = branch.date |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 180 | commit_list = branch.commits |
Shawn O. Pearce | 66bdd46 | 2009-04-17 18:47:22 -0700 | [diff] [blame] | 181 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 182 | print('Upload project %s/ to remote branch %s:' % (project.relpath, project.revisionExpr)) |
| 183 | print(' branch %s (%2d commit%s, %s):' % ( |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 184 | name, |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 185 | len(commit_list), |
| 186 | len(commit_list) != 1 and 's' or '', |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 187 | date)) |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 188 | for commit in commit_list: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 189 | print(' %s' % commit) |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 190 | |
Mike Frysinger | e931127 | 2011-08-11 15:46:43 -0400 | [diff] [blame] | 191 | sys.stdout.write('to %s (y/N)? ' % remote.review) |
David Pursehouse | fc24124 | 2012-11-14 09:19:39 +0900 | [diff] [blame] | 192 | answer = sys.stdin.readline().strip().lower() |
| 193 | answer = answer in ('y', 'yes', '1', 'true', 't') |
Shawn O. Pearce | a608fb0 | 2009-04-17 12:11:24 -0700 | [diff] [blame] | 194 | |
| 195 | if answer: |
Dan Morrill | 879a9a5 | 2010-05-04 16:56:07 -0700 | [diff] [blame] | 196 | if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD: |
| 197 | answer = _ConfirmManyUploads() |
| 198 | |
| 199 | if answer: |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 200 | self._UploadAndReport(opt, [branch], people) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 201 | else: |
| 202 | _die("upload aborted by user") |
| 203 | |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 204 | def _MultipleBranches(self, opt, pending, people): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 205 | projects = {} |
| 206 | branches = {} |
| 207 | |
| 208 | script = [] |
| 209 | script.append('# Uncomment the branches to upload:') |
| 210 | for project, avail in pending: |
| 211 | script.append('#') |
| 212 | script.append('# project %s/:' % project.relpath) |
| 213 | |
| 214 | b = {} |
| 215 | for branch in avail: |
| 216 | name = branch.name |
| 217 | date = branch.date |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 218 | commit_list = branch.commits |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 219 | |
| 220 | if b: |
| 221 | script.append('#') |
Christer Fletcher | 6a1f737 | 2011-04-28 14:13:14 +0200 | [diff] [blame] | 222 | script.append('# branch %s (%2d commit%s, %s) to remote branch %s:' % ( |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 223 | name, |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 224 | len(commit_list), |
| 225 | len(commit_list) != 1 and 's' or '', |
Christer Fletcher | 6a1f737 | 2011-04-28 14:13:14 +0200 | [diff] [blame] | 226 | date, |
| 227 | project.revisionExpr)) |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 228 | for commit in commit_list: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 229 | script.append('# %s' % commit) |
| 230 | b[name] = branch |
| 231 | |
| 232 | projects[project.relpath] = project |
| 233 | branches[project.name] = b |
| 234 | script.append('') |
| 235 | |
chenguodong | 605a9a4 | 2011-08-22 18:42:47 +0800 | [diff] [blame] | 236 | script = [ x.encode('utf-8') |
| 237 | if issubclass(type(x), unicode) |
| 238 | else x |
| 239 | for x in script ] |
| 240 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 241 | script = Editor.EditString("\n".join(script)).split("\n") |
| 242 | |
| 243 | project_re = re.compile(r'^#?\s*project\s*([^\s]+)/:$') |
| 244 | branch_re = re.compile(r'^\s*branch\s*([^\s(]+)\s*\(.*') |
| 245 | |
| 246 | project = None |
| 247 | todo = [] |
| 248 | |
| 249 | for line in script: |
| 250 | m = project_re.match(line) |
| 251 | if m: |
| 252 | name = m.group(1) |
| 253 | project = projects.get(name) |
| 254 | if not project: |
| 255 | _die('project %s not available for upload', name) |
| 256 | continue |
| 257 | |
| 258 | m = branch_re.match(line) |
| 259 | if m: |
| 260 | name = m.group(1) |
| 261 | if not project: |
| 262 | _die('project for branch %s not in script', name) |
| 263 | branch = branches[project.name].get(name) |
| 264 | if not branch: |
| 265 | _die('branch %s not in %s', name, project.relpath) |
| 266 | todo.append(branch) |
| 267 | if not todo: |
| 268 | _die("nothing uncommented for upload") |
Dan Morrill | 879a9a5 | 2010-05-04 16:56:07 -0700 | [diff] [blame] | 269 | |
| 270 | many_commits = False |
| 271 | for branch in todo: |
| 272 | if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD: |
| 273 | many_commits = True |
| 274 | break |
| 275 | if many_commits: |
| 276 | if not _ConfirmManyUploads(multiple_branches=True): |
| 277 | _die("upload aborted by user") |
| 278 | |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 279 | self._UploadAndReport(opt, todo, people) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 280 | |
Ben Komalo | 08a3f68 | 2010-07-15 16:03:02 -0700 | [diff] [blame] | 281 | def _AppendAutoCcList(self, branch, people): |
| 282 | """ |
| 283 | Appends the list of users in the CC list in the git project's config if a |
| 284 | non-empty reviewer list was found. |
| 285 | """ |
| 286 | |
| 287 | name = branch.name |
| 288 | project = branch.project |
| 289 | key = 'review.%s.autocopy' % project.GetBranch(name).remote.review |
| 290 | raw_list = project.config.GetString(key) |
| 291 | if not raw_list is None and len(people[0]) > 0: |
| 292 | people[1].extend([entry.strip() for entry in raw_list.split(',')]) |
| 293 | |
Ficus Kirkpatrick | bc7ef67 | 2009-05-04 12:45:11 -0700 | [diff] [blame] | 294 | def _FindGerritChange(self, branch): |
| 295 | last_pub = branch.project.WasPublished(branch.name) |
| 296 | if last_pub is None: |
| 297 | return "" |
| 298 | |
| 299 | refs = branch.GetPublishedRefs() |
| 300 | try: |
| 301 | # refs/changes/XYZ/N --> XYZ |
| 302 | return refs.get(last_pub).split('/')[-2] |
David Pursehouse | 1d947b3 | 2012-10-25 12:23:11 +0900 | [diff] [blame] | 303 | except (AttributeError, IndexError): |
Ficus Kirkpatrick | bc7ef67 | 2009-05-04 12:45:11 -0700 | [diff] [blame] | 304 | return "" |
| 305 | |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 306 | def _UploadAndReport(self, opt, todo, original_people): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 307 | have_errors = False |
| 308 | for branch in todo: |
| 309 | try: |
Ben Komalo | 08a3f68 | 2010-07-15 16:03:02 -0700 | [diff] [blame] | 310 | people = copy.deepcopy(original_people) |
| 311 | self._AppendAutoCcList(branch, people) |
| 312 | |
Anthony Newnam | cc50bac | 2010-04-08 10:28:59 -0500 | [diff] [blame] | 313 | # Check if there are local changes that may have been forgotten |
| 314 | if branch.project.HasChanges(): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 315 | key = 'review.%s.autoupload' % branch.project.remote.review |
| 316 | answer = branch.project.config.GetBoolean(key) |
Anthony Newnam | cc50bac | 2010-04-08 10:28:59 -0500 | [diff] [blame] | 317 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 318 | # if they want to auto upload, let's not ask because it could be automated |
| 319 | if answer is None: |
| 320 | sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ') |
| 321 | a = sys.stdin.readline().strip().lower() |
| 322 | if a not in ('y', 'yes', 't', 'true', 'on'): |
| 323 | print("skipping upload", file=sys.stderr) |
| 324 | branch.uploaded = False |
| 325 | branch.error = 'User aborted' |
| 326 | continue |
Anthony Newnam | cc50bac | 2010-04-08 10:28:59 -0500 | [diff] [blame] | 327 | |
Anthony Russello | d666e93 | 2012-06-01 00:48:22 -0400 | [diff] [blame] | 328 | # Check if topic branches should be sent to the server during upload |
| 329 | if opt.auto_topic is not True: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 330 | key = 'review.%s.uploadtopic' % branch.project.remote.review |
| 331 | opt.auto_topic = branch.project.config.GetBoolean(key) |
Anthony Russello | d666e93 | 2012-06-01 00:48:22 -0400 | [diff] [blame] | 332 | |
Brian Harring | 435370c | 2012-07-28 15:37:04 -0700 | [diff] [blame] | 333 | branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 334 | branch.uploaded = True |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 335 | except UploadError as e: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 336 | branch.error = e |
| 337 | branch.uploaded = False |
| 338 | have_errors = True |
| 339 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 340 | print(file=sys.stderr) |
| 341 | print('----------------------------------------------------------------------', file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 342 | |
| 343 | if have_errors: |
| 344 | for branch in todo: |
| 345 | if not branch.uploaded: |
Shawn O. Pearce | f00e0ce | 2009-08-22 18:39:49 -0700 | [diff] [blame] | 346 | if len(str(branch.error)) <= 30: |
| 347 | fmt = ' (%s)' |
| 348 | else: |
| 349 | fmt = '\n (%s)' |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 350 | print(('[FAILED] %-15s %-15s' + fmt) % ( |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 351 | branch.project.relpath + '/', \ |
| 352 | branch.name, \ |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 353 | str(branch.error)), |
| 354 | file=sys.stderr) |
| 355 | print() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 356 | |
| 357 | for branch in todo: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 358 | if branch.uploaded: |
| 359 | print('[OK ] %-15s %s' % ( |
| 360 | branch.project.relpath + '/', |
| 361 | branch.name), |
| 362 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 363 | |
| 364 | if have_errors: |
| 365 | sys.exit(1) |
| 366 | |
| 367 | def Execute(self, opt, args): |
| 368 | project_list = self.GetProjects(args) |
| 369 | pending = [] |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 370 | reviewers = [] |
| 371 | cc = [] |
Mandeep Singh Baines | d6c93a2 | 2011-05-26 10:34:11 -0700 | [diff] [blame] | 372 | branch = None |
| 373 | |
| 374 | if opt.branch: |
| 375 | branch = opt.branch |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 376 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 377 | for project in project_list: |
Daniel Sandler | e9d6b61 | 2012-04-06 10:39:32 -0400 | [diff] [blame] | 378 | if opt.current_branch: |
| 379 | cbr = project.CurrentBranch |
| 380 | avail = [project.GetUploadableBranch(cbr)] if cbr else None |
| 381 | else: |
| 382 | avail = project.GetUploadableBranches(branch) |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 383 | if avail: |
| 384 | pending.append((project, avail)) |
| 385 | |
| 386 | if pending and (not opt.bypass_hooks): |
| 387 | hook = RepoHook('pre-upload', self.manifest.repo_hooks_project, |
| 388 | self.manifest.topdir, abort_if_user_denies=True) |
| 389 | pending_proj_names = [project.name for (project, avail) in pending] |
| 390 | try: |
| 391 | hook.Run(opt.allow_all_hooks, project_list=pending_proj_names) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 392 | except HookError as e: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 393 | print("ERROR: %s" % str(e), file=sys.stderr) |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 394 | return |
| 395 | |
Joe Onorato | 2896a79 | 2008-11-17 16:56:36 -0500 | [diff] [blame] | 396 | if opt.reviewers: |
| 397 | reviewers = _SplitEmails(opt.reviewers) |
| 398 | if opt.cc: |
| 399 | cc = _SplitEmails(opt.cc) |
David Pursehouse | 8f62fb7 | 2012-11-14 12:09:38 +0900 | [diff] [blame] | 400 | people = (reviewers, cc) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 | if not pending: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 403 | print("no branches ready for upload", file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 404 | elif len(pending) == 1 and len(pending[0][1]) == 1: |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 405 | self._SingleBranch(opt, pending[0][1][0], people) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 406 | else: |
Shawn O. Pearce | a5ece0e | 2010-07-15 16:52:42 -0700 | [diff] [blame] | 407 | self._MultipleBranches(opt, pending, people) |