tamird created this revision.
tamird added a reviewer: hans.
Herald added a project: All.
tamird requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Handle the case where the diff is a pure removal of lines. Before this
change start_line would end up as 0 which is rejected by clang-format.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144291
Files:
clang/tools/clang-format/clang-format-diff.py
Index: clang/tools/clang-format/clang-format-diff.py
===================================================================
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -84,12 +84,19 @@
if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
continue
- match = re.search(r'^@@.*\+(\d+)(,(\d+))?', line)
+ match = re.search(r'^@@.*\+(\d+)(?:,(\d+))?', line)
if match:
start_line = int(match.group(1))
line_count = 1
- if match.group(3):
- line_count = int(match.group(3))
+ if match.group(2):
+ line_count = int(match.group(2))
+ # The input is something like
+ #
+ # @@ -1, +0,0 @@
+ #
+ # which means no lines were added.
+ if line_count == 0:
+ continue
# Also format lines range if line_count is 0 in case of deleting
# surrounding statements.
end_line = start_line
Index: clang/tools/clang-format/clang-format-diff.py
===================================================================
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -84,12 +84,19 @@
if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
continue
- match = re.search(r'^@@.*\+(\d+)(,(\d+))?', line)
+ match = re.search(r'^@@.*\+(\d+)(?:,(\d+))?', line)
if match:
start_line = int(match.group(1))
line_count = 1
- if match.group(3):
- line_count = int(match.group(3))
+ if match.group(2):
+ line_count = int(match.group(2))
+ # The input is something like
+ #
+ # @@ -1, +0,0 @@
+ #
+ # which means no lines were added.
+ if line_count == 0:
+ continue
# Also format lines range if line_count is 0 in case of deleting
# surrounding statements.
end_line = start_line
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits