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

Jorge Acereda jacereda at brainstorm.es
Fri Jul 19 07:12:16 CDT 2013


# HG changeset patch
# User Jorge Acereda <jacereda at brainstorm.es>
# Date 1374235830 -7200
# Node ID 04aaab0462d6c836612a85f32f6943627fb88abd
# Parent  004f965630d907a3417a93e87d056ad4c2dab541
eol: support alternate location for .hgeol file (issue3975)

diff -r 004f965630d9 -r 04aaab0462d6 hgext/eol.py
--- a/hgext/eol.py	Fri Jul 12 11:14:42 2013 +0900
+++ 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 004f965630d9 -r 04aaab0462d6 mercurial/ui.py
--- a/mercurial/ui.py	Fri Jul 12 11:14:42 2013 +0900
+++ 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 004f965630d9 -r 04aaab0462d6 tests/test-eol.t
--- a/tests/test-eol.t	Fri Jul 12 11:14:42 2013 +0900
+++ 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


More information about the Mercurial-devel mailing list