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.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
| 9 | 9 |
| 10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2260 return 0 | 2260 return 0 |
| 2261 RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files, | 2261 RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files, |
| 2262 cwd=top_dir) | 2262 cwd=top_dir) |
| 2263 else: | 2263 else: |
| 2264 # diff_output is a patch to send to clang-format-diff.py | 2264 # diff_output is a patch to send to clang-format-diff.py |
| 2265 cfd_path = os.path.join('/usr', 'lib', 'clang-format', | 2265 cfd_path = os.path.join('/usr', 'lib', 'clang-format', |
| 2266 'clang-format-diff.py') | 2266 'clang-format-diff.py') |
| 2267 if not os.path.exists(cfd_path): | 2267 if not os.path.exists(cfd_path): |
| 2268 DieWithError('Could not find clang-format-diff at %s.' % cfd_path) | 2268 DieWithError('Could not find clang-format-diff at %s.' % cfd_path) |
| 2269 cmd = [sys.executable, cfd_path, '-p0', '-style', 'Chromium'] | 2269 cmd = [sys.executable, cfd_path, '-p0', '-style', 'Chromium'] |
| 2270 | |
| 2271 # Newer versions of clang-format-diff.py require an explicit -i flag | |
| 2272 # to apply the edits to files, otherwise it just displays a diff. | |
| 2273 # Probe the usage string to verify if this is needed. | |
| 2274 help_text = RunCommand([sys.executable, cfd_path, '-h']) | |
| 2275 help_line1 = help_text.split('\n')[0] | |
|
M-A Ruel
2013/10/25 15:19:09
if '[-i]' in help_text:
cmd.append('-i')
assume
digit1
2013/10/25 15:25:21
Excellent suggestion thanks. I used the first vers
| |
| 2276 if help_line1.find('[-i]') >= 0: | |
| 2277 cmd.append('-i') | |
| 2278 | |
| 2270 RunCommand(cmd, stdin=diff_output, cwd=top_dir) | 2279 RunCommand(cmd, stdin=diff_output, cwd=top_dir) |
| 2271 | 2280 |
| 2272 return 0 | 2281 return 0 |
| 2273 | 2282 |
| 2274 | 2283 |
| 2275 class OptionParser(optparse.OptionParser): | 2284 class OptionParser(optparse.OptionParser): |
| 2276 """Creates the option parse and add --verbose support.""" | 2285 """Creates the option parse and add --verbose support.""" |
| 2277 def __init__(self, *args, **kwargs): | 2286 def __init__(self, *args, **kwargs): |
| 2278 optparse.OptionParser.__init__( | 2287 optparse.OptionParser.__init__( |
| 2279 self, *args, prog='git cl', version=__version__, **kwargs) | 2288 self, *args, prog='git cl', version=__version__, **kwargs) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2310 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2319 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 2311 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2320 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 2312 | 2321 |
| 2313 | 2322 |
| 2314 if __name__ == '__main__': | 2323 if __name__ == '__main__': |
| 2315 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2324 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2316 # unit testing. | 2325 # unit testing. |
| 2317 fix_encoding.fix_encoding() | 2326 fix_encoding.fix_encoding() |
| 2318 colorama.init() | 2327 colorama.init() |
| 2319 sys.exit(main(sys.argv[1:])) | 2328 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |