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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | presubmit_canned_checks.py » ('j') | 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 d9e2d9803b0203d3203e61721d4e9b6fced0f616..b1cf7fa2695ad42fd316c3f0bfa158c0bf7c203b 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2303,6 +2303,7 @@ def CMDowners(parser, args):
disable_color=options.no_color).run()
+@subcommand.usage('[files or directories to diff]')
def CMDformat(parser, args):
"""Runs clang-format on the diff."""
CLANG_EXTS = ['.cc', '.cpp', '.h']
@@ -2311,8 +2312,6 @@ def CMDformat(parser, args):
parser.add_option('--dry-run', action='store_true',
help='Don\'t modify any file on disk.')
opts, args = parser.parse_args(args)
- if args:
- parser.error('Unrecognized args: %s' % ' '.join(args))
# git diff generates paths against the root of the repository. Change
# to that directory so clang-format can find files even within subdirs.
@@ -2348,7 +2347,16 @@ def CMDformat(parser, args):
# Handle source file filtering.
diff_cmd.append('--')
- diff_cmd += ['*' + ext for ext in CLANG_EXTS]
+ if args:
+ for arg in args:
+ if os.path.isdir(arg):
+ 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
+ elif os.path.isfile(arg):
+ diff_cmd.append(arg)
+ else:
+ DieWithError('Argument "%s" is not a file or a directory' % arg)
+ else:
+ diff_cmd += ['*' + ext for ext in CLANG_EXTS]
diff_output = RunGit(diff_cmd)
top_dir = os.path.normpath(
« 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