Skip to content

Add a line-ending preservation mode to apply_patch - #37757

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/085f0cbc57e0965aa62c6a2d0e80870424e762f5
Aug 10, 2026
Merged

Add a line-ending preservation mode to apply_patch#37757
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/085f0cbc57e0965aa62c6a2d0e80870424e762f5

Conversation

@copyberry

@copyberry copyberry Bot commented Aug 10, 2026

Copy link
Copy Markdown

Add a line-ending preservation mode to apply_patch

Why

Updating a file with apply_patch historically normalized its contents to LF,
which can rewrite line endings outside the requested change.

What changed

  • Add an opt-in PreserveLineEndings update mode and thread it through patch
    verification, application, and the standalone executable. Existing APIs keep
    the LF-normalizing mode by default.
  • Retain the original endings of untouched and context lines, including in
    mixed-ending files, and use the file's first line ending for inserted or
    replaced lines.
  • Track patch context separately from identical changed lines so preservation
    does not alter replacement ordering or matching.

Testing

Add coverage for CRLF, CR, mixed endings, trailing blank lines, repeated lines,
EOF overlap rejection, and legacy LF normalization.

## Why

Updating a file with `apply_patch` historically normalized its contents to LF,
which can rewrite line endings outside the requested change.

## What changed

- Add an opt-in `PreserveLineEndings` update mode and thread it through patch
  verification, application, and the standalone executable. Existing APIs keep
  the LF-normalizing mode by default.
- Retain the original endings of untouched and context lines, including in
  mixed-ending files, and use the file's first line ending for inserted or
  replaced lines.
- Track patch context separately from identical changed lines so preservation
  does not alter replacement ordering or matching.

## Testing

Add coverage for CRLF, CR, mixed endings, trailing blank lines, repeated lines,
EOF overlap rejection, and legacy LF normalization.

GitOrigin-RevId: 085f0cbc57e0965aa62c6a2d0e80870424e762f5
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/085f0cbc57e0965aa62c6a2d0e80870424e762f5 branch from acd8b0b to 21aa552 Compare August 10, 2026 01:41
@copyberry
copyberry Bot merged commit 21aa552 into main Aug 10, 2026
30 of 32 checks passed
@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/085f0cbc57e0965aa62c6a2d0e80870424e762f5 branch August 10, 2026 01:42
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant