Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index b34edcf38df385ee4be9566372e16259c696c6d4..6d85ca5b92b7a61619a501b6e896f468252a42d9 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -1952,24 +1952,35 @@ def CMDformat(parser, args): |
| if args: |
| parser.error('Unrecognized args: %s' % ' '.join(args)) |
| + # Generate diff for the current branch's changes. |
| + diff_cmd = ['diff', '--no-ext-diff'] |
| if opts.full: |
| - cmd = ['diff', '--name-only', '--'] + ['.*' + ext for ext in CLANG_EXTS] |
| - files = RunGit(cmd).split() |
| + # Only list the names of modified files. |
| + diff_cmd += ['--name-only'] |
|
M-A Ruel
2013/05/17 12:41:48
I highly prefer append() even if it is clunky. It'
|
| + else: |
| + # Only generate context-less patches. |
| + diff_cmd += ['-U0'] |
| + |
| + # Handle branch and source file filtering. |
| + diff_cmd += ['@{u}', '--'] + ['*' + ext for ext in CLANG_EXTS] |
|
M-A Ruel
2013/05/17 12:41:48
Note that @{u} may not be exactly what you want. I
|
| + diff_output = RunGit(diff_cmd) |
| + |
| + if opts.full: |
| + # diff_output is a list of files to send to clang-format. |
| + files = diff_output.split() |
| if not files: |
| print "Nothing to format." |
| return 0 |
| - RunCommand(['clang-format', '-i'] + files) |
| + RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files) |
| else: |
| + # diff_output is a patch to send to clang-format-diff.py |
| cfd_path = os.path.join('/usr', 'lib', 'clang-format', |
| 'clang-format-diff.py') |
| if not os.path.exists(cfd_path): |
| print >> sys.stderr, 'Could not find clang-format-diff at %s.' % cfd_path |
| return 2 |
| - cmd = ['diff', '-U0', '@{u}', '--'] + ['.*' + ext for ext in CLANG_EXTS] |
| - diff = RunGit(cmd) |
| - cmd = [sys.executable, '/usr/lib/clang-format/clang-format-diff.py', |
| - '-style', 'Chromium'] |
| - RunCommand(cmd, stdin=diff) |
| + cmd = [sys.executable, cfd_path, '-style', 'Chromium'] |
| + RunCommand(cmd, stdin=diff_output) |
| return 0 |