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 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree() | 2351 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree() |
2352 except clang_format.NotFoundError, e: | 2352 except clang_format.NotFoundError, e: |
2353 DieWithError(e) | 2353 DieWithError(e) |
2354 | 2354 |
2355 if opts.full: | 2355 if opts.full: |
2356 # diff_output is a list of files to send to clang-format. | 2356 # diff_output is a list of files to send to clang-format. |
2357 files = diff_output.splitlines() | 2357 files = diff_output.splitlines() |
2358 if not files: | 2358 if not files: |
2359 print "Nothing to format." | 2359 print "Nothing to format." |
2360 return 0 | 2360 return 0 |
2361 RunCommand([clang_format_tool, '-i', '-style', 'Chromium'] + files, | 2361 RunCommand([clang_format_tool, '-i'] + files, |
2362 cwd=top_dir) | 2362 cwd=top_dir) |
2363 else: | 2363 else: |
2364 env = os.environ.copy() | 2364 env = os.environ.copy() |
2365 env['PATH'] = os.path.dirname(clang_format_tool) | 2365 env['PATH'] = os.path.dirname(clang_format_tool) |
2366 # diff_output is a patch to send to clang-format-diff.py | 2366 # diff_output is a patch to send to clang-format-diff.py |
2367 try: | 2367 try: |
2368 script = clang_format.FindClangFormatScriptInChromiumTree( | 2368 script = clang_format.FindClangFormatScriptInChromiumTree( |
2369 'clang-format-diff.py') | 2369 'clang-format-diff.py') |
2370 except clang_format.NotFoundError, e: | 2370 except clang_format.NotFoundError, e: |
2371 DieWithError(e) | 2371 DieWithError(e) |
2372 | 2372 |
2373 cmd = [sys.executable, script, '-p0', '-style', 'Chromium', '-i'] | 2373 cmd = [sys.executable, script, '-p0', '-i'] |
2374 | 2374 |
2375 RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) | 2375 RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) |
2376 | 2376 |
2377 return 0 | 2377 return 0 |
2378 | 2378 |
2379 | 2379 |
2380 class OptionParser(optparse.OptionParser): | 2380 class OptionParser(optparse.OptionParser): |
2381 """Creates the option parse and add --verbose support.""" | 2381 """Creates the option parse and add --verbose support.""" |
2382 def __init__(self, *args, **kwargs): | 2382 def __init__(self, *args, **kwargs): |
2383 optparse.OptionParser.__init__( | 2383 optparse.OptionParser.__init__( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2415 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2415 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
2416 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2416 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
2417 | 2417 |
2418 | 2418 |
2419 if __name__ == '__main__': | 2419 if __name__ == '__main__': |
2420 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2420 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2421 # unit testing. | 2421 # unit testing. |
2422 fix_encoding.fix_encoding() | 2422 fix_encoding.fix_encoding() |
2423 colorama.init() | 2423 colorama.init() |
2424 sys.exit(main(sys.argv[1:])) | 2424 sys.exit(main(sys.argv[1:])) |
OLD | NEW |