[clang] [git-clang-format] Don't format the line preceding a deletion (PR #215946)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 21:52:11 PDT 2026
MaskRay wrote:
Tested a few scenarios. git-clang-format should now match clang-format-diff.py.
```
Confirmed — but with one wrinkle worth knowing before review.
The behavioral claim holds. I fed identical scenarios to both tools and compared:
┌───────────────────────┬─────────────────┬──────────────────────┬──────────────────────────┐
│ Scenario │ Hunk header │ clang-format-diff.py │ git-clang-format (fixed) │
├───────────────────────┼─────────────────┼──────────────────────┼──────────────────────────┤
│ Pure deletion │ @@ -3,3 +2,0 @@ │ no changes │ no changes │
├───────────────────────┼─────────────────┼──────────────────────┼──────────────────────────┤
│ Modification │ @@ -6 +6 @@ │ changes proposed │ changes proposed │
├───────────────────────┼─────────────────┼──────────────────────┼──────────────────────────┤
│ Insertion │ @@ -7,0 +8 @@ │ changes proposed │ changes proposed │
├───────────────────────┼─────────────────┼──────────────────────┼──────────────────────────┤
│ Leading-line deletion │ @@ -1,2 +0,0 @@ │ no changes │ no changes │
└───────────────────────┴─────────────────┴──────────────────────┴──────────────────────────┘
They agree everywhere. And the divergence the patch closes is real, not imagined: on the pure-deletion case the unpatched git-clang-format proposes reflowing the untouched neighbor while clang-format-diff.py proposes nothing, on byte-identical input.
```
https://github.com/llvm/llvm-project/pull/215946
More information about the cfe-commits
mailing list