OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 return self.tree_status_url | 547 return self.tree_status_url |
548 | 548 |
549 def GetViewVCUrl(self): | 549 def GetViewVCUrl(self): |
550 if not self.viewvc_url: | 550 if not self.viewvc_url: |
551 self.viewvc_url = self._GetRietveldConfig('viewvc-url', error_ok=True) | 551 self.viewvc_url = self._GetRietveldConfig('viewvc-url', error_ok=True) |
552 return self.viewvc_url | 552 return self.viewvc_url |
553 | 553 |
554 def GetBugPrefix(self): | 554 def GetBugPrefix(self): |
555 return self._GetRietveldConfig('bug-prefix', error_ok=True) | 555 return self._GetRietveldConfig('bug-prefix', error_ok=True) |
556 | 556 |
| 557 def GetIsSkipDependencyUpload(self, branch_name): |
| 558 """Returns true if specified branch should skip dep uploads.""" |
| 559 return self._GetBranchConfig(branch_name, 'skip-deps-uploads', |
| 560 error_ok=True) |
| 561 |
557 def GetRunPostUploadHook(self): | 562 def GetRunPostUploadHook(self): |
558 run_post_upload_hook = self._GetRietveldConfig( | 563 run_post_upload_hook = self._GetRietveldConfig( |
559 'run-post-upload-hook', error_ok=True) | 564 'run-post-upload-hook', error_ok=True) |
560 return run_post_upload_hook == "True" | 565 return run_post_upload_hook == "True" |
561 | 566 |
562 def GetDefaultCCList(self): | 567 def GetDefaultCCList(self): |
563 return self._GetRietveldConfig('cc', error_ok=True) | 568 return self._GetRietveldConfig('cc', error_ok=True) |
564 | 569 |
565 def GetDefaultPrivateFlag(self): | 570 def GetDefaultPrivateFlag(self): |
566 return self._GetRietveldConfig('private', error_ok=True) | 571 return self._GetRietveldConfig('private', error_ok=True) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 603 |
599 def GetPendingRefPrefix(self): | 604 def GetPendingRefPrefix(self): |
600 if not self.pending_ref_prefix: | 605 if not self.pending_ref_prefix: |
601 self.pending_ref_prefix = self._GetRietveldConfig( | 606 self.pending_ref_prefix = self._GetRietveldConfig( |
602 'pending-ref-prefix', error_ok=True) | 607 'pending-ref-prefix', error_ok=True) |
603 return self.pending_ref_prefix | 608 return self.pending_ref_prefix |
604 | 609 |
605 def _GetRietveldConfig(self, param, **kwargs): | 610 def _GetRietveldConfig(self, param, **kwargs): |
606 return self._GetConfig('rietveld.' + param, **kwargs) | 611 return self._GetConfig('rietveld.' + param, **kwargs) |
607 | 612 |
| 613 def _GetBranchConfig(self, branch_name, param, **kwargs): |
| 614 return self._GetConfig('branch.' + branch_name + '.' + param, **kwargs) |
| 615 |
608 def _GetConfig(self, param, **kwargs): | 616 def _GetConfig(self, param, **kwargs): |
609 self.LazyUpdateIfNeeded() | 617 self.LazyUpdateIfNeeded() |
610 return RunGit(['config', param], **kwargs).strip() | 618 return RunGit(['config', param], **kwargs).strip() |
611 | 619 |
612 | 620 |
613 def ShortBranchName(branch): | 621 def ShortBranchName(branch): |
614 """Convert a name like 'refs/heads/foo' to just 'foo'.""" | 622 """Convert a name like 'refs/heads/foo' to just 'foo'.""" |
615 return branch.replace('refs/heads/', '') | 623 return branch.replace('refs/heads/', '') |
616 | 624 |
617 | 625 |
(...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2184 settings.GetPendingRefPrefix()) | 2192 settings.GetPendingRefPrefix()) |
2185 if target_ref: | 2193 if target_ref: |
2186 upload_args.extend(['--target_ref', target_ref]) | 2194 upload_args.extend(['--target_ref', target_ref]) |
2187 | 2195 |
2188 # Look for dependent patchsets. See crbug.com/480453 for more details. | 2196 # Look for dependent patchsets. See crbug.com/480453 for more details. |
2189 remote, upstream_branch = cl.FetchUpstreamTuple(cl.GetBranch()) | 2197 remote, upstream_branch = cl.FetchUpstreamTuple(cl.GetBranch()) |
2190 upstream_branch = ShortBranchName(upstream_branch) | 2198 upstream_branch = ShortBranchName(upstream_branch) |
2191 if remote is '.': | 2199 if remote is '.': |
2192 # A local branch is being tracked. | 2200 # A local branch is being tracked. |
2193 local_branch = ShortBranchName(upstream_branch) | 2201 local_branch = ShortBranchName(upstream_branch) |
2194 auth_config = auth.extract_auth_config_from_options(options) | 2202 if settings.GetIsSkipDependencyUpload(local_branch): |
2195 branch_cl = Changelist(branchref=local_branch, auth_config=auth_config) | |
2196 branch_cl_issue_url = branch_cl.GetIssueURL() | |
2197 branch_cl_issue = branch_cl.GetIssue() | |
2198 branch_cl_patchset = branch_cl.GetPatchset() | |
2199 if branch_cl_issue_url and branch_cl_issue and branch_cl_patchset: | |
2200 upload_args.extend( | |
2201 ['--depends_on_patchset', '%s:%s' % ( | |
2202 branch_cl_issue, branch_cl_patchset)]) | |
2203 print | 2203 print |
2204 print ('The current branch (%s) is tracking a local branch (%s) with ' | 2204 print ('Skipping dependency patchset upload because git config ' |
2205 'an associated CL.') % (cl.GetBranch(), local_branch) | 2205 'branch.%s.skip-deps-uploads is set to True.' % local_branch) |
2206 print 'Adding %s/#ps%s as a dependency patchset.' % ( | |
2207 branch_cl_issue_url, branch_cl_patchset) | |
2208 print | 2206 print |
| 2207 else: |
| 2208 auth_config = auth.extract_auth_config_from_options(options) |
| 2209 branch_cl = Changelist(branchref=local_branch, auth_config=auth_config) |
| 2210 branch_cl_issue_url = branch_cl.GetIssueURL() |
| 2211 branch_cl_issue = branch_cl.GetIssue() |
| 2212 branch_cl_patchset = branch_cl.GetPatchset() |
| 2213 if branch_cl_issue_url and branch_cl_issue and branch_cl_patchset: |
| 2214 upload_args.extend( |
| 2215 ['--depends_on_patchset', '%s:%s' % ( |
| 2216 branch_cl_issue, branch_cl_patchset)]) |
| 2217 print |
| 2218 print ('The current branch (%s) is tracking a local branch (%s) with ' |
| 2219 'an associated CL.') % (cl.GetBranch(), local_branch) |
| 2220 print 'Adding %s/#ps%s as a dependency patchset.' % ( |
| 2221 branch_cl_issue_url, branch_cl_patchset) |
| 2222 print |
2209 | 2223 |
2210 project = settings.GetProject() | 2224 project = settings.GetProject() |
2211 if project: | 2225 if project: |
2212 upload_args.extend(['--project', project]) | 2226 upload_args.extend(['--project', project]) |
2213 | 2227 |
2214 if options.cq_dry_run: | 2228 if options.cq_dry_run: |
2215 upload_args.extend(['--cq_dry_run']) | 2229 upload_args.extend(['--cq_dry_run']) |
2216 | 2230 |
2217 try: | 2231 try: |
2218 upload_args = ['upload'] + upload_args + args | 2232 upload_args = ['upload'] + upload_args + args |
(...skipping 30 matching lines...) Expand all Loading... |
2249 So that "--reviewers joe@c,john@c --reviewers joa@c" results in | 2263 So that "--reviewers joe@c,john@c --reviewers joa@c" results in |
2250 options.reviewers == sorted(['joe@c', 'john@c', 'joa@c']). | 2264 options.reviewers == sorted(['joe@c', 'john@c', 'joa@c']). |
2251 """ | 2265 """ |
2252 items = sum((i.split(',') for i in l), []) | 2266 items = sum((i.split(',') for i in l), []) |
2253 stripped_items = (i.strip() for i in items) | 2267 stripped_items = (i.strip() for i in items) |
2254 return sorted(filter(None, stripped_items)) | 2268 return sorted(filter(None, stripped_items)) |
2255 | 2269 |
2256 | 2270 |
2257 @subcommand.usage('[args to "git diff"]') | 2271 @subcommand.usage('[args to "git diff"]') |
2258 def CMDupload(parser, args): | 2272 def CMDupload(parser, args): |
2259 """Uploads the current changelist to codereview.""" | 2273 """Uploads the current changelist to codereview. |
| 2274 |
| 2275 Can skip dependency patchset uploads for a branch by running: |
| 2276 git config branch.branch_name.skip-deps-uploads True |
| 2277 To unset run: |
| 2278 git config --unset branch.branch_name.skip-deps-uploads |
| 2279 Can also set the above globally by using the --global flag. |
| 2280 """ |
2260 parser.add_option('--bypass-hooks', action='store_true', dest='bypass_hooks', | 2281 parser.add_option('--bypass-hooks', action='store_true', dest='bypass_hooks', |
2261 help='bypass upload presubmit hook') | 2282 help='bypass upload presubmit hook') |
2262 parser.add_option('--bypass-watchlists', action='store_true', | 2283 parser.add_option('--bypass-watchlists', action='store_true', |
2263 dest='bypass_watchlists', | 2284 dest='bypass_watchlists', |
2264 help='bypass watchlists auto CC-ing reviewers') | 2285 help='bypass watchlists auto CC-ing reviewers') |
2265 parser.add_option('-f', action='store_true', dest='force', | 2286 parser.add_option('-f', action='store_true', dest='force', |
2266 help="force yes to questions (don't prompt)") | 2287 help="force yes to questions (don't prompt)") |
2267 parser.add_option('-m', dest='message', help='message for patchset') | 2288 parser.add_option('-m', dest='message', help='message for patchset') |
2268 parser.add_option('-t', dest='title', help='title for patchset') | 2289 parser.add_option('-t', dest='title', help='title for patchset') |
2269 parser.add_option('-r', '--reviewers', | 2290 parser.add_option('-r', '--reviewers', |
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3530 if __name__ == '__main__': | 3551 if __name__ == '__main__': |
3531 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3552 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3532 # unit testing. | 3553 # unit testing. |
3533 fix_encoding.fix_encoding() | 3554 fix_encoding.fix_encoding() |
3534 colorama.init() | 3555 colorama.init() |
3535 try: | 3556 try: |
3536 sys.exit(main(sys.argv[1:])) | 3557 sys.exit(main(sys.argv[1:])) |
3537 except KeyboardInterrupt: | 3558 except KeyboardInterrupt: |
3538 sys.stderr.write('interrupted\n') | 3559 sys.stderr.write('interrupted\n') |
3539 sys.exit(1) | 3560 sys.exit(1) |
OLD | NEW |