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

Side by Side Diff: git_cl.py

Issue 134313007: Depot tools: use the clang-format binaries that are now included (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Fixed gclient_utils_test.py Created 6 years, 11 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 | « gclient_utils.py ('k') | gn.py » ('j') | 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 14 matching lines...) Expand all
25 25
26 try: 26 try:
27 import readline # pylint: disable=F0401,W0611 27 import readline # pylint: disable=F0401,W0611
28 except ImportError: 28 except ImportError:
29 pass 29 pass
30 30
31 31
32 from third_party import colorama 32 from third_party import colorama
33 from third_party import upload 33 from third_party import upload
34 import breakpad # pylint: disable=W0611 34 import breakpad # pylint: disable=W0611
35 import clang_format
35 import fix_encoding 36 import fix_encoding
36 import gclient_utils 37 import gclient_utils
37 import presubmit_support 38 import presubmit_support
38 import rietveld 39 import rietveld
39 import scm 40 import scm
40 import subcommand 41 import subcommand
41 import subprocess2 42 import subprocess2
42 import watchlists 43 import watchlists
43 import owners_finder 44 import owners_finder
44 45
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 self.viewvc_url = None 263 self.viewvc_url = None
263 self.updated = False 264 self.updated = False
264 self.is_gerrit = None 265 self.is_gerrit = None
265 self.git_editor = None 266 self.git_editor = None
266 267
267 def LazyUpdateIfNeeded(self): 268 def LazyUpdateIfNeeded(self):
268 """Updates the settings from a codereview.settings file, if available.""" 269 """Updates the settings from a codereview.settings file, if available."""
269 if not self.updated: 270 if not self.updated:
270 # The only value that actually changes the behavior is 271 # The only value that actually changes the behavior is
271 # autoupdate = "false". Everything else means "true". 272 # autoupdate = "false". Everything else means "true".
272 autoupdate = RunGit(['config', 'rietveld.autoupdate'], 273 autoupdate = RunGit(['config', 'rietveld.autoupdate'],
273 error_ok=True 274 error_ok=True
274 ).strip().lower() 275 ).strip().lower()
275 276
276 cr_settings_file = FindCodereviewSettingsFile() 277 cr_settings_file = FindCodereviewSettingsFile()
277 if autoupdate != 'false' and cr_settings_file: 278 if autoupdate != 'false' and cr_settings_file:
278 LoadCodereviewSettingsFromFile(cr_settings_file) 279 LoadCodereviewSettingsFromFile(cr_settings_file)
279 # set updated to True to avoid infinite calling loop 280 # set updated to True to avoid infinite calling loop
280 # through DownloadHooks 281 # through DownloadHooks
281 self.updated = True 282 self.updated = True
282 DownloadHooks(False) 283 DownloadHooks(False)
(...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after
2335 DieWithError('Could not find base commit for this branch. ' 2336 DieWithError('Could not find base commit for this branch. '
2336 'Are you in detached state?') 2337 'Are you in detached state?')
2337 2338
2338 diff_cmd.append(upstream_commit) 2339 diff_cmd.append(upstream_commit)
2339 2340
2340 # Handle source file filtering. 2341 # Handle source file filtering.
2341 diff_cmd.append('--') 2342 diff_cmd.append('--')
2342 diff_cmd += ['*' + ext for ext in CLANG_EXTS] 2343 diff_cmd += ['*' + ext for ext in CLANG_EXTS]
2343 diff_output = RunGit(diff_cmd) 2344 diff_output = RunGit(diff_cmd)
2344 2345
2345 top_dir = RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n') 2346 top_dir = os.path.normpath(
2347 RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n'))
2348
2349 # Locate the clang-format binary in the checkout
2350 try:
2351 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree()
2352 except clang_format.NotFoundError, e:
2353 DieWithError(e)
2346 2354
2347 if opts.full: 2355 if opts.full:
2348 # 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.
2349 files = diff_output.splitlines() 2357 files = diff_output.splitlines()
2350 if not files: 2358 if not files:
2351 print "Nothing to format." 2359 print "Nothing to format."
2352 return 0 2360 return 0
2353 RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files, 2361 RunCommand([clang_format_tool, '-i', '-style', 'Chromium'] + files,
2354 cwd=top_dir) 2362 cwd=top_dir)
2355 else: 2363 else:
2364 env = os.environ.copy()
2365 env['PATH'] = os.path.dirname(clang_format_tool)
2356 # 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
2357 cfd_path = os.path.join('/usr', 'lib', 'clang-format', 2367 try:
2358 'clang-format-diff.py') 2368 script = clang_format.FindClangFormatScriptInChromiumTree(
2359 if not os.path.exists(cfd_path): 2369 'clang-format-diff.py')
2360 DieWithError('Could not find clang-format-diff at %s.' % cfd_path) 2370 except clang_format.NotFoundError, e:
2361 cmd = [sys.executable, cfd_path, '-p0', '-style', 'Chromium'] 2371 DieWithError(e)
2362 2372
2363 # Newer versions of clang-format-diff.py require an explicit -i flag 2373 cmd = [sys.executable, script, '-p0', '-style', 'Chromium', '-i']
2364 # to apply the edits to files, otherwise it just displays a diff.
2365 # Probe the usage string to verify if this is needed.
2366 help_text = RunCommand([sys.executable, cfd_path, '-h'])
2367 if '[-i]' in help_text:
2368 cmd.append('-i')
2369 2374
2370 RunCommand(cmd, stdin=diff_output, cwd=top_dir) 2375 RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env)
2371 2376
2372 return 0 2377 return 0
2373 2378
2374 2379
2375 class OptionParser(optparse.OptionParser): 2380 class OptionParser(optparse.OptionParser):
2376 """Creates the option parse and add --verbose support.""" 2381 """Creates the option parse and add --verbose support."""
2377 def __init__(self, *args, **kwargs): 2382 def __init__(self, *args, **kwargs):
2378 optparse.OptionParser.__init__( 2383 optparse.OptionParser.__init__(
2379 self, *args, prog='git cl', version=__version__, **kwargs) 2384 self, *args, prog='git cl', version=__version__, **kwargs)
2380 self.add_option( 2385 self.add_option(
(...skipping 29 matching lines...) Expand all
2410 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2415 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2411 '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)))
2412 2417
2413 2418
2414 if __name__ == '__main__': 2419 if __name__ == '__main__':
2415 # 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
2416 # unit testing. 2421 # unit testing.
2417 fix_encoding.fix_encoding() 2422 fix_encoding.fix_encoding()
2418 colorama.init() 2423 colorama.init()
2419 sys.exit(main(sys.argv[1:])) 2424 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « gclient_utils.py ('k') | gn.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698