Chromium Code Reviews| 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 and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
| 9 | 9 |
| 10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 sys.exit(1) | 88 sys.exit(1) |
| 89 | 89 |
| 90 | 90 |
| 91 def GetNoGitPagerEnv(): | 91 def GetNoGitPagerEnv(): |
| 92 env = os.environ.copy() | 92 env = os.environ.copy() |
| 93 # 'cat' is a magical git string that disables pagers on all platforms. | 93 # 'cat' is a magical git string that disables pagers on all platforms. |
| 94 env['GIT_PAGER'] = 'cat' | 94 env['GIT_PAGER'] = 'cat' |
| 95 return env | 95 return env |
| 96 | 96 |
| 97 | 97 |
| 98 def RunCommand(args, error_ok=False, error_message=None, shell=False, **kwargs): | 98 def RunCommand(args, error_ok=False, error_message=None, shell=False, **kwargs): |
|
tandrii(chromium)
2016/04/29 16:01:13
rebase artifact :(
| |
| 99 try: | 99 try: |
| 100 return subprocess2.check_output(args, shell=shell, **kwargs) | 100 return subprocess2.check_output(args, shell=shell, **kwargs) |
| 101 except subprocess2.CalledProcessError as e: | 101 except subprocess2.CalledProcessError as e: |
| 102 logging.debug('Failed running %s', args) | 102 logging.debug('Failed running %s', args) |
| 103 if not error_ok: | 103 if not error_ok: |
| 104 DieWithError( | 104 DieWithError( |
| 105 'Command "%s" failed.\n%s' % ( | 105 'Command "%s" failed.\n%s' % ( |
| 106 ' '.join(args), error_message or e.stdout or '')) | 106 ' '.join(args), error_message or e.stdout or '')) |
| 107 return e.stdout | 107 return e.stdout |
| 108 | 108 |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1310 def UpdateDescription(self, description): | 1310 def UpdateDescription(self, description): |
| 1311 self.description = description | 1311 self.description = description |
| 1312 return self._codereview_impl.UpdateDescriptionRemote(description) | 1312 return self._codereview_impl.UpdateDescriptionRemote(description) |
| 1313 | 1313 |
| 1314 def RunHook(self, committing, may_prompt, verbose, change): | 1314 def RunHook(self, committing, may_prompt, verbose, change): |
| 1315 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" | 1315 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" |
| 1316 try: | 1316 try: |
| 1317 return presubmit_support.DoPresubmitChecks(change, committing, | 1317 return presubmit_support.DoPresubmitChecks(change, committing, |
| 1318 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, | 1318 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, |
| 1319 default_presubmit=None, may_prompt=may_prompt, | 1319 default_presubmit=None, may_prompt=may_prompt, |
| 1320 rietveld_obj=self._codereview_impl.GetRieveldObjForPresubmit()) | 1320 rietveld_obj=self._codereview_impl.GetRieveldObjForPresubmit(), |
| 1321 gerrit_obj=self._codereview_impl.GetGerritObjForPresubmit()) | |
| 1321 except presubmit_support.PresubmitFailure, e: | 1322 except presubmit_support.PresubmitFailure, e: |
| 1322 DieWithError( | 1323 DieWithError( |
| 1323 ('%s\nMaybe your depot_tools is out of date?\n' | 1324 ('%s\nMaybe your depot_tools is out of date?\n' |
| 1324 'If all fails, contact maruel@') % e) | 1325 'If all fails, contact maruel@') % e) |
| 1325 | 1326 |
| 1326 def CMDPatchIssue(self, issue_arg, reject, nocommit, directory): | 1327 def CMDPatchIssue(self, issue_arg, reject, nocommit, directory): |
| 1327 """Fetches and applies the issue patch from codereview to local branch.""" | 1328 """Fetches and applies the issue patch from codereview to local branch.""" |
| 1328 if isinstance(issue_arg, (int, long)) or issue_arg.isdigit(): | 1329 if isinstance(issue_arg, (int, long)) or issue_arg.isdigit(): |
| 1329 parsed_issue_arg = _ParsedIssueNumberArgument(int(issue_arg)) | 1330 parsed_issue_arg = _ParsedIssueNumberArgument(int(issue_arg)) |
| 1330 else: | 1331 else: |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1494 | 1495 |
| 1495 def PatchsetSetting(self): | 1496 def PatchsetSetting(self): |
| 1496 """Returns name of git config setting which stores issue number.""" | 1497 """Returns name of git config setting which stores issue number.""" |
| 1497 raise NotImplementedError() | 1498 raise NotImplementedError() |
| 1498 | 1499 |
| 1499 def GetRieveldObjForPresubmit(self): | 1500 def GetRieveldObjForPresubmit(self): |
| 1500 # This is an unfortunate Rietveld-embeddedness in presubmit. | 1501 # This is an unfortunate Rietveld-embeddedness in presubmit. |
| 1501 # For non-Rietveld codereviews, this probably should return a dummy object. | 1502 # For non-Rietveld codereviews, this probably should return a dummy object. |
| 1502 raise NotImplementedError() | 1503 raise NotImplementedError() |
| 1503 | 1504 |
| 1505 def GetGerritObjForPresubmit(self): | |
| 1506 # None is valid return value, otherwise presubmit_support.GerritAccessor. | |
| 1507 return None | |
| 1508 | |
| 1504 def UpdateDescriptionRemote(self, description): | 1509 def UpdateDescriptionRemote(self, description): |
| 1505 """Update the description on codereview site.""" | 1510 """Update the description on codereview site.""" |
| 1506 raise NotImplementedError() | 1511 raise NotImplementedError() |
| 1507 | 1512 |
| 1508 def CloseIssue(self): | 1513 def CloseIssue(self): |
| 1509 """Closes the issue.""" | 1514 """Closes the issue.""" |
| 1510 raise NotImplementedError() | 1515 raise NotImplementedError() |
| 1511 | 1516 |
| 1512 def GetApprovingReviewers(self): | 1517 def GetApprovingReviewers(self): |
| 1513 """Returns a list of reviewers approving the change. | 1518 """Returns a list of reviewers approving the change. |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2100 def __getattr__(self, attr): | 2105 def __getattr__(self, attr): |
| 2101 print( | 2106 print( |
| 2102 'You aren\'t using Rietveld at the moment, but Gerrit.\n' | 2107 'You aren\'t using Rietveld at the moment, but Gerrit.\n' |
| 2103 'Using Rietveld in your PRESUBMIT scripts won\'t work.\n' | 2108 'Using Rietveld in your PRESUBMIT scripts won\'t work.\n' |
| 2104 'Please, either change your PRESUBIT to not use rietveld_obj.%s,\n' | 2109 'Please, either change your PRESUBIT to not use rietveld_obj.%s,\n' |
| 2105 'or use Rietveld for codereview.\n' | 2110 'or use Rietveld for codereview.\n' |
| 2106 'See also http://crbug.com/579160.' % attr) | 2111 'See also http://crbug.com/579160.' % attr) |
| 2107 raise NotImplementedError() | 2112 raise NotImplementedError() |
| 2108 return ThisIsNotRietveldIssue() | 2113 return ThisIsNotRietveldIssue() |
| 2109 | 2114 |
| 2115 def GetGerritObjForPresubmit(self): | |
| 2116 return presubmit_support.GerritAccessor(self._GetGerritHost()) | |
| 2117 | |
| 2110 def GetStatus(self): | 2118 def GetStatus(self): |
| 2111 """Apply a rough heuristic to give a simple summary of an issue's review | 2119 """Apply a rough heuristic to give a simple summary of an issue's review |
| 2112 or CQ status, assuming adherence to a common workflow. | 2120 or CQ status, assuming adherence to a common workflow. |
| 2113 | 2121 |
| 2114 Returns None if no issue for this branch, or one of the following keywords: | 2122 Returns None if no issue for this branch, or one of the following keywords: |
| 2115 * 'error' - error from review tool (including deleted issues) | 2123 * 'error' - error from review tool (including deleted issues) |
| 2116 * 'unsent' - no reviewers added | 2124 * 'unsent' - no reviewers added |
| 2117 * 'waiting' - waiting for review | 2125 * 'waiting' - waiting for review |
| 2118 * 'reply' - waiting for owner to reply to review | 2126 * 'reply' - waiting for owner to reply to review |
| 2119 * 'not lgtm' - Code-Review -2 from at least one approved reviewer | 2127 * 'not lgtm' - Code-Review -2 from at least one approved reviewer |
| (...skipping 2622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4742 'found in this checkout. Files in other languages are still ' + | 4750 'found in this checkout. Files in other languages are still ' + |
| 4743 'formatted.') | 4751 'formatted.') |
| 4744 | 4752 |
| 4745 # Format GN build files. Always run on full build files for canonical form. | 4753 # Format GN build files. Always run on full build files for canonical form. |
| 4746 if gn_diff_files: | 4754 if gn_diff_files: |
| 4747 cmd = ['gn', 'format'] | 4755 cmd = ['gn', 'format'] |
| 4748 if not opts.dry_run and not opts.diff: | 4756 if not opts.dry_run and not opts.diff: |
| 4749 cmd.append('--in-place') | 4757 cmd.append('--in-place') |
| 4750 for gn_diff_file in gn_diff_files: | 4758 for gn_diff_file in gn_diff_files: |
| 4751 stdout = RunCommand(cmd + [gn_diff_file], | 4759 stdout = RunCommand(cmd + [gn_diff_file], |
| 4752 shell=sys.platform == 'win32', | 4760 shell=sys.platform == 'win32', |
|
tandrii(chromium)
2016/04/29 16:01:13
rebase artifact :(
| |
| 4753 cwd=top_dir) | 4761 cwd=top_dir) |
| 4754 if opts.diff: | 4762 if opts.diff: |
| 4755 sys.stdout.write(stdout) | 4763 sys.stdout.write(stdout) |
| 4756 | 4764 |
| 4757 return return_value | 4765 return return_value |
| 4758 | 4766 |
| 4759 | 4767 |
| 4760 @subcommand.usage('<codereview url or issue id>') | 4768 @subcommand.usage('<codereview url or issue id>') |
| 4761 def CMDcheckout(parser, args): | 4769 def CMDcheckout(parser, args): |
| 4762 """Checks out a branch associated with a given Rietveld or Gerrit issue.""" | 4770 """Checks out a branch associated with a given Rietveld or Gerrit issue.""" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4857 if __name__ == '__main__': | 4865 if __name__ == '__main__': |
| 4858 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4866 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 4859 # unit testing. | 4867 # unit testing. |
| 4860 fix_encoding.fix_encoding() | 4868 fix_encoding.fix_encoding() |
| 4861 setup_color.init() | 4869 setup_color.init() |
| 4862 try: | 4870 try: |
| 4863 sys.exit(main(sys.argv[1:])) | 4871 sys.exit(main(sys.argv[1:])) |
| 4864 except KeyboardInterrupt: | 4872 except KeyboardInterrupt: |
| 4865 sys.stderr.write('interrupted\n') | 4873 sys.stderr.write('interrupted\n') |
| 4866 sys.exit(1) | 4874 sys.exit(1) |
| OLD | NEW |