-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(apply-patch): preserve CRLF line endings on Windows #7515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… files (Fixes #4003) - Detect CRLF in original file, strip trailing \r for matching, and re-emit using original EOL style - Add test to ensure updated files retain CRLF endings and avoid mixed EOLs
…d unintended newline conversion\n\n- Count total vs CRLF pairs and treat as CRLF only if every newline is CRLF\n- Prevents converting LF-formatted files that contain embedded in literals
| } | ||
|
|
||
| /// Detects whether the source file uses Windows CRLF line endings consistently. | ||
| /// We only consider a file CRLF-formatted if every newline is part of a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems strict, though admittedly, I'm not sure if there's a better way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could potentially relax this constraint, but for now I'd prefer to keep this strict.
|
|
||
| // TODO(dylan-hurd-oai): I think we can migrate to just use `contents.lines()` | ||
| // across all platforms. | ||
| fn build_lines_from_contents(contents: &str) -> Vec<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a huge deal, but it would be nice to do the work in contents_uses_crlf() as part of this so that we do the splitting and \r\n check in one forward pass of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single forward pass would be ideal, agreed
Summary
This PR is heavily based on #4017, which contains the core logic for the fix. To reduce the risk, we are first introducing it only on windows. We can then expand to wsl / other environments as needed, and then tackle net new files.
Testing