Skip to content
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

Harmonize line endings amongst source file and search/replace text. #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thebjorn
Copy link
Contributor

We want to keep the line endings in the source file, regardless of what
the line endings in the config file is. The algorithm for finding the
line ending, and the decision to only look at the first line, is
inspired by ConfigObj
(https://github.com/DiffSK/configobj/blob/0daebcb55aec2b5a18b287bbb2f4f6f03599f00e/configobj.py#L1294).

This fixes the windows test failure of
test_search_replace_expanding_changelog.

We want to keep the line endings in the source file, regardless of what
the line endings in the config file is. The algorithm for finding the
line ending, and the decision to only look at the first line, is
inspired by ConfigObj
(https://github.com/DiffSK/configobj/blob/0daebcb55aec2b5a18b287bbb2f4f6f03599f00e/configobj.py#L1294).

This fixes the windows test failure of
test_search_replace_expanding_changelog.
@pombreda
Copy link

@thebjorn This is quite nice, but IMHO looking at the first line only can be misleading and is not fool proof. FWIW mixed line endings are possible. It may be better instead to avoid any line ending changes by just keeping them as them were in the original files.

@thebjorn
Copy link
Contributor Author

@pombreda that's actually what this code tries to do ;-) The problem here is that the line endings in the replacement text has no relation to the line endings in the file. We shouldn't try to change line endings in the file, and we should definitely not introduce mixed line endings. If the file has consistent line endings, then it is sufficient to look at the first line. If the file does not have consistent line endings, then no choice of line endings will be correct (making it sufficient to also look at the first line only). IIRC then the current code always adds \r\n on windows, which will corrupt files containing only \n (I seem to remember that I found this in a makefile, but it's a while ago).

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