From 0f5d1b102e5cacaef4595f07458a050334094c17 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Tue, 27 Oct 2026 21:11:55 +0000 Subject: [PATCH] Don't normalise newlines --- examples/merge_file.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/merge_file.py b/examples/merge_file.py index 23e8555..76dfebb 100644 --- a/examples/merge_file.py +++ b/examples/merge_file.py @@ -22,15 +22,23 @@ def main() -> None: print("Usage: merge_file.py [output]", file=sys.stderr) sys.exit(1) - mine = Path(args[0]).read_text() - base = Path(args[1]).read_text() - theirs = Path(args[2]).read_text() + # Disable universal newline translation to preserve the original line endings. + with Path(args[0]).open(newline="") as file: + mine = file.read() + with Path(args[1]).open(newline="") as file: + base = file.read() + with Path(args[2]).open(newline="") as file: + theirs = file.read() result = reconcile(base, mine, theirs) if len(args) == 4: - Path(args[3]).write_text(result["text"]) + with Path(args[3]).open("w", newline="") as file: + file.write(result["text"]) else: + reconfigure = getattr(sys.stdout, "reconfigure", None) + if reconfigure is not None: + reconfigure(newline="") print(result["text"], end="")