Changeset View
Changeset View
Standalone View
Standalone View
cfe/trunk/tools/clang-format/clang-format-diff.py
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | def main(): | ||||
parser.add_argument('-binary', default='clang-format', | parser.add_argument('-binary', default='clang-format', | ||||
help='location of binary to use for clang-format') | help='location of binary to use for clang-format') | ||||
args = parser.parse_args() | args = parser.parse_args() | ||||
# Extract changed lines for each file. | # Extract changed lines for each file. | ||||
filename = None | filename = None | ||||
lines_by_file = {} | lines_by_file = {} | ||||
for line in sys.stdin: | for line in sys.stdin: | ||||
match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line) | match = re.search(r'^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line) | ||||
if match: | if match: | ||||
filename = match.group(2) | filename = match.group(2) | ||||
if filename == None: | if filename == None: | ||||
continue | continue | ||||
if args.regex is not None: | if args.regex is not None: | ||||
if not re.match('^%s$' % args.regex, filename): | if not re.match('^%s$' % args.regex, filename): | ||||
continue | continue | ||||
else: | else: | ||||
if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): | if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): | ||||
continue | continue | ||||
match = re.search('^@@.*\+(\d+)(,(\d+))?', line) | match = re.search(r'^@@.*\+(\d+)(,(\d+))?', line) | ||||
if match: | if match: | ||||
start_line = int(match.group(1)) | start_line = int(match.group(1)) | ||||
line_count = 1 | line_count = 1 | ||||
if match.group(3): | if match.group(3): | ||||
line_count = int(match.group(3)) | line_count = int(match.group(3)) | ||||
if line_count == 0: | if line_count == 0: | ||||
continue | continue | ||||
end_line = start_line + line_count - 1 | end_line = start_line + line_count - 1 | ||||
Show All 37 Lines |