| 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 import difflib | 10 import difflib |
| (...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2114 DieWithError('Could not find base commit for this branch. ' | 2114 DieWithError('Could not find base commit for this branch. ' |
| 2115 'Are you in detached state?') | 2115 'Are you in detached state?') |
| 2116 | 2116 |
| 2117 diff_cmd.append(upstream_commit) | 2117 diff_cmd.append(upstream_commit) |
| 2118 | 2118 |
| 2119 # Handle source file filtering. | 2119 # Handle source file filtering. |
| 2120 diff_cmd.append('--') | 2120 diff_cmd.append('--') |
| 2121 diff_cmd += ['*' + ext for ext in CLANG_EXTS] | 2121 diff_cmd += ['*' + ext for ext in CLANG_EXTS] |
| 2122 diff_output = RunGit(diff_cmd) | 2122 diff_output = RunGit(diff_cmd) |
| 2123 | 2123 |
| 2124 top_dir = RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n') |
| 2125 |
| 2124 if opts.full: | 2126 if opts.full: |
| 2125 # diff_output is a list of files to send to clang-format. | 2127 # diff_output is a list of files to send to clang-format. |
| 2126 files = diff_output.splitlines() | 2128 files = diff_output.splitlines() |
| 2127 if not files: | 2129 if not files: |
| 2128 print "Nothing to format." | 2130 print "Nothing to format." |
| 2129 return 0 | 2131 return 0 |
| 2130 RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files) | 2132 RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files, |
| 2133 cwd=top_dir) |
| 2131 else: | 2134 else: |
| 2132 # diff_output is a patch to send to clang-format-diff.py | 2135 # diff_output is a patch to send to clang-format-diff.py |
| 2133 cfd_path = os.path.join('/usr', 'lib', 'clang-format', | 2136 cfd_path = os.path.join('/usr', 'lib', 'clang-format', |
| 2134 'clang-format-diff.py') | 2137 'clang-format-diff.py') |
| 2135 if not os.path.exists(cfd_path): | 2138 if not os.path.exists(cfd_path): |
| 2136 DieWithError('Could not find clang-format-diff at %s.' % cfd_path) | 2139 DieWithError('Could not find clang-format-diff at %s.' % cfd_path) |
| 2137 cmd = [sys.executable, cfd_path, '-style', 'Chromium'] | 2140 cmd = [sys.executable, cfd_path, '-style', 'Chromium'] |
| 2138 RunCommand(cmd, stdin=diff_output) | 2141 RunCommand(cmd, stdin=diff_output, cwd=top_dir) |
| 2139 | 2142 |
| 2140 return 0 | 2143 return 0 |
| 2141 | 2144 |
| 2142 | 2145 |
| 2143 ### Glue code for subcommand handling. | 2146 ### Glue code for subcommand handling. |
| 2144 | 2147 |
| 2145 | 2148 |
| 2146 def Commands(): | 2149 def Commands(): |
| 2147 """Returns a dict of command and their handling function.""" | 2150 """Returns a dict of command and their handling function.""" |
| 2148 module = sys.modules[__name__] | 2151 module = sys.modules[__name__] |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 GenUsage(parser, 'help') | 2274 GenUsage(parser, 'help') |
| 2272 return CMDhelp(parser, argv) | 2275 return CMDhelp(parser, argv) |
| 2273 | 2276 |
| 2274 | 2277 |
| 2275 if __name__ == '__main__': | 2278 if __name__ == '__main__': |
| 2276 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2279 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2277 # unit testing. | 2280 # unit testing. |
| 2278 fix_encoding.fix_encoding() | 2281 fix_encoding.fix_encoding() |
| 2279 colorama.init() | 2282 colorama.init() |
| 2280 sys.exit(main(sys.argv[1:])) | 2283 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |