================
@@ -480,9 +480,9 @@ def extract_lines(patch_file, whole_file):
line_count = 1
if match.group(3):
line_count = int(match.group(3))
+ # A hunk that adds no lines is a pure deletion, and start_line
+ # refers to the preceding line, which the deletion left alone.
if line_count == 0:
- line_count = 1
- if start_line == 0:
----------------
MaskRay wrote:
It can't happen once the `line_count == 0` hunks are skipped — `start_line ==
0` is strictly a subset of them, so the check is dead code rather than a case
we stop handling.
A unified diff reports the line *before* an empty range, so `+0` is only ever
produced by a zero new-side count at the start of a file; since line numbers
are 1-based, `+0` can never carry a positive count. I checked that empirically
over `git diff -U0` of the last 3000 non-merge commits in this repo: `+0,0`
shows up 1268 times and is the only `+0…` header form that appears — no `+0,N`
with N>0, and no bare `+0`.
And no, there is nothing it should format: 5e969125c609 added the check because
a whole-file deletion handed clang-format `-lines=0:0` and it asserts; the
file's content is gone, and the following line was left alone.
clang-format-diff.py went through exactly this sequence, which is why the two
now agree: f93169226a29 introduced the coerce-zero-count-to-one behavior in
both scripts, then 50563944ab96 put `if line_count == 0: continue` in front of
it, leaving the coercion unreachable (it's still sitting there today). This
patch does the same for git-clang-format.
I've reworded the comment to call out the start-of-file case inline:
```python
# A hunk that adds no lines is a pure deletion. start_line
# refers to the preceding line (0 when the deletion is at the
# start of a file), which the deletion left alone.
if line_count == 0:
continue
```
Verified end to end against a scratch repo: a whole-file deletion is skipped
cleanly with no assertion, while an unrelated file modified in the same commit
is still formatted, matching clang-format-diff.py.
https://github.com/llvm/llvm-project/pull/215946
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits