##// END OF EJS Templates
config: include the component level when returning them...
marmoute -
r53323:22129ce9 default
parent child Browse files
Show More
@@ -10,11 +10,15 from typing import (
10
10
11 # keep typing simple for now
11 # keep typing simple for now
12 ConfigLevelT = str
12 ConfigLevelT = str
13 LEVEL_USER = 'user' # "user" is the default level and never passed explicitly
13 LEVEL_BUNDLED_RESOURCE = 'RESOURCE'
14 LEVEL_ENV_OVERWRITE = 'ENV-HGRCPATH'
15 LEVEL_USER = 'user'
14 LEVEL_LOCAL = 'local'
16 LEVEL_LOCAL = 'local'
15 LEVEL_GLOBAL = 'global'
17 LEVEL_GLOBAL = 'global'
16 LEVEL_SHARED = 'shared'
18 LEVEL_SHARED = 'shared'
17 LEVEL_NON_SHARED = 'non_shared'
19 LEVEL_NON_SHARED = 'non_shared'
20 # only include level that it make sense to edit
21 # note: "user" is the default level and never passed explicitly
18 EDIT_LEVELS = (
22 EDIT_LEVELS = (
19 LEVEL_USER,
23 LEVEL_USER,
20 LEVEL_LOCAL,
24 LEVEL_LOCAL,
@@ -27,6 +31,7 ConfigItemT = Tuple[bytes, bytes, bytes,
27 ResourceIDT = Tuple[bytes, bytes]
31 ResourceIDT = Tuple[bytes, bytes]
28 FileRCT = bytes
32 FileRCT = bytes
29 ComponentT = Tuple[
33 ComponentT = Tuple[
34 ConfigLevelT,
30 bytes,
35 bytes,
31 Union[
36 Union[
32 List[ConfigItemT],
37 List[ConfigItemT],
@@ -111,7 +111,7 def show_component(ui: uimod.ui, repo) -
111 XXX this skip over various source and ignore the repository config, so it
111 XXX this skip over various source and ignore the repository config, so it
112 XXX is probably useless old code.
112 XXX is probably useless old code.
113 """
113 """
114 for t, f in rcutil.rccomponents():
114 for _lvl, t, f in rcutil.rccomponents():
115 if t == b'path':
115 if t == b'path':
116 ui.debug(b'read config from: %s\n' % f)
116 ui.debug(b'read config from: %s\n' % f)
117 elif t == b'resource':
117 elif t == b'resource':
@@ -100,25 +100,29 def rccomponents() -> List[ComponentT]:
100 list of (section, name, value, source) that should fill the config directly.
100 list of (section, name, value, source) that should fill the config directly.
101 If type is 'resource', obj is a tuple of (package name, resource name).
101 If type is 'resource', obj is a tuple of (package name, resource name).
102 """
102 """
103 envrc = (b'items', envrcitems())
103 envrc = (conf_mod.LEVEL_ENV_OVERWRITE, b'items', envrcitems())
104
105 _rccomponents = []
106 comp = _rccomponents.append
104
107
105 if b'HGRCPATH' in encoding.environ:
108 if b'HGRCPATH' in encoding.environ:
106 # assume HGRCPATH is all about user configs so environments can be
109 # assume HGRCPATH is all about user configs so environments can be
107 # overridden.
110 # overridden.
108 _rccomponents = [envrc]
111 comp(envrc)
109 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep):
112 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep):
110 if not p:
113 if not p:
111 continue
114 continue
112 _rccomponents.extend((b'path', p) for p in _expandrcpath(p))
115 for p in _expandrcpath(p):
116 comp((conf_mod.LEVEL_ENV_OVERWRITE, b'path', p))
113 else:
117 else:
114 _rccomponents = [(b'resource', r) for r in default_rc_resources()]
118 for r in default_rc_resources():
119 comp((conf_mod.LEVEL_BUNDLED_RESOURCE, b'resource', r))
115
120
116 normpaths = lambda paths: [
121 for p in systemrcpath():
117 (b'path', os.path.normpath(p)) for p in paths
122 comp((conf_mod.LEVEL_GLOBAL, b'path', os.path.normpath(p)))
118 ]
123 comp(envrc)
119 _rccomponents.extend(normpaths(systemrcpath()))
124 for p in userrcpath():
120 _rccomponents.append(envrc)
125 comp((conf_mod.LEVEL_USER, b'path', os.path.normpath(p)))
121 _rccomponents.extend(normpaths(userrcpath()))
122 return _rccomponents
126 return _rccomponents
123
127
124
128
@@ -147,10 +151,24 def _shared_source_component(path: bytes
147 def repo_components(repo_path: bytes) -> List[ComponentT]:
151 def repo_components(repo_path: bytes) -> List[ComponentT]:
148 """return the list of config file to read for a repository"""
152 """return the list of config file to read for a repository"""
149 components = []
153 components = []
150 components.extend(_shared_source_component(repo_path))
154 comp = components.append
151 components.append(os.path.join(repo_path, b".hg", b"hgrc"))
155 for p in _shared_source_component(repo_path):
152 components.append(os.path.join(repo_path, b".hg", b"hgrc-not-shared"))
156 comp((conf_mod.LEVEL_SHARED, b'path', p))
153 return [(b'path', c) for c in components]
157 comp(
158 (
159 conf_mod.LEVEL_LOCAL,
160 b'path',
161 os.path.join(repo_path, b".hg", b"hgrc"),
162 )
163 )
164 comp(
165 (
166 conf_mod.LEVEL_NON_SHARED,
167 b'path',
168 os.path.join(repo_path, b".hg", b"hgrc-not-shared"),
169 )
170 )
171 return components
154
172
155
173
156 def defaultpagerenv() -> Dict[bytes, bytes]:
174 def defaultpagerenv() -> Dict[bytes, bytes]:
@@ -954,7 +954,7 def _getlocal(ui, rpath, wd=None):
954 else:
954 else:
955 lui = ui.copy()
955 lui = ui.copy()
956 if rcutil.use_repo_hgrc():
956 if rcutil.use_repo_hgrc():
957 for c_type, rc_path in rcutil.repo_components(path):
957 for __, c_type, rc_path in rcutil.repo_components(path):
958 assert c_type == b'path'
958 assert c_type == b'path'
959 lui.readconfig(rc_path, root=path)
959 lui.readconfig(rc_path, root=path)
960
960
@@ -966,7 +966,7 def _getlocal(ui, rpath, wd=None):
966 path = path_obj.rawloc
966 path = path_obj.rawloc
967 lui = ui.copy()
967 lui = ui.copy()
968 if rcutil.use_repo_hgrc():
968 if rcutil.use_repo_hgrc():
969 for c_type, rc_path in rcutil.repo_components(path):
969 for __, c_type, rc_path in rcutil.repo_components(path):
970 assert c_type == b'path'
970 assert c_type == b'path'
971 lui.readconfig(rc_path, root=path)
971 lui.readconfig(rc_path, root=path)
972
972
@@ -335,7 +335,7 class ui:
335 """Create a ui and load global and user configs"""
335 """Create a ui and load global and user configs"""
336 u = cls()
336 u = cls()
337 # we always trust global config files and environment variables
337 # we always trust global config files and environment variables
338 for t, f in rcutil.rccomponents():
338 for _lvl, t, f in rcutil.rccomponents():
339 if t == b'path':
339 if t == b'path':
340 u.readconfig(f, trust=True)
340 u.readconfig(f, trust=True)
341 elif t == b'resource':
341 elif t == b'resource':
General Comments 0
You need to be logged in to leave comments. Login now