Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 4e89e065e73a1d8a2b292a8b3361f0d50a6006ba..3e4f182dcc27158a78f1e159b76a306c9484369b 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -1923,6 +1923,37 @@ def CMDset_close(parser, args): |
| return 0 |
| +def CMDformat(parser, args): |
| + """run clang-format on the diff""" |
| + CLANG_EXTS = ['.cc', '.cpp', '.h'] |
| + parser.add_option('--full', action='store_true', default=False) |
| + opts, args = parser.parse_args(args) |
| + if args: |
| + parser.error('Unrecognized args: %s' % ' '.join(args)) |
| + |
| + if opts.full: |
| + cmd = ['diff', '--name-only', '--'] + ['.*' + ext for ext in CLANG_EXTS] |
| + files = RunGit(cmd).split() |
| + if not files: |
| + print "Nothing to format." |
| + return 0 |
| + cmd = ['clang-format', '-i'] + files |
| + RunCommand(cmd) |
|
M-A Ruel
2013/05/03 01:55:56
RunCommand(['clang-format', '-i'] + files)
agable
2013/05/06 17:41:31
Done.
|
| + else: |
| + cfd_path = os.path.join('/usr', 'lib', 'clang-format', |
|
M-A Ruel
2013/05/03 01:55:56
It looks like it fits one line.
agable
2013/05/06 17:41:31
Nope, it's 82 chars.
|
| + '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) |
| + |
| + return 0 |
| + |
| + |
| def Command(name): |
| return getattr(sys.modules[__name__], 'CMD' + name, None) |