Mercurial > public > mercurial-scm > hg
annotate mercurial/configuration/rcutil.py @ 52426:22129ce9f86d
config: include the component level when returning them
This will be useful when modifying them.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 23 Oct 2024 01:32:33 +0200 |
parents | 3e79ca017157 |
children | 8c509a70b6fa |
rev | line source |
---|---|
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
1 # rcutil.py - utilities about config paths, special config sections etc. |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
2 # |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
3 # Copyright Mercurial Contributors |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
4 # |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
7 |
51859
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
8 from __future__ import annotations |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
9 |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
10 import os |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
11 |
52420
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
12 from typing import ( |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
13 Dict, |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
14 List, |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
15 Optional, |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
16 ) |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
17 |
52416
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51859
diff
changeset
|
18 from .. import ( |
52425
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52424
diff
changeset
|
19 configuration as conf_mod, |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
20 encoding, |
52423
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
21 localrepo, |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
22 pycompat, |
52423
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
23 requirements as requirementsmod, |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
24 util, |
52423
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
25 vfs, |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
26 ) |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
27 |
52416
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51859
diff
changeset
|
28 from ..utils import resourceutil |
43674
5be909dbe385
util: remove datapath and swith users over to resourceutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
43670
diff
changeset
|
29 |
34645 | 30 if pycompat.iswindows: |
52416
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51859
diff
changeset
|
31 from .. import scmwindows as scmplatform |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
32 else: |
52416
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51859
diff
changeset
|
33 from .. import scmposix as scmplatform |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
34 |
32078
bf5e13e38390
pager: use less as a fallback on Unix
Yuya Nishihara <yuya@tcha.org>
parents:
31954
diff
changeset
|
35 fallbackpager = scmplatform.fallbackpager |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
36 systemrcpath = scmplatform.systemrcpath |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
37 userrcpath = scmplatform.userrcpath |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
38 |
52425
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52424
diff
changeset
|
39 ComponentT = conf_mod.ComponentT |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52424
diff
changeset
|
40 ConfigItemT = conf_mod.ConfigItemT |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52424
diff
changeset
|
41 FileRCT = conf_mod.FileRCT |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52424
diff
changeset
|
42 ResourceIDT = conf_mod.ResourceIDT |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
42093
diff
changeset
|
43 |
52420
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
44 |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
45 def _expandrcpath(path: bytes) -> List[FileRCT]: |
31681
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
46 '''path could be a file or a directory. return a list of file paths''' |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
47 p = util.expandpath(path) |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
48 if os.path.isdir(p): |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
49 join = os.path.join |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
42093
diff
changeset
|
50 return sorted( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
51 join(p, f) for f, k in util.listdir(p) if f.endswith(b'.rc') |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
42093
diff
changeset
|
52 ) |
31681
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
53 return [p] |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
54 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
42093
diff
changeset
|
55 |
52420
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
56 def envrcitems(env: Optional[Dict[bytes, bytes]] = None) -> List[ConfigItemT]: |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44243
diff
changeset
|
57 """Return [(section, name, value, source)] config items. |
31684
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
58 |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
59 The config items are extracted from environment variables specified by env, |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
60 used to override systemrc, but not userrc. |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
61 |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
62 If env is not provided, encoding.environ will be used. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44243
diff
changeset
|
63 """ |
31684
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
64 if env is None: |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
65 env = encoding.environ |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
66 checklist = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
67 (b'EDITOR', b'ui', b'editor'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
68 (b'VISUAL', b'ui', b'editor'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
69 (b'PAGER', b'pager', b'pager'), |
31684
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
70 ] |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
71 result = [] |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
72 for envname, section, configname in checklist: |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
73 if envname not in env: |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
74 continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
75 result.append((section, configname, env[envname], b'$%s' % envname)) |
31684
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
76 return result |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
77 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
42093
diff
changeset
|
78 |
52420
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
79 def default_rc_resources() -> List[ResourceIDT]: |
44031
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
80 """return rc resource IDs in defaultrc""" |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
81 rsrcs = resourceutil.contents(b'mercurial.defaultrc') |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
82 return [ |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
83 (b'mercurial.defaultrc', r) |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
84 for r in sorted(rsrcs) |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
85 if resourceutil.is_resource(b'mercurial.defaultrc', r) |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
86 and r.endswith(b'.rc') |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
87 ] |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
88 |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
89 |
52420
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
90 def rccomponents() -> List[ComponentT]: |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44243
diff
changeset
|
91 """return an ordered [(type, obj)] about where to load configs. |
31683
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
92 |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
93 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
94 used. if $HGRCPATH is not set, the platform default will be used. |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
95 |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
96 if a directory is provided, *.rc files under it will be used. |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
97 |
44031
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
98 type could be either 'path', 'items' or 'resource'. If type is 'path', |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
99 obj is a string, and is the config file path. if type is 'items', obj is a |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
100 list of (section, name, value, source) that should fill the config directly. |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
101 If type is 'resource', obj is a tuple of (package name, resource name). |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44243
diff
changeset
|
102 """ |
52426
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
103 envrc = (conf_mod.LEVEL_ENV_OVERWRITE, b'items', envrcitems()) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
104 |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
105 _rccomponents = [] |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
106 comp = _rccomponents.append |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31684
diff
changeset
|
107 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
108 if b'HGRCPATH' in encoding.environ: |
31693 | 109 # assume HGRCPATH is all about user configs so environments can be |
110 # overridden. | |
52426
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
111 comp(envrc) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
112 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): |
31693 | 113 if not p: |
114 continue | |
52426
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
115 for p in _expandrcpath(p): |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
116 comp((conf_mod.LEVEL_ENV_OVERWRITE, b'path', p)) |
31693 | 117 else: |
52426
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
118 for r in default_rc_resources(): |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
119 comp((conf_mod.LEVEL_BUNDLED_RESOURCE, b'resource', r)) |
44031
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43918
diff
changeset
|
120 |
52426
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
121 for p in systemrcpath(): |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
122 comp((conf_mod.LEVEL_GLOBAL, b'path', os.path.normpath(p))) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
123 comp(envrc) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
124 for p in userrcpath(): |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
125 comp((conf_mod.LEVEL_USER, b'path', os.path.normpath(p))) |
31682
07d62fa518a4
rcutil: rename rcpath to rccomponents (API)
Jun Wu <quark@fb.com>
parents:
31681
diff
changeset
|
126 return _rccomponents |
31954
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
127 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
42093
diff
changeset
|
128 |
52423
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
129 def _shared_source_component(path: bytes) -> List[FileRCT]: |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
130 """if the current repository is shared one, this tries to read |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
131 .hg/hgrc of shared source if we are in share-safe mode |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
132 |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
133 This should be called before reading .hg/hgrc or the main repo |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
134 as that overrides config set in shared source""" |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
135 try: |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
136 with open(os.path.join(path, b".hg", b"requires"), "rb") as fp: |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
137 requirements = set(fp.read().splitlines()) |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
138 if not ( |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
139 requirementsmod.SHARESAFE_REQUIREMENT in requirements |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
140 and requirementsmod.SHARED_REQUIREMENT in requirements |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
141 ): |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
142 return [] |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
143 hgvfs = vfs.vfs(os.path.join(path, b".hg")) |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
144 sharedvfs = localrepo._getsharedvfs(hgvfs, requirements) |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
145 return [sharedvfs.join(b"hgrc")] |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
146 except IOError: |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
147 pass |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
148 return [] |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
149 |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
150 |
52424
e3b45916c375
config: return component from `repo_components`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52423
diff
changeset
|
151 def repo_components(repo_path: bytes) -> List[ComponentT]: |
52423
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
152 """return the list of config file to read for a repository""" |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
153 components = [] |
52426
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
154 comp = components.append |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
155 for p in _shared_source_component(repo_path): |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
156 comp((conf_mod.LEVEL_SHARED, b'path', p)) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
157 comp( |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
158 ( |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
159 conf_mod.LEVEL_LOCAL, |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
160 b'path', |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
161 os.path.join(repo_path, b".hg", b"hgrc"), |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
162 ) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
163 ) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
164 comp( |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
165 ( |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
166 conf_mod.LEVEL_NON_SHARED, |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
167 b'path', |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
168 os.path.join(repo_path, b".hg", b"hgrc-not-shared"), |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
169 ) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
170 ) |
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
171 return components |
52423
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
172 |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52420
diff
changeset
|
173 |
52420
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
174 def defaultpagerenv() -> Dict[bytes, bytes]: |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44243
diff
changeset
|
175 """return a dict of default environment variables and their values, |
31954
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
176 intended to be set before starting a pager. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44243
diff
changeset
|
177 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
178 return {b'LESS': b'FRX', b'LV': b'-c'} |
44243
238790674d69
config: add a function in `rcutil` to abstract HGRCSKIPREPO
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44032
diff
changeset
|
179 |
238790674d69
config: add a function in `rcutil` to abstract HGRCSKIPREPO
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44032
diff
changeset
|
180 |
52420
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52416
diff
changeset
|
181 def use_repo_hgrc() -> bool: |
44243
238790674d69
config: add a function in `rcutil` to abstract HGRCSKIPREPO
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44032
diff
changeset
|
182 """True if repositories `.hg/hgrc` config should be read""" |
238790674d69
config: add a function in `rcutil` to abstract HGRCSKIPREPO
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44032
diff
changeset
|
183 return b'HGRCSKIPREPO' not in encoding.environ |