Show More
@@ -9,6 +9,14 from __future__ import annotations | |||||
9 |
|
9 | |||
10 | import os |
|
10 | import os | |
11 |
|
11 | |||
|
12 | from typing import ( | |||
|
13 | Dict, | |||
|
14 | List, | |||
|
15 | Optional, | |||
|
16 | Tuple, | |||
|
17 | Union, | |||
|
18 | ) | |||
|
19 | ||||
12 | from .. import ( |
|
20 | from .. import ( | |
13 | encoding, |
|
21 | encoding, | |
14 | pycompat, |
|
22 | pycompat, | |
@@ -26,8 +34,20 fallbackpager = scmplatform.fallbackpage | |||||
26 | systemrcpath = scmplatform.systemrcpath |
|
34 | systemrcpath = scmplatform.systemrcpath | |
27 | userrcpath = scmplatform.userrcpath |
|
35 | userrcpath = scmplatform.userrcpath | |
28 |
|
36 | |||
|
37 | ConfigItemT = Tuple[bytes, bytes, bytes, bytes] | |||
|
38 | ResourceIDT = Tuple[bytes, bytes] | |||
|
39 | FileRCT = bytes | |||
|
40 | ComponentT = Tuple[ | |||
|
41 | bytes, | |||
|
42 | Union[ | |||
|
43 | List[ConfigItemT], | |||
|
44 | FileRCT, | |||
|
45 | ResourceIDT, | |||
|
46 | ], | |||
|
47 | ] | |||
29 |
|
48 | |||
30 | def _expandrcpath(path): |
|
49 | ||
|
50 | def _expandrcpath(path: bytes) -> List[FileRCT]: | |||
31 | '''path could be a file or a directory. return a list of file paths''' |
|
51 | '''path could be a file or a directory. return a list of file paths''' | |
32 | p = util.expandpath(path) |
|
52 | p = util.expandpath(path) | |
33 | if os.path.isdir(p): |
|
53 | if os.path.isdir(p): | |
@@ -38,7 +58,7 def _expandrcpath(path): | |||||
38 | return [p] |
|
58 | return [p] | |
39 |
|
59 | |||
40 |
|
60 | |||
41 | def envrcitems(env=None): |
|
61 | def envrcitems(env: Optional[Dict[bytes, bytes]] = None) -> List[ConfigItemT]: | |
42 | """Return [(section, name, value, source)] config items. |
|
62 | """Return [(section, name, value, source)] config items. | |
43 |
|
63 | |||
44 | The config items are extracted from environment variables specified by env, |
|
64 | The config items are extracted from environment variables specified by env, | |
@@ -61,7 +81,7 def envrcitems(env=None): | |||||
61 | return result |
|
81 | return result | |
62 |
|
82 | |||
63 |
|
83 | |||
64 | def default_rc_resources(): |
|
84 | def default_rc_resources() -> List[ResourceIDT]: | |
65 | """return rc resource IDs in defaultrc""" |
|
85 | """return rc resource IDs in defaultrc""" | |
66 | rsrcs = resourceutil.contents(b'mercurial.defaultrc') |
|
86 | rsrcs = resourceutil.contents(b'mercurial.defaultrc') | |
67 | return [ |
|
87 | return [ | |
@@ -72,7 +92,7 def default_rc_resources(): | |||||
72 | ] |
|
92 | ] | |
73 |
|
93 | |||
74 |
|
94 | |||
75 | def rccomponents(): |
|
95 | def rccomponents() -> List[ComponentT]: | |
76 | """return an ordered [(type, obj)] about where to load configs. |
|
96 | """return an ordered [(type, obj)] about where to load configs. | |
77 |
|
97 | |||
78 | respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is |
|
98 | respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is | |
@@ -107,13 +127,13 def rccomponents(): | |||||
107 | return _rccomponents |
|
127 | return _rccomponents | |
108 |
|
128 | |||
109 |
|
129 | |||
110 | def defaultpagerenv(): |
|
130 | def defaultpagerenv() -> Dict[bytes, bytes]: | |
111 | """return a dict of default environment variables and their values, |
|
131 | """return a dict of default environment variables and their values, | |
112 | intended to be set before starting a pager. |
|
132 | intended to be set before starting a pager. | |
113 | """ |
|
133 | """ | |
114 | return {b'LESS': b'FRX', b'LV': b'-c'} |
|
134 | return {b'LESS': b'FRX', b'LV': b'-c'} | |
115 |
|
135 | |||
116 |
|
136 | |||
117 | def use_repo_hgrc(): |
|
137 | def use_repo_hgrc() -> bool: | |
118 | """True if repositories `.hg/hgrc` config should be read""" |
|
138 | """True if repositories `.hg/hgrc` config should be read""" | |
119 | return b'HGRCSKIPREPO' not in encoding.environ |
|
139 | return b'HGRCSKIPREPO' not in encoding.environ |
General Comments 0
You need to be logged in to leave comments.
Login now