aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/clang-format/clang-format-diff.py
diff options
context:
space:
mode:
authorZequan Wu <zequanwu@google.com>2021-10-06 14:18:12 -0700
committerZequan Wu <zequanwu@google.com>2021-10-08 10:25:54 -0700
commitf93169226a298f8fb22d768671d5564030c0ffa9 (patch)
treec978e94414a4e58240496e8f8c51df0b9ac545be /clang/tools/clang-format/clang-format-diff.py
parentc960c8c33997af21492cf2d9a39c13ac78fe6c62 (diff)
downloadllvm-f93169226a298f8fb22d768671d5564030c0ffa9.zip
llvm-f93169226a298f8fb22d768671d5564030c0ffa9.tar.gz
llvm-f93169226a298f8fb22d768671d5564030c0ffa9.tar.bz2
[clang-format-diff] Fix missing formatting for zero length git diff lines
If we only delete lines that are outer block statements (if, while, etc), clang-format-diff.py can't format the statements inside the block statements. An example to repro: 1. Delete the if statment at line 118 in llvm/lib/CodeGen/Analysis.cpp. 2. Run `git diff -U0 --no-color HEAD^ | clang/tools/clang-format/clang-format-diff.py -i -p1` It fails to format the statement after if. Differential Revision: https://reviews.llvm.org/D111273
Diffstat (limited to 'clang/tools/clang-format/clang-format-diff.py')
-rwxr-xr-xclang/tools/clang-format/clang-format-diff.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py
index ecad015..28ac027 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -90,9 +90,11 @@ def main():
line_count = 1
if match.group(3):
line_count = int(match.group(3))
- if line_count == 0:
- continue
- end_line = start_line + line_count - 1
+ # Also format lines range if line_count is 0 in case of deleting
+ # surrounding statements.
+ end_line = start_line
+ if line_count != 0:
+ end_line += line_count - 1
lines_by_file.setdefault(filename, []).extend(
['-lines', str(start_line) + ':' + str(end_line)])