Repository navigation
Commit 35027d1
committed
fix(repo): preserve trailing whitespace in blamed line content
`Repo.blame` built each blamed line with `line_bytes.rstrip().decode(defenc)`
and then stripped the leading tab, but a `git blame -p` content line is a
leading tab, the blamed line's exact bytes, and git's own terminating line
feed. `rstrip` therefore dropped a line's trailing spaces and tabs, emptied a
whitespace-only line, and removed the carriage return of a CRLF line, so the
content returned by `repo.blame()` differed from both the file and
`git blame`. A caller that reconstructs or compares file content from blame,
for example to find the commit that introduced an exact line, was handed
altered text.
Recover the exact bytes instead: drop the leading tab and only git's trailing
line feed, then decode. Binary lines and the hexsha/header parsing are
unchanged, so the only behavior change is that blamed lines keep their
original trailing whitespace and carriage returns.
Adds `tests/fixtures/blame-content.sh` and `test_blame_preserves_line_content`
in `test/test_repo.py`, which fail before the change
(`['alpha', 'beta', '', 'crlf', 'gamma']`) and pass after
(`['alpha ', 'beta', '\t', 'crlf\r', 'gamma']`) on both the `cli` and `gix`
backends. `ruff check`, `ruff format --check` and `mypy` pass on the touched
files. The repository's pre-existing shallow-clone failures occur identically
with and without this change.
Agent-Model: claude-opus-4-81 parent 8e919a4 commit 35027d1
3 files changed
Lines changed: 25 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1550 | 1550 | | |
1551 | 1551 | | |
1552 | 1552 | | |
1553 | | - | |
1554 | | - | |
1555 | | - | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
1556 | 1562 | | |
1557 | 1563 | | |
1558 | 1564 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
787 | 793 | | |
788 | 794 | | |
789 | 795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments