mercurial needs better end-of-line support
One real world issue with source control systems is the handling of end-of-line characters in text files. Currently Mercurial pretty much punts. The hg book says:
Note: The Windows version of Mercurial does not automatically convert line endings between Windows and Unix styles. If you want to share work with Unix users, you must do a little additional configuration work. XXX Flesh this out.
NOTE: the tempfile mechanism is recommended for Windows systems,
where the standard shell I/O redirection operators often have
strange effects. In particular, if you are doing line ending
conversion on Windows using the popular dos2unix and unix2dos
programs, you *must* use the tempfile mechanism, as using pipes will
corrupt the contents of your files.
Tempfile example:
[encode]
# convert files to unix line ending conventions on checkin
**.txt = tempfile: dos2unix -n INFILE OUTFILE
[decode]
# convert files to windows line ending conventions when writing
# them to the working dir
**.txt = tempfile: unix2dos -n INFILE OUTFILE
However (1) unix2dos and dos2unix are generally not available on Windows machines and (2) if dos2unix isn’t available the “encoding” here will silently wipe out your file to empty content on checkin.
How is Mozilla handling this in their hg repository? Is it mandated that new files added on Windows use Unix line endings or is some kind of conversion for Windows attempted?


September 13th, 2007 at 6:05 pm
For Mozilla code, Unix line endings are mandatory on all platforms. Some versions of CVS support line ending conversion, but I don’t think most Mozilla coders use it; the standard Mozilla build enviornment for Windows (MozillaBuild) defaults to checking out using Unix line endings, and even before that, the suggested setup was to have cygwin set to Unix line endings. I’m assuming this will continue through the hg conversion. It’s not really a big deal, though; I just use an editor that supports Unix line endings.
September 13th, 2007 at 6:54 pm
Thanks, Eli. Fair enough. The world would be a better place if \r\n went away everywhere. In general all the work I do (and we do at ActiveState) is with tools that support \n on Windows. I suppose I should look into a pre-commit hook for hg that warns or errors out about new files on Windows that have \r\n EOLs — because I know that it will come up in Komodo development (the main project I work on with multiple devs).
September 14th, 2007 at 12:57 pm
I’ve been working in various hg.mozilla.org repositories for a few months. No conversion is attempted, and there’s no pretxncommit hook or anything like that. As a matter of policy, all Mozilla code has Unix-style newlines.
Works for us… but yes, you’ll probably have to think harder about it than we have. :(