Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/dispatch.py @ 45805:fd1de908f2b4
dispatch: load shared source repository config in share-safe mode
It seems to me now that there are two steps when config is loaded:
1) on dispatch
2) repository object creation
Recent patches added functionality that there can be shares in share-safe mode
where config of the source repository is shared with the the shares. However we
missed adding logic to read the source config on dispatch. This leads to
extensions not being loaded on dispatch and hence extensions command not being
recognized.
This patch fixes it by reading the shared source config on dispatch.
Differential Revision: https://phab.mercurial-scm.org/D9047
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Fri, 18 Sep 2020 18:52:38 +0530 |
parents | 0883413e09bc |
children | 88a47cbf063c |
comparison
equal
deleted
inserted
replaced
45804:b1664f6eb650 | 45805:fd1de908f2b4 |
---|---|
34 extensions, | 34 extensions, |
35 fancyopts, | 35 fancyopts, |
36 help, | 36 help, |
37 hg, | 37 hg, |
38 hook, | 38 hook, |
39 localrepo, | |
39 profiling, | 40 profiling, |
40 pycompat, | 41 pycompat, |
41 rcutil, | 42 rcutil, |
42 registrar, | 43 registrar, |
44 requirements as requirementsmod, | |
43 scmutil, | 45 scmutil, |
44 ui as uimod, | 46 ui as uimod, |
45 util, | 47 util, |
48 vfs, | |
46 ) | 49 ) |
47 | 50 |
48 from .utils import ( | 51 from .utils import ( |
49 procutil, | 52 procutil, |
50 stringutil, | 53 stringutil, |
937 ) | 940 ) |
938 raise | 941 raise |
939 return ret | 942 return ret |
940 | 943 |
941 | 944 |
945 def _readsharedsourceconfig(ui, path): | |
946 """if the current repository is shared one, this tries to read | |
947 .hg/hgrc of shared source if we are in share-safe mode | |
948 | |
949 Config read is loaded into the ui object passed | |
950 | |
951 This should be called before reading .hg/hgrc or the main repo | |
952 as that overrides config set in shared source""" | |
953 try: | |
954 with open(os.path.join(path, b".hg", b"requires"), "rb") as fp: | |
955 requirements = set(fp.read().splitlines()) | |
956 if not ( | |
957 requirementsmod.SHARESAFE_REQUIREMENT in requirements | |
958 and requirementsmod.SHARED_REQUIREMENT in requirements | |
959 ): | |
960 return | |
961 hgvfs = vfs.vfs(os.path.join(path, b".hg")) | |
962 sharedvfs = localrepo._getsharedvfs(hgvfs, requirements) | |
963 ui.readconfig(sharedvfs.join(b"hgrc"), path) | |
964 except IOError: | |
965 pass | |
966 | |
967 | |
942 def _getlocal(ui, rpath, wd=None): | 968 def _getlocal(ui, rpath, wd=None): |
943 """Return (path, local ui object) for the given target path. | 969 """Return (path, local ui object) for the given target path. |
944 | 970 |
945 Takes paths in [cwd]/.hg/hgrc into account." | 971 Takes paths in [cwd]/.hg/hgrc into account." |
946 """ | 972 """ |
957 if not path: | 983 if not path: |
958 lui = ui | 984 lui = ui |
959 else: | 985 else: |
960 lui = ui.copy() | 986 lui = ui.copy() |
961 if rcutil.use_repo_hgrc(): | 987 if rcutil.use_repo_hgrc(): |
988 _readsharedsourceconfig(lui, path) | |
962 lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path) | 989 lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path) |
963 | 990 |
964 if rpath: | 991 if rpath: |
965 path = lui.expandpath(rpath) | 992 path = lui.expandpath(rpath) |
966 lui = ui.copy() | 993 lui = ui.copy() |
967 if rcutil.use_repo_hgrc(): | 994 if rcutil.use_repo_hgrc(): |
995 _readsharedsourceconfig(lui, path) | |
968 lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path) | 996 lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path) |
969 | 997 |
970 return path, lui | 998 return path, lui |
971 | 999 |
972 | 1000 |