comparison hgext/chgserver.py @ 28599:0e7a929754aa

chgserver: use global ui instead of repo ui for dispatch.request.ui Before this patch, chgserver will use repo ui as dispatch.request.ui, while req.ui is designed to be global ui without repo config. Passing repo ui as dispatch.request.ui leads to repo.ui being incorrect, which can lead to unwanted results. For example, if the repo config has [extensions], it could affect which localrepository.featuresetupfuncs get executed and the repo may have an incorrect list of supported requirements. This patch changes _renewui to return both global ui and repo ui. The global ui is passed to req.ui, and the repo ui is used to calculate confighash. It will make chg pass test-largefiles-misc.t and test-requires.t, which are both related to repo requirements.
author Jun Wu <quark@fb.com>
date Thu, 17 Mar 2016 18:32:10 +0000
parents 82cee85d5274
children 83127a9fe76e
comparison
equal deleted inserted replaced
28598:c30d5ca4945b 28599:0e7a929754aa
265 raise onerr(errmsg) 265 raise onerr(errmsg)
266 return rc 266 return rc
267 267
268 return chgui(srcui) 268 return chgui(srcui)
269 269
270 def _renewui(srcui, args=None): 270 def _loadnewui(srcui, args=None):
271 if not args: 271 if not args:
272 args = [] 272 args = []
273 273
274 newui = srcui.__class__() 274 newui = srcui.__class__()
275 for a in ['fin', 'fout', 'ferr', 'environ']: 275 for a in ['fin', 'fout', 'ferr', 'environ']:
276 setattr(newui, a, getattr(srcui, a)) 276 setattr(newui, a, getattr(srcui, a))
277 if util.safehasattr(srcui, '_csystem'): 277 if util.safehasattr(srcui, '_csystem'):
278 newui._csystem = srcui._csystem 278 newui._csystem = srcui._csystem
279 279
280 # load wd and repo config, copied from dispatch.py
281 cwds = dispatch._earlygetopt(['--cwd'], args)
282 cwd = cwds and os.path.realpath(cwds[-1]) or None
283 rpath = dispatch._earlygetopt(["-R", "--repository", "--repo"], args)
284 path, newui = dispatch._getlocal(newui, rpath, wd=cwd)
285
286 # internal config: extensions.chgserver 280 # internal config: extensions.chgserver
287 # copy it. it can only be overrided from command line.
288 newui.setconfig('extensions', 'chgserver', 281 newui.setconfig('extensions', 'chgserver',
289 srcui.config('extensions', 'chgserver'), '--config') 282 srcui.config('extensions', 'chgserver'), '--config')
290 283
291 # command line args 284 # command line args
292 dispatch._parseconfig(newui, dispatch._earlygetopt(['--config'], args)) 285 dispatch._parseconfig(newui, dispatch._earlygetopt(['--config'], args))
299 continue 292 continue
300 if source == 'none': 293 if source == 'none':
301 # ui.configsource returns 'none' by default 294 # ui.configsource returns 'none' by default
302 source = '' 295 source = ''
303 newui.setconfig(section, name, value, source) 296 newui.setconfig(section, name, value, source)
304 return newui 297
298 # load wd and repo config, copied from dispatch.py
299 args = args[:]
300 cwds = dispatch._earlygetopt(['--cwd'], args)
301 cwd = cwds and os.path.realpath(cwds[-1]) or None
302 rpath = dispatch._earlygetopt(["-R", "--repository", "--repo"], args)
303 path, newlui = dispatch._getlocal(newui, rpath, wd=cwd)
304
305 return (newui, newlui)
305 306
306 class channeledsystem(object): 307 class channeledsystem(object):
307 """Propagate ui.system() request in the following format: 308 """Propagate ui.system() request in the following format:
308 309
309 payload length (unsigned int), 310 payload length (unsigned int),
448 list, the client can continue with this server after completing all 449 list, the client can continue with this server after completing all
449 the instructions. 450 the instructions.
450 """ 451 """
451 args = self._readlist() 452 args = self._readlist()
452 try: 453 try:
453 self.ui = _renewui(self.ui, args) 454 self.ui, lui = _loadnewui(self.ui, args)
454 except error.ParseError as inst: 455 except error.ParseError as inst:
455 dispatch._formatparse(self.ui.warn, inst) 456 dispatch._formatparse(self.ui.warn, inst)
456 self.ui.flush() 457 self.ui.flush()
457 self.cresult.write('exit 255') 458 self.cresult.write('exit 255')
458 return 459 return
459 newhash = hashstate.fromui(self.ui, self.hashstate.mtimepaths) 460 newhash = hashstate.fromui(lui, self.hashstate.mtimepaths)
460 insts = [] 461 insts = []
461 if newhash.mtimehash != self.hashstate.mtimehash: 462 if newhash.mtimehash != self.hashstate.mtimehash:
462 addr = _hashaddress(self.baseaddress, self.hashstate.confighash) 463 addr = _hashaddress(self.baseaddress, self.hashstate.confighash)
463 insts.append('unlink %s' % addr) 464 insts.append('unlink %s' % addr)
464 # mtimehash is empty if one or more extensions fail to load. 465 # mtimehash is empty if one or more extensions fail to load.
531 os.environ.clear() 532 os.environ.clear()
532 os.environ.update(newenv) 533 os.environ.update(newenv)
533 534
534 if set(['HGPLAIN', 'HGPLAINEXCEPT']) & diffkeys: 535 if set(['HGPLAIN', 'HGPLAINEXCEPT']) & diffkeys:
535 # reload config so that ui.plain() takes effect 536 # reload config so that ui.plain() takes effect
536 self.ui = _renewui(self.ui) 537 self.ui, _lui = _loadnewui(self.ui)
537 538
538 _clearenvaliases(commands.table) 539 _clearenvaliases(commands.table)
539 540
540 capabilities = commandserver.server.capabilities.copy() 541 capabilities = commandserver.server.capabilities.copy()
541 capabilities.update({'attachio': attachio, 542 capabilities.update({'attachio': attachio,