changeset 8183:2858ab754995

config: allow including other config files
author Matt Mackall <mpm@selenic.com>
date Sun, 26 Apr 2009 16:50:43 -0500
parents b97abc7c1135
children 9189afe1eba3
files mercurial/config.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/config.py	Sun Apr 26 16:50:43 2009 -0500
+++ b/mercurial/config.py	Sun Apr 26 16:50:43 2009 -0500
@@ -1,5 +1,5 @@
 from i18n import _
-import re, error
+import re, error, os
 
 class sortdict(dict):
     'a simple append-only sorted dictionary'
@@ -62,6 +62,7 @@
         itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)')
         contre = re.compile(r'\s+(\S.*)')
         emptyre = re.compile(r'(;|#|\s*$)')
+        includere = re.compile(r'%include\s+(\S.*)')
         section = ""
         item = None
         line = 0
@@ -79,6 +80,14 @@
                     self.set(section, item, v, "%s:%d" % (path, line))
                     continue
                 item = None
+            m = includere.match(l)
+            if m:
+                inc = m.group(1)
+                base = os.path.dirname(path)
+                inc = os.path.normpath(os.path.join(base, inc))
+                incfp = open(inc)
+                self.read(inc, incfp)
+                continue
             if emptyre.match(l):
                 continue
             m = sectionre.match(l)