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

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: Upload with --no-find-copies 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 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 DieWithError('Could not find base commit for this branch. ' 2328 DieWithError('Could not find base commit for this branch. '
2328 'Are you in detached state?') 2329 'Are you in detached state?')
2329 2330
2330 diff_cmd.append(upstream_commit) 2331 diff_cmd.append(upstream_commit)
2331 2332
2332 # Handle source file filtering. 2333 # Handle source file filtering.
2333 diff_cmd.append('--') 2334 diff_cmd.append('--')
2334 diff_cmd += ['*' + ext for ext in CLANG_EXTS] 2335 diff_cmd += ['*' + ext for ext in CLANG_EXTS]
2335 diff_output = RunGit(diff_cmd) 2336 diff_output = RunGit(diff_cmd)
2336 2337
2337 top_dir = RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n') 2338 top_dir = os.path.normpath(
2339 RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n'))
2340
2341 # Locate the clang-format binary in the checkout
2342 try:
2343 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree()
2344 except clang_format.NotFoundError, e:
2345 DieWithError(e)
2338 2346
2339 if opts.full: 2347 if opts.full:
2340 # diff_output is a list of files to send to clang-format. 2348 # diff_output is a list of files to send to clang-format.
2341 files = diff_output.splitlines() 2349 files = diff_output.splitlines()
2342 if not files: 2350 if not files:
2343 print "Nothing to format." 2351 print "Nothing to format."
2344 return 0 2352 return 0
2345 RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files, 2353 RunCommand([clang_format_tool, '-i', '-style', 'Chromium'] + files,
2346 cwd=top_dir) 2354 cwd=top_dir)
2347 else: 2355 else:
2356 env = os.environ.copy()
2357 env['PATH'] = os.path.dirname(clang_format_tool)
2348 # diff_output is a patch to send to clang-format-diff.py 2358 # diff_output is a patch to send to clang-format-diff.py
2349 cfd_path = os.path.join('/usr', 'lib', 'clang-format', 2359 try:
2350 'clang-format-diff.py') 2360 script = clang_format.FindClangFormatScriptInChromiumTree(
2351 if not os.path.exists(cfd_path): 2361 'clang-format-diff.py')
2352 DieWithError('Could not find clang-format-diff at %s.' % cfd_path) 2362 except clang_format.NotFoundError, e:
2353 cmd = [sys.executable, cfd_path, '-p0', '-style', 'Chromium'] 2363 DieWithError(e)
2354 2364
2355 # Newer versions of clang-format-diff.py require an explicit -i flag 2365 cmd = [sys.executable, script, '-p0', '-style', 'Chromium']
enne (OOO) 2014/01/15 00:59:47 Are you missing an '-i' here?
ncarter (slow) 2014/01/15 01:18:37 Oh my! You're right! Shameful last-minute cleanup.
2356 # to apply the edits to files, otherwise it just displays a diff.
2357 # Probe the usage string to verify if this is needed.
2358 help_text = RunCommand([sys.executable, cfd_path, '-h'])
2359 if '[-i]' in help_text:
2360 cmd.append('-i')
2361 2366
2362 RunCommand(cmd, stdin=diff_output, cwd=top_dir) 2367 RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env)
2363 2368
2364 return 0 2369 return 0
2365 2370
2366 2371
2367 class OptionParser(optparse.OptionParser): 2372 class OptionParser(optparse.OptionParser):
2368 """Creates the option parse and add --verbose support.""" 2373 """Creates the option parse and add --verbose support."""
2369 def __init__(self, *args, **kwargs): 2374 def __init__(self, *args, **kwargs):
2370 optparse.OptionParser.__init__( 2375 optparse.OptionParser.__init__(
2371 self, *args, prog='git cl', version=__version__, **kwargs) 2376 self, *args, prog='git cl', version=__version__, **kwargs)
2372 self.add_option( 2377 self.add_option(
(...skipping 29 matching lines...) Expand all
2402 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2407 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2403 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2408 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2404 2409
2405 2410
2406 if __name__ == '__main__': 2411 if __name__ == '__main__':
2407 # These affect sys.stdout so do it outside of main() to simplify mocks in 2412 # These affect sys.stdout so do it outside of main() to simplify mocks in
2408 # unit testing. 2413 # unit testing.
2409 fix_encoding.fix_encoding() 2414 fix_encoding.fix_encoding()
2410 colorama.init() 2415 colorama.init()
2411 sys.exit(main(sys.argv[1:])) 2416 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