##// END OF EJS Templates
rcutil: let rccomponents return different types of configs (API)...
Jun Wu -
r31683:00e569a2 default
parent child Browse files
Show More
@@ -1804,8 +1804,11 b' def config(ui, repo, *values, **opts):'
1804 1804 return
1805 1805 ui.pager('config')
1806 1806 fm = ui.formatter('config', opts)
1807 for f in rcutil.rccomponents():
1808 ui.debug('read config from: %s\n' % f)
1807 for t, f in rcutil.rccomponents():
1808 if t == 'path':
1809 ui.debug('read config from: %s\n' % f)
1810 else:
1811 raise error.ProgrammingError('unknown rctype: %s' % t)
1809 1812 untrusted = bool(opts.get('untrusted'))
1810 1813 if values:
1811 1814 sections = [v for v in values if '.' not in v]
@@ -43,11 +43,17 b' def defaultrcpath():'
43 43 _rccomponents = None
44 44
45 45 def rccomponents():
46 '''return hgrc search path. if env var HGRCPATH is set, use it.
47 for each item in path, if directory, use files ending in .rc,
48 else use item.
49 make HGRCPATH empty to only look in .hg/hgrc of current repo.
50 if no HGRCPATH, use default os-specific path.'''
46 '''return an ordered [(type, obj)] about where to load configs.
47
48 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is
49 used. if $HGRCPATH is not set, the platform default will be used.
50
51 if a directory is provided, *.rc files under it will be used.
52
53 type could be either 'path' or 'items', if type is 'path', obj is a string,
54 and is the config file path. if type is 'items', obj is a list of (section,
55 name, value, source) that should fill the config directly.
56 '''
51 57 global _rccomponents
52 58 if _rccomponents is None:
53 59 if 'HGRCPATH' in encoding.environ:
@@ -55,8 +61,8 b' def rccomponents():'
55 61 for p in encoding.environ['HGRCPATH'].split(pycompat.ospathsep):
56 62 if not p:
57 63 continue
58 _rccomponents.extend(_expandrcpath(p))
64 _rccomponents.extend(('path', p) for p in _expandrcpath(p))
59 65 else:
60 66 paths = defaultrcpath() + systemrcpath() + userrcpath()
61 _rccomponents = pycompat.maplist(os.path.normpath, paths)
67 _rccomponents = [('path', os.path.normpath(p)) for p in paths]
62 68 return _rccomponents
@@ -212,8 +212,11 b' class ui(object):'
212 212 """Create a ui and load global and user configs"""
213 213 u = cls()
214 214 # we always trust global config files
215 for f in rcutil.rccomponents():
216 u.readconfig(f, trust=True)
215 for t, f in rcutil.rccomponents():
216 if t == 'path':
217 u.readconfig(f, trust=True)
218 else:
219 raise error.ProgrammingError('unknown rctype: %s' % t)
217 220 return u
218 221
219 222 def copy(self):
General Comments 0
You need to be logged in to leave comments. Login now