EOL extension

Greg Ward greg-hg at gerg.ca
Sat Nov 28 17:09:48 CST 2009

On Sat, Nov 28, 2009 at 3:52 PM, Martin Geisler <mg at lazybytes.net> wrote:
> Read its help
>  hg help eol
> and test it! See the bottom of this page a TODO list:

I spotted one grammatical error in the help and ended up rewriting it.
 Sigh: how I get myself into these messes?  Rather than send you a
confusing and messy patch which will be bikeshedded to death, here is
my attempt.  Note that I have never used eol and only glanced briefly
at the source; this is just based on reading your help.  So I might
have got it wrong.

"""manage newlines

This extension allows you to manage what kind of line endings (CRLF or
LF) are used in the repository and in the local working directory.

The extension reads its configuration from a versioned ``.hgeol``
configuration file every time you run an ``hg`` command.  ``.hgeol`` has
similar syntax to regular Mercurial configuration files.  It uses two
sections, ``[patterns]`` and ``[repository]``.

Use ``[patterns]`` to specify the encodings to use by file pattern in
the working directory.  The available encodings are ``LF``, ``CRLF``,
and ``BIN``.  Additionally, ``native`` is an alias for the platform's
default encoding: ``LF`` on Unix (including Mac OS X) and ``CRLF`` on
Windows.  Note that ``BIN`` (do nothing to line endings) is Mercurial's
default behaviour; it's only needed so that later, more specific
patterns can override earlier, more general patterns.

You can override the default interpretation of ``native`` by configuring
``hg-eol.native``.  Set it to ``LF`` or ``CRLF``.

The repository representation of newlines in files configured as
``native`` can be specified in the ``[repository]`` section in
``.hgeol``. The default is LF, meaning that on Windows, files configured
as ``native`` (CRLF) will be converted to LF on commit.

Example versioned ``.hgeol`` file::

  *.py = native
  *.vcproj = CRLF
  *.txt = native
  Makefile = LF
  *.jpg = BIN

  native = LF

Example ``.hgrc`` (or ``Mercurial.ini``) section::

  native = CRLF

Random comments:

  * shouldn't the extension's config section just be [eol]?

  * docs should specify exactly where (which changeset) .hgeol is read from.

  * is it "native" or "NATIVE"?

I don't think reading .hgeol from tip is a good idea, since that can
bounce back and forth from branch to branch.  I recently implemented
an extension that also reads config from the repo, and it just reads
from the tipmost head of 'default'.  (I think it falls back to tip if
there is no default branch.)  That seems to work, but with one big
catch: it means the next command after a rollback has to rebuild the
branch head cache, which is deadly on a big repo.  (30 sec for my 104k
changesets.)  So I replaced repo['default'] with a loop down from tip
to the latest changeset on 'default': icky, but avoids that 30 sec
penalty.  (Hmmm, I guess that won't work if there is no default.


More information about the Mercurial-devel mailing list