comparison mercurial/localrepo.py @ 39690:e0c5017124b3

localrepo: load extensions in makelocalrepository() Behavior does change subtly. First, we now load the hgrc before optionally setting up the vfs ward. That's fine: the vfs ward is for debugging and we know we won't hit it when reading .hg/hgrc. If the loaded extension were performing repo/vfs I/O, then we'd be worried. But extensions don't have access to the repo object that loaded them when they are loaded. Unless they are doing stack walking as part of module loading (which would be crazy), they shouldn't have access to the repo that incurred their load. Second, we now load extensions outside of the try..except IOError block. Previously, if loading an extension raised IOError, it would be silently ignored. I'm pretty sure the IOError is there for missing .hgrc files and should never have been ignored for issues loading extensions. I don't think this matters in reality because extension loading traps I/O errors. Differential Revision: https://phab.mercurial-scm.org/D4566
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 12 Sep 2018 11:44:57 -0700
parents f19bba3f4d3f
children 2f067e365532
comparison
equal deleted inserted replaced
39689:f19bba3f4d3f 39690:e0c5017124b3
395 395
396 # Main VFS for .hg/ directory. 396 # Main VFS for .hg/ directory.
397 hgpath = wdirvfs.join(b'.hg') 397 hgpath = wdirvfs.join(b'.hg')
398 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) 398 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
399 399
400 # The .hg/hgrc file may load extensions or contain config options
401 # that influence repository construction. Attempt to load it and
402 # process any new extensions that it may have pulled in.
403 try:
404 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
405 except IOError:
406 pass
407 else:
408 extensions.loadall(ui)
409
400 return localrepository( 410 return localrepository(
401 baseui=baseui, 411 baseui=baseui,
402 ui=ui, 412 ui=ui,
403 origroot=path, 413 origroot=path,
404 wdirvfs=wdirvfs, 414 wdirvfs=wdirvfs,
505 self.vfs.audit = self._getvfsward(self.vfs.audit) 515 self.vfs.audit = self._getvfsward(self.vfs.audit)
506 # A list of callback to shape the phase if no data were found. 516 # A list of callback to shape the phase if no data were found.
507 # Callback are in the form: func(repo, roots) --> processed root. 517 # Callback are in the form: func(repo, roots) --> processed root.
508 # This list it to be filled by extension during repo setup 518 # This list it to be filled by extension during repo setup
509 self._phasedefaults = [] 519 self._phasedefaults = []
510 try:
511 self.ui.readconfig(self.vfs.join("hgrc"), self.root)
512 self._loadextensions()
513 except IOError:
514 pass
515 520
516 if featuresetupfuncs: 521 if featuresetupfuncs:
517 self.supported = set(self._basesupported) # use private copy 522 self.supported = set(self._basesupported) # use private copy
518 extmods = set(m.__name__ for n, m 523 extmods = set(m.__name__ for n, m
519 in extensions.extensions(self.ui)) 524 in extensions.extensions(self.ui))
672 return ret 677 return ret
673 return checksvfs 678 return checksvfs
674 679
675 def close(self): 680 def close(self):
676 self._writecaches() 681 self._writecaches()
677
678 def _loadextensions(self):
679 extensions.loadall(self.ui)
680 682
681 def _writecaches(self): 683 def _writecaches(self):
682 if self._revbranchcache: 684 if self._revbranchcache:
683 self._revbranchcache.write() 685 self._revbranchcache.write()
684 686