Skip to content

Write patches as UTF-8 with LF line endings - #125

Merged
jorio merged 1 commit into
jorio:masterfrom
grub-basket:fix/patch-write-encoding
Jul 23, 2026
Merged

Write patches as UTF-8 with LF line endings#125
jorio merged 1 commit into
jorio:masterfrom
grub-basket:fix/patch-write-encoding

Conversation

@grub-basket

Copy link
Copy Markdown
Contributor

Problem

Patch files are written with Path.write_text(...) without an explicit encoding or newline:

  • Encoding: defaults to the locale encoding (cp1252 on Windows), so exporting any patch containing non-cp1252 characters raises UnicodeEncodeError inside the worker thread and the export fails.
  • Newlines: default text mode translates \n\r\n on Windows. GitDriver.buildDiffCommand always passes --binary, and CRLF corrupts the base85 binary payloads; it can also break git apply on the re-saved trash copies of discarded patches.

Fix

Pin encoding="utf-8", newline="\n" at the three patch write sites:

  • tasks/exporttasks.py (savePatch)
  • diffview/diffview.py (exportPatch — partial-line export)
  • trash.py (backupPatch — trash backup of discarded patches)

Prepared with Claude Fable 5 (Low effort mode).

Patch files were written with Path.write_text() without an explicit
encoding or newline. On Windows this used the locale encoding (cp1252),
raising UnicodeEncodeError on non-cp1252 content, and translated LF to
CRLF. CRLF corrupts the base85 payloads emitted by --binary diffs and can
break 'git apply' on the re-saved trash copies of discarded patches.

Pin encoding='utf-8' and newline='\n' at the three patch write sites
(export, partial-lines export, and trash backup).
@jorio
jorio merged commit 98294aa into jorio:master Jul 23, 2026
7 checks passed
@jorio

jorio commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Nice, Windows compat is still very unofficial/WIP so I never caught this. This should tide us over until Python 3.15 / PEP 686 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants