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

Side by Side Diff: git_cl.py

Issue 44263004: Fix "git cl format" when newer clang-format version is installed. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Simplify Created 7 years, 1 month 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 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if '[-i]' in help_text:
2276 cmd.append('-i')
2277
2270 RunCommand(cmd, stdin=diff_output, cwd=top_dir) 2278 RunCommand(cmd, stdin=diff_output, cwd=top_dir)
2271 2279
2272 return 0 2280 return 0
2273 2281
2274 2282
2275 class OptionParser(optparse.OptionParser): 2283 class OptionParser(optparse.OptionParser):
2276 """Creates the option parse and add --verbose support.""" 2284 """Creates the option parse and add --verbose support."""
2277 def __init__(self, *args, **kwargs): 2285 def __init__(self, *args, **kwargs):
2278 optparse.OptionParser.__init__( 2286 optparse.OptionParser.__init__(
2279 self, *args, prog='git cl', version=__version__, **kwargs) 2287 self, *args, prog='git cl', version=__version__, **kwargs)
(...skipping 30 matching lines...) Expand all
2310 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2318 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2311 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2319 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2312 2320
2313 2321
2314 if __name__ == '__main__': 2322 if __name__ == '__main__':
2315 # These affect sys.stdout so do it outside of main() to simplify mocks in 2323 # These affect sys.stdout so do it outside of main() to simplify mocks in
2316 # unit testing. 2324 # unit testing.
2317 fix_encoding.fix_encoding() 2325 fix_encoding.fix_encoding()
2318 colorama.init() 2326 colorama.init()
2319 sys.exit(main(sys.argv[1:])) 2327 sys.exit(main(sys.argv[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