diff options
author | Alp Toker <alp@nuanti.com> | 2013-12-18 21:34:07 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2013-12-18 21:34:07 +0000 |
commit | 679bf0141b81efaaf5522d59d5653dc618d016a4 (patch) | |
tree | cb1b0c9e3ae3ca8342fcd1c861149fb6369b2814 /clang/tools/clang-format/clang-format-diff.py | |
parent | 84a8726a3150b4b9ceb413657bd43db8a409cb5f (diff) | |
download | bcm5719-llvm-679bf0141b81efaaf5522d59d5653dc618d016a4.tar.gz bcm5719-llvm-679bf0141b81efaaf5522d59d5653dc618d016a4.zip |
clang-format-diff.py: fix -regex/-iregex matching
While debating the finer points of file extension matching, we somehow missed
the bigger problem that the current code will match anything starting with the
default or user-specified pattern (e.g. lit.site.cfg.in).
Fix this by doing what find(1) does, implicitly wrapping the pattern with ^$.
llvm-svn: 197608
Diffstat (limited to 'clang/tools/clang-format/clang-format-diff.py')
-rwxr-xr-x | clang/tools/clang-format/clang-format-diff.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py index 5cece8db9e5..fee16d0e7c6 100755 --- a/clang/tools/clang-format/clang-format-diff.py +++ b/clang/tools/clang-format/clang-format-diff.py @@ -43,7 +43,7 @@ def main(): help='apply edits to files instead of displaying a diff') parser.add_argument('-p', metavar='NUM', default=0, help='strip the smallest prefix containing P slashes') - parser.add_argument('-regex', metavar='PATTERN', default='', + parser.add_argument('-regex', metavar='PATTERN', default=None, help='custom pattern selecting file paths to reformat ' '(case sensitive, override -iregex)') parser.add_argument('-iregex', metavar='PATTERN', default= @@ -66,11 +66,11 @@ def main(): if filename == None: continue - if args.regex != '': - if not re.match(args.regex, filename): + if args.regex is not None: + if not re.match('^%s$' % args.regex, filename): continue else: - if not re.match(args.iregex, filename, re.IGNORECASE): + if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): continue match = re.search('^@@.*\+(\d+)(,(\d+))?', line) |