Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/configuration/rcutil.py @ 52456:3e79ca017157
config: gather constant and type into the `__init__.py`
This will help using them in multiple files.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 23 Oct 2024 00:43:17 +0200 |
parents | e3b45916c375 |
children | 22129ce9f86d |
rev | line source |
---|---|
31684
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 |
51901
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
48966
diff
changeset
|
8 from __future__ import annotations |
31684
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 |
52451
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
12 from typing import ( |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
13 Dict, |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
14 List, |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
15 Optional, |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
16 ) |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
17 |
52447
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51901
diff
changeset
|
18 from .. import ( |
52456
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52455
diff
changeset
|
19 configuration as conf_mod, |
31684
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
20 encoding, |
52454
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
21 localrepo, |
31684
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
22 pycompat, |
52454
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
23 requirements as requirementsmod, |
31684
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
24 util, |
52454
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
25 vfs, |
31684
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 |
52447
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51901
diff
changeset
|
28 from ..utils import resourceutil |
43715
5be909dbe385
util: remove datapath and swith users over to resourceutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
43711
diff
changeset
|
29 |
34645 | 30 if pycompat.iswindows: |
52447
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51901
diff
changeset
|
31 from .. import scmwindows as scmplatform |
31684
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
32 else: |
52447
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51901
diff
changeset
|
33 from .. import scmposix as scmplatform |
31684
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 |
31684
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 |
52456
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52455
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:
52455
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:
52455
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:
52455
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 |
52451
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
44 |
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
45 def _expandrcpath(path: bytes) -> List[FileRCT]: |
31686
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31685
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:
31685
diff
changeset
|
47 p = util.expandpath(path) |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31685
diff
changeset
|
48 if os.path.isdir(p): |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31685
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 ) |
31686
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31685
diff
changeset
|
53 return [p] |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31685
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 |
52451
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
56 def envrcitems(env: Optional[Dict[bytes, bytes]] = None) -> List[ConfigItemT]: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44160
diff
changeset
|
57 """Return [(section, name, value, source)] config items. |
31689
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
58 |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
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:
31688
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:
31688
diff
changeset
|
61 |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
62 If env is not provided, encoding.environ will be used. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44160
diff
changeset
|
63 """ |
31689
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
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:
31688
diff
changeset
|
65 env = encoding.environ |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
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'), |
31689
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
70 ] |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
71 result = [] |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
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:
31688
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:
31688
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)) |
31689
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
76 return result |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31688
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 |
52451
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
79 def default_rc_resources() -> List[ResourceIDT]: |
44033
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43924
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:
43924
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:
43924
diff
changeset
|
82 return [ |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43924
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:
43924
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:
43924
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:
43924
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:
43924
diff
changeset
|
87 ] |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43924
diff
changeset
|
88 |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43924
diff
changeset
|
89 |
52451
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
90 def rccomponents() -> List[ComponentT]: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44160
diff
changeset
|
91 """return an ordered [(type, obj)] about where to load configs. |
31688
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31687
diff
changeset
|
92 |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31687
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:
31687
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:
31687
diff
changeset
|
95 |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31687
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:
31687
diff
changeset
|
97 |
44033
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43924
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:
43924
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:
43924
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:
43924
diff
changeset
|
101 If type is 'resource', obj is a tuple of (package name, resource name). |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44160
diff
changeset
|
102 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
103 envrc = (b'items', envrcitems()) |
31690
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31689
diff
changeset
|
104 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
105 if b'HGRCPATH' in encoding.environ: |
31698 | 106 # assume HGRCPATH is all about user configs so environments can be |
107 # overridden. | |
108 _rccomponents = [envrc] | |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
109 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): |
31698 | 110 if not p: |
111 continue | |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
112 _rccomponents.extend((b'path', p) for p in _expandrcpath(p)) |
31698 | 113 else: |
44033
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43924
diff
changeset
|
114 _rccomponents = [(b'resource', r) for r in default_rc_resources()] |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43924
diff
changeset
|
115 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
116 normpaths = lambda paths: [ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
117 (b'path', os.path.normpath(p)) for p in paths |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
118 ] |
44034
2d4cad94d08a
rcutil: drop the `defaultrcpath()` method (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
119 _rccomponents.extend(normpaths(systemrcpath())) |
31698 | 120 _rccomponents.append(envrc) |
31699
10d88dc7c010
rcutil: extract duplicated logic to a lambda
Jun Wu <quark@fb.com>
parents:
31698
diff
changeset
|
121 _rccomponents.extend(normpaths(userrcpath())) |
31687
07d62fa518a4
rcutil: rename rcpath to rccomponents (API)
Jun Wu <quark@fb.com>
parents:
31686
diff
changeset
|
122 return _rccomponents |
31954
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31699
diff
changeset
|
123 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
42093
diff
changeset
|
124 |
52454
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
125 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:
52451
diff
changeset
|
126 """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:
52451
diff
changeset
|
127 .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:
52451
diff
changeset
|
128 |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
129 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:
52451
diff
changeset
|
130 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:
52451
diff
changeset
|
131 try: |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
132 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:
52451
diff
changeset
|
133 requirements = set(fp.read().splitlines()) |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
134 if not ( |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
135 requirementsmod.SHARESAFE_REQUIREMENT in requirements |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
136 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:
52451
diff
changeset
|
137 ): |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
138 return [] |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
139 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:
52451
diff
changeset
|
140 sharedvfs = localrepo._getsharedvfs(hgvfs, requirements) |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
141 return [sharedvfs.join(b"hgrc")] |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
142 except IOError: |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
143 pass |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
144 return [] |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
145 |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
146 |
52455
e3b45916c375
config: return component from `repo_components`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52454
diff
changeset
|
147 def repo_components(repo_path: bytes) -> List[ComponentT]: |
52454
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
148 """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:
52451
diff
changeset
|
149 components = [] |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
150 components.extend(_shared_source_component(repo_path)) |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
151 components.append(os.path.join(repo_path, b".hg", b"hgrc")) |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
152 components.append(os.path.join(repo_path, b".hg", b"hgrc-not-shared")) |
52455
e3b45916c375
config: return component from `repo_components`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52454
diff
changeset
|
153 return [(b'path', c) for c in components] |
52454
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
154 |
0b791c90280a
repo-config: move rc component of repository inside `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52451
diff
changeset
|
155 |
52451
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
156 def defaultpagerenv() -> Dict[bytes, bytes]: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44160
diff
changeset
|
157 """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:
31699
diff
changeset
|
158 intended to be set before starting a pager. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44160
diff
changeset
|
159 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
160 return {b'LESS': b'FRX', b'LV': b'-c'} |
44160
238790674d69
config: add a function in `rcutil` to abstract HGRCSKIPREPO
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
161 |
238790674d69
config: add a function in `rcutil` to abstract HGRCSKIPREPO
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
162 |
52451
91f22b89ea05
config: type `rcutil`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
163 def use_repo_hgrc() -> bool: |
44160
238790674d69
config: add a function in `rcutil` to abstract HGRCSKIPREPO
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
164 """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:
44034
diff
changeset
|
165 return b'HGRCSKIPREPO' not in encoding.environ |