mercurial/ui.py
changeset 3347 bce7c1b4c1c8
parent 3346 1700a103458e
child 3349 25d270e0b27f
equal deleted inserted replaced
3346:1700a103458e 3347:bce7c1b4c1c8
    69         for f in fn:
    69         for f in fn:
    70             try:
    70             try:
    71                 self.cdata.read(f)
    71                 self.cdata.read(f)
    72             except ConfigParser.ParsingError, inst:
    72             except ConfigParser.ParsingError, inst:
    73                 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst))
    73                 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst))
    74         # translate paths relative to root (or home) into absolute paths
       
    75         if root is None:
       
    76             root = os.path.expanduser('~')
       
    77         for name, path in self.configitems("paths"):
       
    78             if path and "://" not in path and not os.path.isabs(path):
       
    79                 self.cdata.set("paths", name, os.path.join(root, path))
       
    80         # override data from config files with data set with ui.setconfig
    74         # override data from config files with data set with ui.setconfig
    81         if self.overlay:
    75         if self.overlay:
    82             updateconfig(self.overlay, self.cdata)
    76             updateconfig(self.overlay, self.cdata)
       
    77         if root is None:
       
    78             root = os.path.expanduser('~')
       
    79         self.fixconfig(root=root)
    83         for hook in self.readhooks:
    80         for hook in self.readhooks:
    84             hook(self)
    81             hook(self)
    85 
    82 
    86     def addreadhook(self, hook):
    83     def addreadhook(self, hook):
    87         self.readhooks.append(hook)
    84         self.readhooks.append(hook)
       
    85 
       
    86     def fixconfig(self, section=None, name=None, value=None, root=None):
       
    87         # translate paths relative to root (or home) into absolute paths
       
    88         if section is None or section == 'paths':
       
    89             if root is None:
       
    90                 root = os.getcwd()
       
    91             items = section and [(name, value)] or []
       
    92             for cdata in self.cdata, self.overlay:
       
    93                 if not cdata: continue
       
    94                 if not items and cdata.has_section('paths'):
       
    95                     pathsitems = cdata.items('paths')
       
    96                 else:
       
    97                     pathsitems = items
       
    98                 for n, path in pathsitems:
       
    99                     if path and "://" not in path and not os.path.isabs(path):
       
   100                         cdata.set("paths", n, os.path.join(root, path))
    88 
   101 
    89     def setconfig(self, section, name, value):
   102     def setconfig(self, section, name, value):
    90         if not self.overlay:
   103         if not self.overlay:
    91             self.overlay = ConfigParser.SafeConfigParser()
   104             self.overlay = ConfigParser.SafeConfigParser()
    92         for cdata in (self.overlay, self.cdata):
   105         for cdata in (self.overlay, self.cdata):
    93             if not cdata.has_section(section):
   106             if not cdata.has_section(section):
    94                 cdata.add_section(section)
   107                 cdata.add_section(section)
    95             cdata.set(section, name, value)
   108             cdata.set(section, name, value)
       
   109         self.fixconfig(section, name, value)
    96 
   110 
    97     def _config(self, section, name, default, funcname):
   111     def _config(self, section, name, default, funcname):
    98         if self.cdata.has_option(section, name):
   112         if self.cdata.has_option(section, name):
    99             try:
   113             try:
   100                 func = getattr(self.cdata, funcname)
   114                 func = getattr(self.cdata, funcname)