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: svn://svn.chromium.org/llvm-project/cfe/trunk/tools/clang-format@196917 0b72dbe1-c17f-4bc7-b9db-2b4152be0356
diff --git a/clang-format-diff.py b/clang-format-diff.py
index a62cae8..f8fceeb 100755
--- a/clang-format-diff.py
+++ b/clang-format-diff.py
@@ -41,8 +41,11 @@
                                    '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 @@
     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)