diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1804,8 +1804,11 @@ def config(ui, repo, *values, **opts): return ui.pager('config') fm = ui.formatter('config', opts) - for f in rcutil.rccomponents(): - ui.debug('read config from: %s\n' % f) + for t, f in rcutil.rccomponents(): + if t == 'path': + ui.debug('read config from: %s\n' % f) + else: + raise error.ProgrammingError('unknown rctype: %s' % t) untrusted = bool(opts.get('untrusted')) if values: sections = [v for v in values if '.' not in v] diff --git a/mercurial/rcutil.py b/mercurial/rcutil.py --- a/mercurial/rcutil.py +++ b/mercurial/rcutil.py @@ -43,11 +43,17 @@ def defaultrcpath(): _rccomponents = None def rccomponents(): - '''return hgrc search path. if env var HGRCPATH is set, use it. - for each item in path, if directory, use files ending in .rc, - else use item. - make HGRCPATH empty to only look in .hg/hgrc of current repo. - if no HGRCPATH, use default os-specific path.''' + '''return an ordered [(type, obj)] about where to load configs. + + respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is + used. if $HGRCPATH is not set, the platform default will be used. + + if a directory is provided, *.rc files under it will be used. + + type could be either 'path' or 'items', if type is 'path', obj is a string, + and is the config file path. if type is 'items', obj is a list of (section, + name, value, source) that should fill the config directly. + ''' global _rccomponents if _rccomponents is None: if 'HGRCPATH' in encoding.environ: @@ -55,8 +61,8 @@ def rccomponents(): for p in encoding.environ['HGRCPATH'].split(pycompat.ospathsep): if not p: continue - _rccomponents.extend(_expandrcpath(p)) + _rccomponents.extend(('path', p) for p in _expandrcpath(p)) else: paths = defaultrcpath() + systemrcpath() + userrcpath() - _rccomponents = pycompat.maplist(os.path.normpath, paths) + _rccomponents = [('path', os.path.normpath(p)) for p in paths] return _rccomponents diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -212,8 +212,11 @@ class ui(object): """Create a ui and load global and user configs""" u = cls() # we always trust global config files - for f in rcutil.rccomponents(): - u.readconfig(f, trust=True) + for t, f in rcutil.rccomponents(): + if t == 'path': + u.readconfig(f, trust=True) + else: + raise error.ProgrammingError('unknown rctype: %s' % t) return u def copy(self):