##// END OF EJS Templates
ui: add the ability to apply `defaultrc` configs from resources...
Matt Harbison -
r44483:1864efbe default
parent child Browse files
Show More
@@ -2223,6 +2223,8 b' def config(ui, repo, *values, **opts):'
2223 for t, f in rcutil.rccomponents():
2223 for t, f in rcutil.rccomponents():
2224 if t == b'path':
2224 if t == b'path':
2225 ui.debug(b'read config from: %s\n' % f)
2225 ui.debug(b'read config from: %s\n' % f)
2226 elif t == b'resource':
2227 ui.debug(b'read config from: resource:%s.%s\n' % (f[0], f[1]))
2226 elif t == b'items':
2228 elif t == b'items':
2227 # Don't print anything for 'items'.
2229 # Don't print anything for 'items'.
2228 pass
2230 pass
@@ -67,6 +67,17 b' def defaultrcpath():'
67 return _expandrcpath(defaultpath)
67 return _expandrcpath(defaultpath)
68
68
69
69
70 def default_rc_resources():
71 """return rc resource IDs in defaultrc"""
72 rsrcs = resourceutil.contents(b'mercurial.defaultrc')
73 return [
74 (b'mercurial.defaultrc', r)
75 for r in sorted(rsrcs)
76 if resourceutil.is_resource(b'mercurial.defaultrc', r)
77 and r.endswith(b'.rc')
78 ]
79
80
70 def rccomponents():
81 def rccomponents():
71 '''return an ordered [(type, obj)] about where to load configs.
82 '''return an ordered [(type, obj)] about where to load configs.
72
83
@@ -75,9 +86,10 b' def rccomponents():'
75
86
76 if a directory is provided, *.rc files under it will be used.
87 if a directory is provided, *.rc files under it will be used.
77
88
78 type could be either 'path' or 'items', if type is 'path', obj is a string,
89 type could be either 'path', 'items' or 'resource'. If type is 'path',
79 and is the config file path. if type is 'items', obj is a list of (section,
90 obj is a string, and is the config file path. if type is 'items', obj is a
80 name, value, source) that should fill the config directly.
91 list of (section, name, value, source) that should fill the config directly.
92 If type is 'resource', obj is a tuple of (package name, resource name).
81 '''
93 '''
82 envrc = (b'items', envrcitems())
94 envrc = (b'items', envrcitems())
83
95
@@ -90,10 +102,12 b' def rccomponents():'
90 continue
102 continue
91 _rccomponents.extend((b'path', p) for p in _expandrcpath(p))
103 _rccomponents.extend((b'path', p) for p in _expandrcpath(p))
92 else:
104 else:
105 _rccomponents = [(b'resource', r) for r in default_rc_resources()]
106
93 normpaths = lambda paths: [
107 normpaths = lambda paths: [
94 (b'path', os.path.normpath(p)) for p in paths
108 (b'path', os.path.normpath(p)) for p in paths
95 ]
109 ]
96 _rccomponents = normpaths(defaultrcpath() + systemrcpath())
110 _rccomponents.extend(normpaths(defaultrcpath() + systemrcpath()))
97 _rccomponents.append(envrc)
111 _rccomponents.append(envrc)
98 _rccomponents.extend(normpaths(userrcpath()))
112 _rccomponents.extend(normpaths(userrcpath()))
99 return _rccomponents
113 return _rccomponents
@@ -308,6 +308,8 b' class ui(object):'
308 for t, f in rcutil.rccomponents():
308 for t, f in rcutil.rccomponents():
309 if t == b'path':
309 if t == b'path':
310 u.readconfig(f, trust=True)
310 u.readconfig(f, trust=True)
311 elif t == b'resource':
312 u.read_resource_config(f, trust=True)
311 elif t == b'items':
313 elif t == b'items':
312 sections = set()
314 sections = set()
313 for section, name, value, source in f:
315 for section, name, value, source in f:
@@ -37,6 +37,7 b' def userrcpath():'
37
37
38
38
39 extensions.wrapfunction(rcutil, 'defaultrcpath', lambda orig: [])
39 extensions.wrapfunction(rcutil, 'defaultrcpath', lambda orig: [])
40 extensions.wrapfunction(rcutil, 'default_rc_resources', lambda orig: [])
40
41
41 rcutil.systemrcpath = systemrcpath
42 rcutil.systemrcpath = systemrcpath
42 rcutil.userrcpath = userrcpath
43 rcutil.userrcpath = userrcpath
General Comments 0
You need to be logged in to leave comments. Login now