##// END OF EJS Templates
repo-config: move rc component of repository inside `rcutil`...
marmoute -
r53320:0b791c90 default
parent child Browse files
Show More
@@ -19,8 +19,11 from typing import (
19
19
20 from .. import (
20 from .. import (
21 encoding,
21 encoding,
22 localrepo,
22 pycompat,
23 pycompat,
24 requirements as requirementsmod,
23 util,
25 util,
26 vfs,
24 )
27 )
25
28
26 from ..utils import resourceutil
29 from ..utils import resourceutil
@@ -127,6 +130,37 def rccomponents() -> List[ComponentT]:
127 return _rccomponents
130 return _rccomponents
128
131
129
132
133 def _shared_source_component(path: bytes) -> List[FileRCT]:
134 """if the current repository is shared one, this tries to read
135 .hg/hgrc of shared source if we are in share-safe mode
136
137 This should be called before reading .hg/hgrc or the main repo
138 as that overrides config set in shared source"""
139 try:
140 with open(os.path.join(path, b".hg", b"requires"), "rb") as fp:
141 requirements = set(fp.read().splitlines())
142 if not (
143 requirementsmod.SHARESAFE_REQUIREMENT in requirements
144 and requirementsmod.SHARED_REQUIREMENT in requirements
145 ):
146 return []
147 hgvfs = vfs.vfs(os.path.join(path, b".hg"))
148 sharedvfs = localrepo._getsharedvfs(hgvfs, requirements)
149 return [sharedvfs.join(b"hgrc")]
150 except IOError:
151 pass
152 return []
153
154
155 def repo_components(repo_path: bytes) -> List[FileRCT]:
156 """return the list of config file to read for a repository"""
157 components = []
158 components.extend(_shared_source_component(repo_path))
159 components.append(os.path.join(repo_path, b".hg", b"hgrc"))
160 components.append(os.path.join(repo_path, b".hg", b"hgrc-not-shared"))
161 return components
162
163
130 def defaultpagerenv() -> Dict[bytes, bytes]:
164 def defaultpagerenv() -> Dict[bytes, bytes]:
131 """return a dict of default environment variables and their values,
165 """return a dict of default environment variables and their values,
132 intended to be set before starting a pager.
166 intended to be set before starting a pager.
@@ -34,15 +34,12 from . import (
34 help,
34 help,
35 hg,
35 hg,
36 hook,
36 hook,
37 localrepo,
38 profiling,
37 profiling,
39 pycompat,
38 pycompat,
40 registrar,
39 registrar,
41 requirements as requirementsmod,
42 scmutil,
40 scmutil,
43 ui as uimod,
41 ui as uimod,
44 util,
42 util,
45 vfs,
46 )
43 )
47
44
48 from .configuration import rcutil
45 from .configuration import rcutil
@@ -929,29 +926,6 def runcommand(lui, repo, cmd, fullargs,
929 return ret
926 return ret
930
927
931
928
932 def _readsharedsourceconfig(ui, path):
933 """if the current repository is shared one, this tries to read
934 .hg/hgrc of shared source if we are in share-safe mode
935
936 Config read is loaded into the ui object passed
937
938 This should be called before reading .hg/hgrc or the main repo
939 as that overrides config set in shared source"""
940 try:
941 with open(os.path.join(path, b".hg", b"requires"), "rb") as fp:
942 requirements = set(fp.read().splitlines())
943 if not (
944 requirementsmod.SHARESAFE_REQUIREMENT in requirements
945 and requirementsmod.SHARED_REQUIREMENT in requirements
946 ):
947 return
948 hgvfs = vfs.vfs(os.path.join(path, b".hg"))
949 sharedvfs = localrepo._getsharedvfs(hgvfs, requirements)
950 ui.readconfig(sharedvfs.join(b"hgrc"), root=path)
951 except IOError:
952 pass
953
954
955 def _getlocal(ui, rpath, wd=None):
929 def _getlocal(ui, rpath, wd=None):
956 """Return (path, local ui object) for the given target path.
930 """Return (path, local ui object) for the given target path.
957
931
@@ -980,9 +954,8 def _getlocal(ui, rpath, wd=None):
980 else:
954 else:
981 lui = ui.copy()
955 lui = ui.copy()
982 if rcutil.use_repo_hgrc():
956 if rcutil.use_repo_hgrc():
983 _readsharedsourceconfig(lui, path)
957 for rc_path in rcutil.repo_components(path):
984 lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path)
958 lui.readconfig(rc_path, root=path)
985 lui.readconfig(os.path.join(path, b".hg", b"hgrc-not-shared"), path)
986
959
987 if rpath:
960 if rpath:
988 # the specified path, might be defined in the [paths] section of the
961 # the specified path, might be defined in the [paths] section of the
@@ -992,9 +965,8 def _getlocal(ui, rpath, wd=None):
992 path = path_obj.rawloc
965 path = path_obj.rawloc
993 lui = ui.copy()
966 lui = ui.copy()
994 if rcutil.use_repo_hgrc():
967 if rcutil.use_repo_hgrc():
995 _readsharedsourceconfig(lui, path)
968 for rc_path in rcutil.repo_components(path):
996 lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path)
969 lui.readconfig(rc_path, root=path)
997 lui.readconfig(os.path.join(path, b".hg", b"hgrc-not-shared"), path)
998
970
999 if oldcwd:
971 if oldcwd:
1000 os.chdir(oldcwd)
972 os.chdir(oldcwd)
General Comments 0
You need to be logged in to leave comments. Login now