Mercurial > public > mercurial-scm > hg
comparison hgext/chgserver.py @ 28264:3682e201cce6
chgserver: make _renewui load repo and command line configs
Before this patch, there is no way to load repo config in chgserver. This
patch revised _renewui to let it load repo config and take command line
flags passed into consideration.
The _renewui logic is not ideal at present because it's very tricky to know
what should copy and what should not from the old ui object to the new one.
This is partially because the current ui and config object design is not
ideal. In the future, we may want to avoid all ui or config copies.
author | Jun Wu <quark@fb.com> |
---|---|
date | Fri, 26 Feb 2016 15:22:46 +0000 |
parents | 53dc4aada2d9 |
children | b4ceadb2c439 |
comparison
equal
deleted
inserted
replaced
28263:59509c6724c7 | 28264:3682e201cce6 |
---|---|
178 raise onerr(errmsg) | 178 raise onerr(errmsg) |
179 return rc | 179 return rc |
180 | 180 |
181 return chgui(srcui) | 181 return chgui(srcui) |
182 | 182 |
183 def _renewui(srcui): | 183 def _renewui(srcui, args=None): |
184 if not args: | |
185 args = [] | |
186 | |
184 newui = srcui.__class__() | 187 newui = srcui.__class__() |
185 for a in ['fin', 'fout', 'ferr', 'environ']: | 188 for a in ['fin', 'fout', 'ferr', 'environ']: |
186 setattr(newui, a, getattr(srcui, a)) | 189 setattr(newui, a, getattr(srcui, a)) |
187 if util.safehasattr(srcui, '_csystem'): | 190 if util.safehasattr(srcui, '_csystem'): |
188 newui._csystem = srcui._csystem | 191 newui._csystem = srcui._csystem |
192 | |
193 # load wd and repo config, copied from dispatch.py | |
194 cwds = dispatch._earlygetopt(['--cwd'], args) | |
195 cwd = cwds and os.path.realpath(cwds[-1]) or None | |
196 rpath = dispatch._earlygetopt(["-R", "--repository", "--repo"], args) | |
197 path, newui = dispatch._getlocal(newui, rpath, wd=cwd) | |
198 | |
199 # internal config: extensions.chgserver | |
200 # copy it. it can only be overrided from command line. | |
201 newui.setconfig('extensions', 'chgserver', | |
202 srcui.config('extensions', 'chgserver'), '--config') | |
203 | |
204 # command line args | |
205 dispatch._parseconfig(newui, dispatch._earlygetopt(['--config'], args)) | |
206 | |
189 # stolen from tortoisehg.util.copydynamicconfig() | 207 # stolen from tortoisehg.util.copydynamicconfig() |
190 for section, name, value in srcui.walkconfig(): | 208 for section, name, value in srcui.walkconfig(): |
191 source = srcui.configsource(section, name) | 209 source = srcui.configsource(section, name) |
192 if ':' in source: | 210 if ':' in source or source == '--config': |
193 # path:line | 211 # path:line or command line |
194 continue | 212 continue |
195 if source == 'none': | 213 if source == 'none': |
196 # ui.configsource returns 'none' by default | 214 # ui.configsource returns 'none' by default |
197 source = '' | 215 source = '' |
198 newui.setconfig(section, name, value, source) | 216 newui.setconfig(section, name, value, source) |