ui: add configpath helper
authorMatt Mackall <mpm@selenic.com>
Thu, 06 Jan 2011 17:04:33 -0600
changeset 13238 1b591f9b7fd2
parent 13237 c046978cc0a9
child 13239 12ed25f39d0b
ui: add configpath helper
mercurial/ui.py
--- a/mercurial/ui.py	Wed Dec 29 18:29:15 2010 -0800
+++ b/mercurial/ui.py	Thu Jan 06 17:04:33 2011 -0600
@@ -153,6 +153,16 @@
                              "%s.%s = %s\n") % (section, name, uvalue))
         return value
 
+    def configpath(self, section, name, default=None, untrusted=False):
+        'get a path config item, expanded relative to config file'
+        v = self.config(section, name, default, untrusted)
+        if not os.path.isabs(v) or "://" not in v:
+            src = self.configsource(section, name, untrusted)
+            if ':' in src:
+                base = os.path.dirname(src.rsplit(':'))
+                v = os.path.join(base, os.path.expanduser(v))
+        return v
+
     def configbool(self, section, name, default=False, untrusted=False):
         v = self.config(section, name, None, untrusted)
         if v is None: