diff options
author | Alp Toker <alp@nuanti.com> | 2013-12-10 13:51:53 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2013-12-10 13:51:53 +0000 |
commit | b6c2b00ea6f12b5c40f58f33bc4b00051453fa4f (patch) | |
tree | 39efbe24a523cdff27895491c1664fcc71230e68 /tools/clang-format | |
parent | d31b98f0a89e0d8cb3a32fb693018ab9d98f3131 (diff) | |
download | clang-b6c2b00ea6f12b5c40f58f33bc4b00051453fa4f.tar.gz clang-b6c2b00ea6f12b5c40f58f33bc4b00051453fa4f.tar.bz2 clang-b6c2b00ea6f12b5c40f58f33bc4b00051453fa4f.tar.xz |
clang-format-diff.py: Support -regex filter and more filename extensions
Add support for more filename extensions based on the list in the clang
plus JavaScript.
Also adds a -regex option so users can override defaults if they have unusual
file extensions or want to format everything in the diff.
Keeping with tradition the flag is modelled on Unix conventions, this time
matching the semantics of find(1).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196917 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format')
-rwxr-xr-x | tools/clang-format/clang-format-diff.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/tools/clang-format/clang-format-diff.py b/tools/clang-format/clang-format-diff.py index a62cae8ad5..f8fceeb4fc 100755 --- a/tools/clang-format/clang-format-diff.py +++ b/tools/clang-format/clang-format-diff.py @@ -41,8 +41,11 @@ def main(): 'introduced.') parser.add_argument('-i', action='store_true', default=False, help='apply edits to files instead of displaying a diff') - parser.add_argument('-p', default=0, + parser.add_argument('-p', metavar='NUM', default=0, help='strip the smallest prefix containing P slashes') + parser.add_argument('-regex', metavar='PATTERN', default= + r'.*\.(cpp|cc|CPP|C|c\+\+|cxx|c|h|hpp|m|mm|inc|js)', + help='custom pattern selecting file paths to reformat') parser.add_argument( '-style', help= @@ -59,9 +62,7 @@ def main(): if filename == None: continue - # FIXME: Add other types containing C++/ObjC code. - if not (filename.endswith(".cpp") or filename.endswith(".cc") or - filename.endswith(".h")): + if not re.match(args.regex, filename): continue match = re.search('^@@.*\+(\d+)(,(\d+))?', line) |