Repository navigation
Commit b145459
committed
fix(commit): parse the
`Commit._deserialize` compared a 10-byte slice of each stripped header
line against the 9-byte literal `b"encoding "`, so the comparison never
matched and the branch reading a commit's declared encoding was
unreachable. Every commit parsed from the object database was decoded
with the default UTF-8: `Commit.encoding` reported `UTF-8` regardless of
the header, and the author, committer, and message of a commit written
under `i18n.commitencoding` came back with U+FFFD replacement characters
while `git log` shows them correctly. Re-serializing such a commit also
dropped its `encoding` header and stored the garbled text.
Compare the right slice length so the header is read. Adopt the declared
encoding only when Python has a text codec for it: the identity lines
are decoded with `errors="replace"`, which does not guard against an
unknown codec name, so a commit declaring one would otherwise raise
`LookupError` on attribute access. An unknown name keeps the previous
behavior (the default encoding) and logs the error.
Validated against a repository committed under `i18n.commitencoding =
ISO-8859-1`: `commit.encoding`, `commit.author.name`, and
`commit.message` now match what `git log` shows. Adds regression tests
in `test/test_commit.py` that fail before the change.encoding header when deserializing1 parent 6eedd2c commit b145459
2 files changed
Lines changed: 46 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
896 | 896 | | |
897 | 897 | | |
898 | 898 | | |
899 | | - | |
900 | | - | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
901 | 910 | | |
902 | 911 | | |
903 | 912 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
461 | 496 | | |
462 | 497 | | |
463 | 498 | | |
| |||
0 commit comments