Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 45496:b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
The second part of the Share Safe Plan is to share source repo config also.
This patch adds logic to load the source repo .hg/hgrc if we are in share safe
mode. On unshare, we copy and prepend source config to current repo so that
config which was shared is persisted.
A test is added to show that now if we enable a hook on the source repo, that
also runs on the shared repositories.
API change as a new optional argument sharedvfs added to localrepo.loadhgrc()
Differential Revision: https://phab.mercurial-scm.org/D8656
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 02 Jul 2020 16:23:36 +0530 |
parents | d252f51ab032 |
children | 0ce6af73f481 |
comparison
equal
deleted
inserted
replaced
45495:63eb1b5c580d | 45496:b71858b42963 |
---|---|
567 requirements |= _readrequires(storevfs, False) | 567 requirements |= _readrequires(storevfs, False) |
568 | 568 |
569 # The .hg/hgrc file may load extensions or contain config options | 569 # The .hg/hgrc file may load extensions or contain config options |
570 # that influence repository construction. Attempt to load it and | 570 # that influence repository construction. Attempt to load it and |
571 # process any new extensions that it may have pulled in. | 571 # process any new extensions that it may have pulled in. |
572 if loadhgrc(ui, wdirvfs, hgvfs, requirements): | 572 if loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs): |
573 afterhgrcload(ui, wdirvfs, hgvfs, requirements) | 573 afterhgrcload(ui, wdirvfs, hgvfs, requirements) |
574 extensions.loadall(ui) | 574 extensions.loadall(ui) |
575 extensions.populateui(ui) | 575 extensions.populateui(ui) |
576 | 576 |
577 # Set of module names of extensions loaded for this repository. | 577 # Set of module names of extensions loaded for this repository. |
695 features=features, | 695 features=features, |
696 intents=intents, | 696 intents=intents, |
697 ) | 697 ) |
698 | 698 |
699 | 699 |
700 def loadhgrc(ui, wdirvfs, hgvfs, requirements): | 700 def loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs=None): |
701 """Load hgrc files/content into a ui instance. | 701 """Load hgrc files/content into a ui instance. |
702 | 702 |
703 This is called during repository opening to load any additional | 703 This is called during repository opening to load any additional |
704 config files or settings relevant to the current repository. | 704 config files or settings relevant to the current repository. |
705 | 705 |
706 Returns a bool indicating whether any additional configs were loaded. | 706 Returns a bool indicating whether any additional configs were loaded. |
707 | 707 |
708 Extensions should monkeypatch this function to modify how per-repo | 708 Extensions should monkeypatch this function to modify how per-repo |
709 configs are loaded. For example, an extension may wish to pull in | 709 configs are loaded. For example, an extension may wish to pull in |
710 configs from alternate files or sources. | 710 configs from alternate files or sources. |
711 | |
712 sharedvfs is vfs object pointing to source repo if the current one is a | |
713 shared one | |
711 """ | 714 """ |
712 if not rcutil.use_repo_hgrc(): | 715 if not rcutil.use_repo_hgrc(): |
713 return False | 716 return False |
717 | |
718 # first load config from shared source if we has to | |
719 if requirementsmod.SHARESAFE_REQUIREMENT in requirements and sharedvfs: | |
720 try: | |
721 ui.readconfig(sharedvfs.join(b'hgrc'), root=sharedvfs.base) | |
722 except IOError: | |
723 pass | |
724 | |
714 try: | 725 try: |
715 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | 726 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) |
716 return True | 727 return True |
717 except IOError: | 728 except IOError: |
718 return False | 729 return False |