Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: git_cl.py

Issue 1734863002: Fix git cl format when it finds no clang-formattable files. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3566 matching lines...) Expand 10 before | Expand all | Expand 10 after
3577 # Locate the clang-format binary in the checkout 3577 # Locate the clang-format binary in the checkout
3578 try: 3578 try:
3579 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree() 3579 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree()
3580 except clang_format.NotFoundError, e: 3580 except clang_format.NotFoundError, e:
3581 DieWithError(e) 3581 DieWithError(e)
3582 3582
3583 # Set to 2 to signal to CheckPatchFormatted() that this patch isn't 3583 # Set to 2 to signal to CheckPatchFormatted() that this patch isn't
3584 # formatted. This is used to block during the presubmit. 3584 # formatted. This is used to block during the presubmit.
3585 return_value = 0 3585 return_value = 0
3586 3586
3587 if opts.full: 3587 if clang_diff_files:
3588 if clang_diff_files: 3588 if opts.full:
3589 cmd = [clang_format_tool] 3589 cmd = [clang_format_tool]
3590 if not opts.dry_run and not opts.diff: 3590 if not opts.dry_run and not opts.diff:
3591 cmd.append('-i') 3591 cmd.append('-i')
3592 stdout = RunCommand(cmd + clang_diff_files, cwd=top_dir) 3592 stdout = RunCommand(cmd + clang_diff_files, cwd=top_dir)
3593 if opts.diff: 3593 if opts.diff:
3594 sys.stdout.write(stdout) 3594 sys.stdout.write(stdout)
3595 else: 3595 else:
3596 env = os.environ.copy() 3596 env = os.environ.copy()
3597 env['PATH'] = str(os.path.dirname(clang_format_tool)) 3597 env['PATH'] = str(os.path.dirname(clang_format_tool))
3598 try: 3598 try:
3599 script = clang_format.FindClangFormatScriptInChromiumTree( 3599 script = clang_format.FindClangFormatScriptInChromiumTree(
3600 'clang-format-diff.py') 3600 'clang-format-diff.py')
3601 except clang_format.NotFoundError, e: 3601 except clang_format.NotFoundError, e:
3602 DieWithError(e) 3602 DieWithError(e)
3603 3603
3604 cmd = [sys.executable, script, '-p0'] 3604 cmd = [sys.executable, script, '-p0']
3605 if not opts.dry_run and not opts.diff: 3605 if not opts.dry_run and not opts.diff:
3606 cmd.append('-i') 3606 cmd.append('-i')
3607 3607
3608 diff_cmd = BuildGitDiffCmd('-U0', upstream_commit, clang_diff_files) 3608 diff_cmd = BuildGitDiffCmd('-U0', upstream_commit, clang_diff_files)
3609 diff_output = RunGit(diff_cmd) 3609 diff_output = RunGit(diff_cmd)
3610 3610
3611 stdout = RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) 3611 stdout = RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env)
3612 if opts.diff: 3612 if opts.diff:
3613 sys.stdout.write(stdout) 3613 sys.stdout.write(stdout)
3614 if opts.dry_run and len(stdout) > 0: 3614 if opts.dry_run and len(stdout) > 0:
3615 return_value = 2 3615 return_value = 2
3616 3616
3617 # Similar code to above, but using yapf on .py files rather than clang-format 3617 # Similar code to above, but using yapf on .py files rather than clang-format
3618 # on C/C++ files 3618 # on C/C++ files
3619 if opts.python: 3619 if opts.python:
3620 yapf_tool = gclient_utils.FindExecutable('yapf') 3620 yapf_tool = gclient_utils.FindExecutable('yapf')
3621 if yapf_tool is None: 3621 if yapf_tool is None:
3622 DieWithError('yapf not found in PATH') 3622 DieWithError('yapf not found in PATH')
3623 3623
3624 if opts.full: 3624 if opts.full:
3625 if python_diff_files: 3625 if python_diff_files:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3760 if __name__ == '__main__': 3760 if __name__ == '__main__':
3761 # These affect sys.stdout so do it outside of main() to simplify mocks in 3761 # These affect sys.stdout so do it outside of main() to simplify mocks in
3762 # unit testing. 3762 # unit testing.
3763 fix_encoding.fix_encoding() 3763 fix_encoding.fix_encoding()
3764 colorama.init() 3764 colorama.init()
3765 try: 3765 try:
3766 sys.exit(main(sys.argv[1:])) 3766 sys.exit(main(sys.argv[1:]))
3767 except KeyboardInterrupt: 3767 except KeyboardInterrupt:
3768 sys.stderr.write('interrupted\n') 3768 sys.stderr.write('interrupted\n')
3769 sys.exit(1) 3769 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698