mercurial/ui.py
changeset 24250 9c32eea2ca04
parent 23269 d9d8d2e0f701
child 24663 7d01371e6358
equal deleted inserted replaced
24249:5058e6962fcc 24250:9c32eea2ca04
   529     def expandpath(self, loc, default=None):
   529     def expandpath(self, loc, default=None):
   530         """Return repository location relative to cwd or from [paths]"""
   530         """Return repository location relative to cwd or from [paths]"""
   531         if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
   531         if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
   532             return loc
   532             return loc
   533 
   533 
   534         path = self.config('paths', loc)
   534         p = self.paths.getpath(loc, default=default)
   535         if not path and default is not None:
   535         if p:
   536             path = self.config('paths', default)
   536             return p.loc
   537         return path or loc
   537         return loc
       
   538 
       
   539     @util.propertycache
       
   540     def paths(self):
       
   541         return paths(self)
   538 
   542 
   539     def pushbuffer(self, error=False):
   543     def pushbuffer(self, error=False):
   540         """install a buffer to capture standard output of the ui object
   544         """install a buffer to capture standard output of the ui object
   541 
   545 
   542         If error is True, the error output will be captured too."""
   546         If error is True, the error output will be captured too."""
   921 
   925 
   922         ui.write(s, 'label') is equivalent to
   926         ui.write(s, 'label') is equivalent to
   923         ui.write(ui.label(s, 'label')).
   927         ui.write(ui.label(s, 'label')).
   924         '''
   928         '''
   925         return msg
   929         return msg
       
   930 
       
   931 class paths(dict):
       
   932     """Represents a collection of paths and their configs.
       
   933 
       
   934     Data is initially derived from ui instances and the config files they have
       
   935     loaded.
       
   936     """
       
   937     def __init__(self, ui):
       
   938         dict.__init__(self)
       
   939 
       
   940         for name, loc in ui.configitems('paths'):
       
   941             # No location is the same as not existing.
       
   942             if not loc:
       
   943                 continue
       
   944             self[name] = path(name, rawloc=loc)
       
   945 
       
   946     def getpath(self, name, default=None):
       
   947         """Return a ``path`` for the specified name, falling back to a default.
       
   948 
       
   949         Returns the first of ``name`` or ``default`` that is present, or None
       
   950         if neither is present.
       
   951         """
       
   952         try:
       
   953             return self[name]
       
   954         except KeyError:
       
   955             if default is not None:
       
   956                 try:
       
   957                     return self[default]
       
   958                 except KeyError:
       
   959                     pass
       
   960 
       
   961         return None
       
   962 
       
   963 class path(object):
       
   964     """Represents an individual path and its configuration."""
       
   965 
       
   966     def __init__(self, name, rawloc=None):
       
   967         """Construct a path from its config options.
       
   968 
       
   969         ``name`` is the symbolic name of the path.
       
   970         ``rawloc`` is the raw location, as defined in the config.
       
   971         """
       
   972         self.name = name
       
   973         # We'll do more intelligent things with rawloc in the future.
       
   974         self.loc = rawloc