changeset 13238:1b591f9b7fd2

ui: add configpath helper
author Matt Mackall <mpm@selenic.com>
date Thu, 06 Jan 2011 17:04:33 -0600
parents c046978cc0a9
children 12ed25f39d0b
files mercurial/ui.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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: