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

Unified Diff: git_cl.py

Issue 14629012: Adding 'git cl format' command for clang-format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Nits Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index 9f691763ba21ee060e86eb0044319830fb18cdd5..a93a04b27ac2b1888b4f49520f52387ef0ef04c6 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -1931,6 +1931,36 @@ 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
+ RunCommand(['clang-format', '-i'] + files)
+ else:
+ 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',
Jiang 2013/05/06 19:27:31 Why don't you use cfd_path here?
+ '-style', 'Chromium']
+ RunCommand(cmd, stdin=diff)
+
+ return 0
+
+
def Command(name):
return getattr(sys.modules[__name__], 'CMD' + name, None)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698