Mercurial > hg
comparison mercurial/localrepo.py @ 40535:473510bf0575
localrepo: extract loading of hgrc files to standalone function
Various 3rd party extensions supplement where per-repo config data
lives. Looking at their sources, they resort to unorthodox means to
inject the config data. And the way they do it is susceptible to
corner cases. e.g. not processing automatic extension loads,
not reacting to new or disabled extensions in configs, etc.
This commit extracts the core logic of loading hgrc files into
a standalone function so there is a clear function that can be
monkeypatched to inject per-repo config data at repository open
time.
Differential Revision: https://phab.mercurial-scm.org/D5221
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 05 Nov 2018 14:14:32 -0800 |
parents | 7caf632e30c3 |
children | 5bcf264bb1a0 |
comparison
equal
deleted
inserted
replaced
40534:7ed611c60168 | 40535:473510bf0575 |
---|---|
449 requirements = set() | 449 requirements = set() |
450 | 450 |
451 # The .hg/hgrc file may load extensions or contain config options | 451 # The .hg/hgrc file may load extensions or contain config options |
452 # that influence repository construction. Attempt to load it and | 452 # that influence repository construction. Attempt to load it and |
453 # process any new extensions that it may have pulled in. | 453 # process any new extensions that it may have pulled in. |
454 try: | 454 if loadhgrc(ui, wdirvfs, hgvfs, requirements): |
455 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | |
456 # Run this before extensions.loadall() so extensions can be | |
457 # automatically enabled. | |
458 afterhgrcload(ui, wdirvfs, hgvfs, requirements) | 455 afterhgrcload(ui, wdirvfs, hgvfs, requirements) |
459 except IOError: | |
460 pass | |
461 else: | |
462 extensions.loadall(ui) | 456 extensions.loadall(ui) |
463 | 457 |
464 # Set of module names of extensions loaded for this repository. | 458 # Set of module names of extensions loaded for this repository. |
465 extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} | 459 extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} |
466 | 460 |
579 sharedpath=storebasepath, | 573 sharedpath=storebasepath, |
580 store=store, | 574 store=store, |
581 cachevfs=cachevfs, | 575 cachevfs=cachevfs, |
582 features=features, | 576 features=features, |
583 intents=intents) | 577 intents=intents) |
578 | |
579 def loadhgrc(ui, wdirvfs, hgvfs, requirements): | |
580 """Load hgrc files/content into a ui instance. | |
581 | |
582 This is called during repository opening to load any additional | |
583 config files or settings relevant to the current repository. | |
584 | |
585 Returns a bool indicating whether any additional configs were loaded. | |
586 | |
587 Extensions should monkeypatch this function to modify how per-repo | |
588 configs are loaded. For example, an extension may wish to pull in | |
589 configs from alternate files or sources. | |
590 """ | |
591 try: | |
592 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | |
593 return True | |
594 except IOError: | |
595 return False | |
584 | 596 |
585 def afterhgrcload(ui, wdirvfs, hgvfs, requirements): | 597 def afterhgrcload(ui, wdirvfs, hgvfs, requirements): |
586 """Perform additional actions after .hg/hgrc is loaded. | 598 """Perform additional actions after .hg/hgrc is loaded. |
587 | 599 |
588 This function is called during repository loading immediately after | 600 This function is called during repository loading immediately after |