Patchwork [V2] eol: support alternate location for .hgeol file (issue3975)

login
register
mail settings
Submitter Jorge Acereda
Date Aug. 6, 2013, 10:43 a.m.
Message ID <5ba1888e15acfb5a7440.1375785796@jacereda-l2.brainstorm.redlan>
Download mbox | patch
Permalink /patch/2005/
State Rejected
Headers show

Comments

Jorge Acereda - Aug. 6, 2013, 10:43 a.m.
# HG changeset patch
# User Jorge Acereda <jacereda@brainstorm.es>
# Date 1374235830 -7200
# Node ID 5ba1888e15acfb5a7440cf2cd212b9c9e8bf1287
# Parent  a58251c0568fc5e86089a803ca75f75cc8c01678
eol: support alternate location for .hgeol file (issue3975)
Matt Mackall - Aug. 15, 2013, 8:48 p.m.
On Tue, 2013-08-06 at 12:43 +0200, Jorge Acereda wrote:
> # HG changeset patch
> # User Jorge Acereda <jacereda@brainstorm.es>
> # Date 1374235830 -7200
> # Node ID 5ba1888e15acfb5a7440cf2cd212b9c9e8bf1287
> # Parent  a58251c0568fc5e86089a803ca75f75cc8c01678
> eol: support alternate location for .hgeol file (issue3975)

Ok, had a bit more time to think about this and I'm afraid I don't like
it.

First, I have to say, in my not so humble opinion as Mercurial's
creator: if you are using EOL rules, you are doing Mercurial wrong.
This is why they're only available as an extension, and the
documentation for that extension starts with "don't":

http://mercurial.selenic.com/wiki/EolExtension

So I do in fact consider it a good thing that the scope of EOL rules is
a single misguided repository. Further, given that there's no way to
turn the rules -off- per repository, you now have a problem if you try
to work on a normal repository which does not use EOL rules, and you may
cause people with non-broken editors to in fact start committing broken
line endings where they otherwise wouldn't.

Further, I think the adminstrative overhead of adding .hgeol rules to
repositories is pretty minimal. So I don't think this feature is worth
it on balance.
Jorge Acereda - Aug. 20, 2013, 10:51 a.m.
Hi,

On Aug 15, 2013, at 10:48 PM, Matt Mackall wrote:

> First, I have to say, in my not so humble opinion as Mercurial's
> creator: if you are using EOL rules, you are doing Mercurial wrong.
> This is why they're only available as an extension, and the
> documentation for that extension starts with "don't":

Can you elaborate on that? 
What would you consider The Right Thing?
pre-commit hooks checking line endings perhaps?

Patch

diff -r a58251c0568f -r 5ba1888e15ac hgext/eol.py
--- a/hgext/eol.py	Thu Aug 01 22:52:05 2013 -0500
+++ b/hgext/eol.py	Fri Jul 19 14:10:30 2013 +0200
@@ -6,8 +6,18 @@ 
 Unix/Mac, thereby letting everybody use their OS native line endings.
 
 The extension reads its configuration from a versioned ``.hgeol``
-configuration file found in the root of the working copy. The
-``.hgeol`` file use the same syntax as all other Mercurial
+configuration file found in the root of the working copy.
+
+An alternate location for the ``.hgeol`` configuration file can be
+specified in a ``configpath`` setting in the ``[eol]`` section of your
+``hgrc``. This can be useful when dealing with lots of subrepos.
+
+Example ``.hgrc`` file specifying the location of the ``.hgeol`` file::
+
+  [eol]
+  configpath = hgeol
+
+The ``.hgeol`` file use the same syntax as all other Mercurial
 configuration files. It uses two sections, ``[patterns]`` and
 ``[repository]``.
 
@@ -205,9 +215,9 @@ 
         for node in nodes:
             try:
                 if node is None:
-                    # Cannot use workingctx.data() since it would load
-                    # and cache the filters before we configure them.
-                    data = repo.wfile('.hgeol').read()
+                    f = open(ui.configpath('eol', 'configpath', '.hgeol'))
+                    data = f.read()
+                    f.close()
                 else:
                     data = repo[node]['.hgeol'].data()
                 return eolfile(ui, repo.root, data)
diff -r a58251c0568f -r 5ba1888e15ac mercurial/ui.py
--- a/mercurial/ui.py	Thu Aug 01 22:52:05 2013 -0500
+++ b/mercurial/ui.py	Fri Jul 19 14:10:30 2013 +0200
@@ -199,7 +199,7 @@ 
             src = self.configsource(section, name, untrusted)
             if ':' in src:
                 base = os.path.dirname(src.rsplit(':')[0])
-                v = os.path.join(base, os.path.expanduser(v))
+                v = os.path.join(base, util.expandpath(v))
         return v
 
     def configbool(self, section, name, default=False, untrusted=False):
diff -r a58251c0568f -r 5ba1888e15ac tests/test-eol.t
--- a/tests/test-eol.t	Thu Aug 01 22:52:05 2013 -0500
+++ b/tests/test-eol.t	Fri Jul 19 14:10:30 2013 +0200
@@ -526,3 +526,23 @@ 
   fifth
 
   $ cd ..
+
+Test .hgeol location configuration
+
+  $ hg init configpath
+  $ TESTROOT=`pwd`
+  $ export TESTROOT
+  $ cd configpath
+  $ printf '[patterns]\nxxx = LF\n' >> .hgeol
+  $ hg showconfig | grep encode.*to-lf
+  encode.xxx=to-lf
+  $ printf '[eol]\nconfigpath = ../yyy\n' >> .hg/hgrc
+  $ printf '[patterns]\nyyy = LF\n' >> yyy
+  $ hg showconfig | grep encode.*to-lf
+  encode.yyy=to-lf
+  $ printf '[eol]\nconfigpath = $TESTROOT/zzz\n' >> .hg/hgrc
+  $ printf '[patterns]\nzzz = LF\n' >> $TESTROOT/zzz
+  $ hg showconfig | grep encode.*to-lf
+  encode.zzz=to-lf
+  $ cd ..
+  $ rm -r configpath