config: allow including other config files
authorMatt Mackall <mpm@selenic.com>
Sun, 26 Apr 2009 16:50:43 -0500
changeset 8183 2858ab754995
parent 8182 b97abc7c1135
child 8184 9189afe1eba3
config: allow including other config files
mercurial/config.py
--- 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)