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 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 return self._codereview_impl.UpdateDescriptionRemote(description) | 1316 return self._codereview_impl.UpdateDescriptionRemote(description) |
1317 | 1317 |
1318 def RunHook(self, committing, may_prompt, verbose, change): | 1318 def RunHook(self, committing, may_prompt, verbose, change): |
1319 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" | 1319 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" |
1320 try: | 1320 try: |
1321 return presubmit_support.DoPresubmitChecks(change, committing, | 1321 return presubmit_support.DoPresubmitChecks(change, committing, |
1322 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, | 1322 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, |
1323 default_presubmit=None, may_prompt=may_prompt, | 1323 default_presubmit=None, may_prompt=may_prompt, |
1324 rietveld_obj=self._codereview_impl.GetRieveldObjForPresubmit(), | 1324 rietveld_obj=self._codereview_impl.GetRieveldObjForPresubmit(), |
1325 gerrit_obj=self._codereview_impl.GetGerritObjForPresubmit()) | 1325 gerrit_obj=self._codereview_impl.GetGerritObjForPresubmit()) |
1326 except presubmit_support.PresubmitFailure, e: | 1326 except presubmit_support.PresubmitFailure as e: |
1327 DieWithError( | 1327 DieWithError( |
1328 ('%s\nMaybe your depot_tools is out of date?\n' | 1328 ('%s\nMaybe your depot_tools is out of date?\n' |
1329 'If all fails, contact maruel@') % e) | 1329 'If all fails, contact maruel@') % e) |
1330 | 1330 |
1331 def CMDPatchIssue(self, issue_arg, reject, nocommit, directory): | 1331 def CMDPatchIssue(self, issue_arg, reject, nocommit, directory): |
1332 """Fetches and applies the issue patch from codereview to local branch.""" | 1332 """Fetches and applies the issue patch from codereview to local branch.""" |
1333 if isinstance(issue_arg, (int, long)) or issue_arg.isdigit(): | 1333 if isinstance(issue_arg, (int, long)) or issue_arg.isdigit(): |
1334 parsed_issue_arg = _ParsedIssueNumberArgument(int(issue_arg)) | 1334 parsed_issue_arg = _ParsedIssueNumberArgument(int(issue_arg)) |
1335 else: | 1335 else: |
1336 # Assume url. | 1336 # Assume url. |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 def CloseIssue(self): | 1706 def CloseIssue(self): |
1707 return self.RpcServer().close_issue(self.GetIssue()) | 1707 return self.RpcServer().close_issue(self.GetIssue()) |
1708 | 1708 |
1709 def SetFlag(self, flag, value): | 1709 def SetFlag(self, flag, value): |
1710 """Patchset must match.""" | 1710 """Patchset must match.""" |
1711 if not self.GetPatchset(): | 1711 if not self.GetPatchset(): |
1712 DieWithError('The patchset needs to match. Send another patchset.') | 1712 DieWithError('The patchset needs to match. Send another patchset.') |
1713 try: | 1713 try: |
1714 return self.RpcServer().set_flag( | 1714 return self.RpcServer().set_flag( |
1715 self.GetIssue(), self.GetPatchset(), flag, value) | 1715 self.GetIssue(), self.GetPatchset(), flag, value) |
1716 except urllib2.HTTPError, e: | 1716 except urllib2.HTTPError as e: |
1717 if e.code == 404: | 1717 if e.code == 404: |
1718 DieWithError('The issue %s doesn\'t exist.' % self.GetIssue()) | 1718 DieWithError('The issue %s doesn\'t exist.' % self.GetIssue()) |
1719 if e.code == 403: | 1719 if e.code == 403: |
1720 DieWithError( | 1720 DieWithError( |
1721 ('Access denied to issue %s. Maybe the patchset %s doesn\'t ' | 1721 ('Access denied to issue %s. Maybe the patchset %s doesn\'t ' |
1722 'match?') % (self.GetIssue(), self.GetPatchset())) | 1722 'match?') % (self.GetIssue(), self.GetPatchset())) |
1723 raise | 1723 raise |
1724 | 1724 |
1725 def RpcServer(self): | 1725 def RpcServer(self): |
1726 """Returns an upload.RpcServer() to access this review's rietveld instance. | 1726 """Returns an upload.RpcServer() to access this review's rietveld instance. |
(...skipping 3115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4842 RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n')) | 4842 RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n')) |
4843 | 4843 |
4844 # Set to 2 to signal to CheckPatchFormatted() that this patch isn't | 4844 # Set to 2 to signal to CheckPatchFormatted() that this patch isn't |
4845 # formatted. This is used to block during the presubmit. | 4845 # formatted. This is used to block during the presubmit. |
4846 return_value = 0 | 4846 return_value = 0 |
4847 | 4847 |
4848 if clang_diff_files: | 4848 if clang_diff_files: |
4849 # Locate the clang-format binary in the checkout | 4849 # Locate the clang-format binary in the checkout |
4850 try: | 4850 try: |
4851 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree() | 4851 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree() |
4852 except clang_format.NotFoundError, e: | 4852 except clang_format.NotFoundError as e: |
4853 DieWithError(e) | 4853 DieWithError(e) |
4854 | 4854 |
4855 if opts.full: | 4855 if opts.full: |
4856 cmd = [clang_format_tool] | 4856 cmd = [clang_format_tool] |
4857 if not opts.dry_run and not opts.diff: | 4857 if not opts.dry_run and not opts.diff: |
4858 cmd.append('-i') | 4858 cmd.append('-i') |
4859 stdout = RunCommand(cmd + clang_diff_files, cwd=top_dir) | 4859 stdout = RunCommand(cmd + clang_diff_files, cwd=top_dir) |
4860 if opts.diff: | 4860 if opts.diff: |
4861 sys.stdout.write(stdout) | 4861 sys.stdout.write(stdout) |
4862 else: | 4862 else: |
4863 env = os.environ.copy() | 4863 env = os.environ.copy() |
4864 env['PATH'] = str(os.path.dirname(clang_format_tool)) | 4864 env['PATH'] = str(os.path.dirname(clang_format_tool)) |
4865 try: | 4865 try: |
4866 script = clang_format.FindClangFormatScriptInChromiumTree( | 4866 script = clang_format.FindClangFormatScriptInChromiumTree( |
4867 'clang-format-diff.py') | 4867 'clang-format-diff.py') |
4868 except clang_format.NotFoundError, e: | 4868 except clang_format.NotFoundError as e: |
4869 DieWithError(e) | 4869 DieWithError(e) |
4870 | 4870 |
4871 cmd = [sys.executable, script, '-p0'] | 4871 cmd = [sys.executable, script, '-p0'] |
4872 if not opts.dry_run and not opts.diff: | 4872 if not opts.dry_run and not opts.diff: |
4873 cmd.append('-i') | 4873 cmd.append('-i') |
4874 | 4874 |
4875 diff_cmd = BuildGitDiffCmd('-U0', upstream_commit, clang_diff_files) | 4875 diff_cmd = BuildGitDiffCmd('-U0', upstream_commit, clang_diff_files) |
4876 diff_output = RunGit(diff_cmd) | 4876 diff_output = RunGit(diff_cmd) |
4877 | 4877 |
4878 stdout = RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) | 4878 stdout = RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5014 # Reload settings. | 5014 # Reload settings. |
5015 global settings | 5015 global settings |
5016 settings = Settings() | 5016 settings = Settings() |
5017 | 5017 |
5018 colorize_CMDstatus_doc() | 5018 colorize_CMDstatus_doc() |
5019 dispatcher = subcommand.CommandDispatcher(__name__) | 5019 dispatcher = subcommand.CommandDispatcher(__name__) |
5020 try: | 5020 try: |
5021 return dispatcher.execute(OptionParser(), argv) | 5021 return dispatcher.execute(OptionParser(), argv) |
5022 except auth.AuthenticationError as e: | 5022 except auth.AuthenticationError as e: |
5023 DieWithError(str(e)) | 5023 DieWithError(str(e)) |
5024 except urllib2.HTTPError, e: | 5024 except urllib2.HTTPError as e: |
5025 if e.code != 500: | 5025 if e.code != 500: |
5026 raise | 5026 raise |
5027 DieWithError( | 5027 DieWithError( |
5028 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 5028 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
5029 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 5029 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
5030 return 0 | 5030 return 0 |
5031 | 5031 |
5032 | 5032 |
5033 if __name__ == '__main__': | 5033 if __name__ == '__main__': |
5034 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5034 # These affect sys.stdout so do it outside of main() to simplify mocks in |
5035 # unit testing. | 5035 # unit testing. |
5036 fix_encoding.fix_encoding() | 5036 fix_encoding.fix_encoding() |
5037 setup_color.init() | 5037 setup_color.init() |
5038 try: | 5038 try: |
5039 sys.exit(main(sys.argv[1:])) | 5039 sys.exit(main(sys.argv[1:])) |
5040 except KeyboardInterrupt: | 5040 except KeyboardInterrupt: |
5041 sys.stderr.write('interrupted\n') | 5041 sys.stderr.write('interrupted\n') |
5042 sys.exit(1) | 5042 sys.exit(1) |
OLD | NEW |