Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 4e89e065e73a1d8a2b292a8b3361f0d50a6006ba..a0204785fc50326863721eced457084997a0dfc5 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -1923,6 +1923,34 @@ def CMDset_close(parser, args): |
| return 0 |
| +def CMDformat(parser, args): |
| + """run clang-format on the diff""" |
| + parser.add_option('--full', action='store_true', default=False) |
|
Greg Spencer (Chromium)
2013/05/02 18:20:11
It might be nice to be able to specify specific fi
M-A Ruel
2013/05/02 20:38:43
Then, this doesn't belong to git-cl. git-cl is not
agable
2013/05/02 20:50:17
Agreed with maruel@ here. If we want an easy comma
|
| + opts, args = parser.parse_args(args) |
| + if args: |
| + parser.error('Unrecognized args: %s' % ' '.join(args)) |
| + if opts.full: |
| + diff = RunGit(['diff', '--name-only']).split() |
|
M-A Ruel
2013/05/02 20:38:43
I'd suggest you to list the valid extensions at th
agable
2013/05/02 20:50:17
I put CLANG_EXTS at the top of this function, not
|
| + files = [name for name in diff if |
| + any([name.endswith(ext) for ext in ['.cc', '.cpp', '.h']])] |
| + if not files: |
| + print "Nothing to format." |
| + return 0 |
| + cmd = ['clang-format', '-i'] + diff |
| + RunCommand(cmd) |
| + else: |
| + diff = RunGit(['diff', '-U0', '@{u}']) |
|
M-A Ruel
2013/05/02 20:38:43
Same with filtering on the file names
|
| + 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 = [sys.executable, '/usr/lib/clang-format/clang-format-diff.py', |
| + '-style', 'Chromium'] |
| + RunCommand(cmd, stdin=diff) |
| + return 0 |
| + |
| + |
| def Command(name): |
| return getattr(sys.modules[__name__], 'CMD' + name, None) |