Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 52423:0b791c90280a
repo-config: move rc component of repository inside `rcutil`
This gather logic about where to find config file in the same location.
This also reduce the amount of logic we do in dispatch.py which is a win in
itself.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 22 Oct 2024 23:42:15 +0200 |
parents | 8a52fd131d3b |
children | e3b45916c375 |
comparison
equal
deleted
inserted
replaced
52422:8a52fd131d3b | 52423:0b791c90280a |
---|---|
32 extensions, | 32 extensions, |
33 fancyopts, | 33 fancyopts, |
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 |
49 from .utils import ( | 46 from .utils import ( |
50 procutil, | 47 procutil, |
927 ) | 924 ) |
928 raise | 925 raise |
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 |
958 Takes paths in [cwd]/.hg/hgrc into account." | 932 Takes paths in [cwd]/.hg/hgrc into account." |
959 """ | 933 """ |
978 if not path: | 952 if not path: |
979 lui = ui | 953 lui = ui |
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 |
989 # local repository. So we had to read the local config first even if it | 962 # local repository. So we had to read the local config first even if it |
990 # get overriden here. | 963 # get overriden here. |
991 path_obj = urlutil.get_clone_path_obj(lui, rpath) | 964 path_obj = urlutil.get_clone_path_obj(lui, rpath) |
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) |
1001 | 973 |
1002 return path, lui | 974 return path, lui |