[PATCH stable] config: allow single-character continuation lines and %include filenames

Matt Mackall mpm at selenic.com
Thu Jan 28 23:06:58 CST 2010


On Wed, 2010-01-27 at 22:15 -0500, Greg Ward wrote:
> # HG changeset patch
> # User Greg Ward <greg-hg at gerg.ca>
> # Date 1264648479 18000
> # Branch stable
> # Node ID 70551c4f2f90a58280177a8d9eceac72e42131a3
> # Parent  1c4ab236ebcbb2602a3e77c32796a29db2a227c4
> config: allow single-character continuation lines and %include filenames
> (issue1999)

Thanks for working on this. I took another stab at fixing up the regex
and came up with this, which actually works. I also simplified the test
case:

diff -r b6f0c20e3b9e mercurial/config.py
--- a/mercurial/config.py	Thu Jan 28 22:45:56 2010 -0600
+++ b/mercurial/config.py	Thu Jan 28 23:02:27 2010 -0600
@@ -73,10 +73,10 @@
     def parse(self, src, data, sections=None, remap=None, include=None):
         sectionre = re.compile(r'\[([^\[]+)\]')
         itemre = re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)')
-        contre = re.compile(r'\s+(\S|\S.*\S)')
+        contre = re.compile(r'\s+(\S|\S.*\S)\s*$')
         emptyre = re.compile(r'(;|#|\s*$)')
         unsetre = re.compile(r'%unset\s+(\S+)')
-        includere = re.compile(r'%include\s+(\S|\S.*\S)')
+        includere = re.compile(r'%include\s+(\S|\S.*\S)\s*$')
         section = ""
         item = None
         line = 0
diff -r b6f0c20e3b9e tests/test-hgrc
--- a/tests/test-hgrc	Thu Jan 28 22:45:56 2010 -0600
+++ b/tests/test-hgrc	Thu Jan 28 23:02:27 2010 -0600
@@ -23,5 +23,9 @@
 echo '  x = y' >> $HGRCPATH
 hg version 2>&1 | sed -e "s|$HGRCPATH|\$HGRCPATH|"
 
+python -c "print '[foo]\nbar = a\n b\n c \n  de\n fg \nbaz = bif cb \n'" \
+    > $HGRCPATH
+hg showconfig foo
+
 echo '%include /no-such-file' > $HGRCPATH
 hg version 2>&1 | sed -e "s|$HGRCPATH|\$HGRCPATH|"
diff -r b6f0c20e3b9e tests/test-hgrc.out
--- a/tests/test-hgrc.out	Thu Jan 28 22:45:56 2010 -0600
+++ b/tests/test-hgrc.out	Thu Jan 28 23:02:27 2010 -0600
@@ -11,4 +11,6 @@
 paths.default=.../foo%bar
 ui.slash=True
 hg: config error at $HGRCPATH:8: '  x = y'
+foo.bar=a\nb\nc\nde\nfg
+foo.baz=bif cb
 hg: config error at $HGRCPATH:1: cannot include /no-such-file (No such file or directory)


-- 
http://selenic.com : development and support for Mercurial and Linux




More information about the Mercurial-devel mailing list