1. Marcus Lindblom Sonestedt
  2. ml-hgext
  3. Issues
Issue #21 resolved

Line endings checks

Michael Rapson
created an issue

checkfiles.py currently provides a great way to verify that changes to a repository conform to white space standards. For teams using a mixture of Windows and Unix/Linux operating systems, ensuring the the end of line characters are consistent is an important test.

There are options in Mercurial to do this, including the EolExtension and Win32TextExtension, however the approach taken in checkfiles.py of simply warning about errors and providing a tool to correct them if desired seems to be a good alternative, without the complexity of converting line endings that those methods use. (They are also marked as features of last resort.)

Is there any interest or intention to provide options to check and correct line endings in the future?

I have implemented checks for CRLF, and fixup to LF line endings, because we intend to use LF line endings in a project. (These checks are not optional in my modified code.) The chief changes required are to test for "chunk == '\r'" in separate elseif statements around lines 245 and 363, and to use splitlines(1) and rstrip('\n') to preserve '\r' at the end of lines for tests around lines 264, and 379. I can provide this code, or diffs if necessary.

Comments (11)

  1. Michael Rapson reporter

    Thanks for your reply. I would rather not pull/push my changes straight into the repository. As it stands, the changes implement tests for CRLF and conversions from CRLF to LF. Configuration options to enable or disable this behaviour have not been added, and I am sure that there will be some users who would want to turn the tests off, so I think pushing straight into the repository could leave it unusable for those people. Instead, I am attaching a copy of the checkfiles.py script as I am currently using it, and a diff relative to 51. Thanks for your help with this, and thanks also for resolving issue #19.

  2. Michael Rapson reporter


    I have finally had a chance to clean my CRLF patch up a bit more. It now offers a flag check_ignores_CRLF. If this is set to true, then the line endings in the file are ignored by checkfiles (although if a line contains trailing whitespace AND a CRLF the warning will mention the CRLF). If it is set of false, then any CRLF in the file will cause a warning in checkfiles.

    Similarly, for fixup_hook and fixwhitespace, if check_ignores_CRLF is true, the file line endings are preserved, and if it is false then the file line endings are converted to '\n' only.

    I have tested the files on OSX, and a colleague tested them on windows.

  3. Log in to comment