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

Side by Side Diff: git_cl.py

Issue 143903006: Support passing files/directories to git cl format (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Change canned check to only check directory 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | presubmit_canned_checks.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 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2296 2296
2297 change = cl.GetChange(base_branch, None) 2297 change = cl.GetChange(base_branch, None)
2298 return owners_finder.OwnersFinder( 2298 return owners_finder.OwnersFinder(
2299 [f.LocalPath() for f in 2299 [f.LocalPath() for f in
2300 cl.GetChange(base_branch, None).AffectedFiles()], 2300 cl.GetChange(base_branch, None).AffectedFiles()],
2301 change.RepositoryRoot(), author, 2301 change.RepositoryRoot(), author,
2302 fopen=file, os_path=os.path, glob=glob.glob, 2302 fopen=file, os_path=os.path, glob=glob.glob,
2303 disable_color=options.no_color).run() 2303 disable_color=options.no_color).run()
2304 2304
2305 2305
2306 @subcommand.usage('[files or directories to diff]')
2306 def CMDformat(parser, args): 2307 def CMDformat(parser, args):
2307 """Runs clang-format on the diff.""" 2308 """Runs clang-format on the diff."""
2308 CLANG_EXTS = ['.cc', '.cpp', '.h'] 2309 CLANG_EXTS = ['.cc', '.cpp', '.h']
2309 parser.add_option('--full', action='store_true', 2310 parser.add_option('--full', action='store_true',
2310 help='Reformat the full content of all touched files') 2311 help='Reformat the full content of all touched files')
2311 parser.add_option('--dry-run', action='store_true', 2312 parser.add_option('--dry-run', action='store_true',
2312 help='Don\'t modify any file on disk.') 2313 help='Don\'t modify any file on disk.')
2313 opts, args = parser.parse_args(args) 2314 opts, args = parser.parse_args(args)
2314 if args:
2315 parser.error('Unrecognized args: %s' % ' '.join(args))
2316 2315
2317 # git diff generates paths against the root of the repository. Change 2316 # git diff generates paths against the root of the repository. Change
2318 # to that directory so clang-format can find files even within subdirs. 2317 # to that directory so clang-format can find files even within subdirs.
2319 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() 2318 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip()
2320 if rel_base_path: 2319 if rel_base_path:
2321 os.chdir(rel_base_path) 2320 os.chdir(rel_base_path)
2322 2321
2323 # Generate diff for the current branch's changes. 2322 # Generate diff for the current branch's changes.
2324 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] 2323 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix']
2325 if opts.full: 2324 if opts.full:
(...skipping 15 matching lines...) Expand all
2341 upstream_commit = upstream_commit.strip() 2340 upstream_commit = upstream_commit.strip()
2342 2341
2343 if not upstream_commit: 2342 if not upstream_commit:
2344 DieWithError('Could not find base commit for this branch. ' 2343 DieWithError('Could not find base commit for this branch. '
2345 'Are you in detached state?') 2344 'Are you in detached state?')
2346 2345
2347 diff_cmd.append(upstream_commit) 2346 diff_cmd.append(upstream_commit)
2348 2347
2349 # Handle source file filtering. 2348 # Handle source file filtering.
2350 diff_cmd.append('--') 2349 diff_cmd.append('--')
2351 diff_cmd += ['*' + ext for ext in CLANG_EXTS] 2350 if args:
2351 for arg in args:
2352 if os.path.isdir(arg):
2353 diff_cmd += [os.path.join(arg, '*' + ext) for ext in CLANG_EXTS]
iannucci 2014/01/29 06:06:03 Is clang format interpreting these globs? Because
enne (OOO) 2014/01/29 18:18:31 According to https://www.kernel.org/pub/software/s
2354 elif os.path.isfile(arg):
2355 diff_cmd.append(arg)
2356 else:
2357 DieWithError('Argument "%s" is not a file or a directory' % arg)
2358 else:
2359 diff_cmd += ['*' + ext for ext in CLANG_EXTS]
2352 diff_output = RunGit(diff_cmd) 2360 diff_output = RunGit(diff_cmd)
2353 2361
2354 top_dir = os.path.normpath( 2362 top_dir = os.path.normpath(
2355 RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n')) 2363 RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n'))
2356 2364
2357 # Locate the clang-format binary in the checkout 2365 # Locate the clang-format binary in the checkout
2358 try: 2366 try:
2359 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree() 2367 clang_format_tool = clang_format.FindClangFormatToolInChromiumTree()
2360 except clang_format.NotFoundError, e: 2368 except clang_format.NotFoundError, e:
2361 DieWithError(e) 2369 DieWithError(e)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2429 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2437 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2430 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2438 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2431 2439
2432 2440
2433 if __name__ == '__main__': 2441 if __name__ == '__main__':
2434 # These affect sys.stdout so do it outside of main() to simplify mocks in 2442 # These affect sys.stdout so do it outside of main() to simplify mocks in
2435 # unit testing. 2443 # unit testing.
2436 fix_encoding.fix_encoding() 2444 fix_encoding.fix_encoding()
2437 colorama.init() 2445 colorama.init()
2438 sys.exit(main(sys.argv[1:])) 2446 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | presubmit_canned_checks.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698