[PATCH] D111273: [clang-format-diff] Fix missing formatting for zero length git diff lines
Zequan Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 8 10:25:06 PDT 2021
zequanwu updated this revision to Diff 378291.
zequanwu added a comment.
Fix the same error in git-clang-format.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111273/new/
https://reviews.llvm.org/D111273
Files:
clang/tools/clang-format/clang-format-diff.py
clang/tools/clang-format/git-clang-format
Index: clang/tools/clang-format/git-clang-format
===================================================================
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -321,8 +321,9 @@
line_count = 1
if match.group(3):
line_count = int(match.group(3))
- if line_count > 0:
- matches.setdefault(filename, []).append(Range(start_line, line_count))
+ if line_count == 0:
+ line_count = 1
+ matches.setdefault(filename, []).append(Range(start_line, line_count))
return matches
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
@@ -90,9 +90,11 @@
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)])
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111273.378291.patch
Type: text/x-patch
Size: 1312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211008/8112b572/attachment.bin>
More information about the cfe-commits
mailing list