Show More
1 | NO CONTENT: file renamed from mercurial/default.d/mergetools.rc to mercurial/defaultrc/mergetools.rc |
|
NO CONTENT: file renamed from mercurial/default.d/mergetools.rc to mercurial/defaultrc/mergetools.rc |
@@ -1,107 +1,107 b'' | |||||
1 | # rcutil.py - utilities about config paths, special config sections etc. |
|
1 | # rcutil.py - utilities about config paths, special config sections etc. | |
2 | # |
|
2 | # | |
3 | # Copyright Mercurial Contributors |
|
3 | # Copyright Mercurial Contributors | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import os |
|
10 | import os | |
11 |
|
11 | |||
12 | from . import ( |
|
12 | from . import ( | |
13 | encoding, |
|
13 | encoding, | |
14 | pycompat, |
|
14 | pycompat, | |
15 | util, |
|
15 | util, | |
16 | ) |
|
16 | ) | |
17 |
|
17 | |||
18 | if pycompat.iswindows: |
|
18 | if pycompat.iswindows: | |
19 | from . import scmwindows as scmplatform |
|
19 | from . import scmwindows as scmplatform | |
20 | else: |
|
20 | else: | |
21 | from . import scmposix as scmplatform |
|
21 | from . import scmposix as scmplatform | |
22 |
|
22 | |||
23 | fallbackpager = scmplatform.fallbackpager |
|
23 | fallbackpager = scmplatform.fallbackpager | |
24 | systemrcpath = scmplatform.systemrcpath |
|
24 | systemrcpath = scmplatform.systemrcpath | |
25 | userrcpath = scmplatform.userrcpath |
|
25 | userrcpath = scmplatform.userrcpath | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | def _expandrcpath(path): |
|
28 | def _expandrcpath(path): | |
29 | '''path could be a file or a directory. return a list of file paths''' |
|
29 | '''path could be a file or a directory. return a list of file paths''' | |
30 | p = util.expandpath(path) |
|
30 | p = util.expandpath(path) | |
31 | if os.path.isdir(p): |
|
31 | if os.path.isdir(p): | |
32 | join = os.path.join |
|
32 | join = os.path.join | |
33 | return sorted( |
|
33 | return sorted( | |
34 | join(p, f) for f, k in util.listdir(p) if f.endswith(b'.rc') |
|
34 | join(p, f) for f, k in util.listdir(p) if f.endswith(b'.rc') | |
35 | ) |
|
35 | ) | |
36 | return [p] |
|
36 | return [p] | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | def envrcitems(env=None): |
|
39 | def envrcitems(env=None): | |
40 | '''Return [(section, name, value, source)] config items. |
|
40 | '''Return [(section, name, value, source)] config items. | |
41 |
|
41 | |||
42 | The config items are extracted from environment variables specified by env, |
|
42 | The config items are extracted from environment variables specified by env, | |
43 | used to override systemrc, but not userrc. |
|
43 | used to override systemrc, but not userrc. | |
44 |
|
44 | |||
45 | If env is not provided, encoding.environ will be used. |
|
45 | If env is not provided, encoding.environ will be used. | |
46 | ''' |
|
46 | ''' | |
47 | if env is None: |
|
47 | if env is None: | |
48 | env = encoding.environ |
|
48 | env = encoding.environ | |
49 | checklist = [ |
|
49 | checklist = [ | |
50 | (b'EDITOR', b'ui', b'editor'), |
|
50 | (b'EDITOR', b'ui', b'editor'), | |
51 | (b'VISUAL', b'ui', b'editor'), |
|
51 | (b'VISUAL', b'ui', b'editor'), | |
52 | (b'PAGER', b'pager', b'pager'), |
|
52 | (b'PAGER', b'pager', b'pager'), | |
53 | ] |
|
53 | ] | |
54 | result = [] |
|
54 | result = [] | |
55 | for envname, section, configname in checklist: |
|
55 | for envname, section, configname in checklist: | |
56 | if envname not in env: |
|
56 | if envname not in env: | |
57 | continue |
|
57 | continue | |
58 | result.append((section, configname, env[envname], b'$%s' % envname)) |
|
58 | result.append((section, configname, env[envname], b'$%s' % envname)) | |
59 | return result |
|
59 | return result | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | def defaultrcpath(): |
|
62 | def defaultrcpath(): | |
63 |
'''return rc paths in default |
|
63 | '''return rc paths in defaultrc''' | |
64 | path = [] |
|
64 | path = [] | |
65 |
defaultpath = os.path.join(util.datapath, b'default |
|
65 | defaultpath = os.path.join(util.datapath, b'defaultrc') | |
66 | if os.path.isdir(defaultpath): |
|
66 | if os.path.isdir(defaultpath): | |
67 | path = _expandrcpath(defaultpath) |
|
67 | path = _expandrcpath(defaultpath) | |
68 | return path |
|
68 | return path | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | def rccomponents(): |
|
71 | def rccomponents(): | |
72 | '''return an ordered [(type, obj)] about where to load configs. |
|
72 | '''return an ordered [(type, obj)] about where to load configs. | |
73 |
|
73 | |||
74 | respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is |
|
74 | respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is | |
75 | used. if $HGRCPATH is not set, the platform default will be used. |
|
75 | used. if $HGRCPATH is not set, the platform default will be used. | |
76 |
|
76 | |||
77 | if a directory is provided, *.rc files under it will be used. |
|
77 | if a directory is provided, *.rc files under it will be used. | |
78 |
|
78 | |||
79 | type could be either 'path' or 'items', if type is 'path', obj is a string, |
|
79 | type could be either 'path' or 'items', if type is 'path', obj is a string, | |
80 | and is the config file path. if type is 'items', obj is a list of (section, |
|
80 | and is the config file path. if type is 'items', obj is a list of (section, | |
81 | name, value, source) that should fill the config directly. |
|
81 | name, value, source) that should fill the config directly. | |
82 | ''' |
|
82 | ''' | |
83 | envrc = (b'items', envrcitems()) |
|
83 | envrc = (b'items', envrcitems()) | |
84 |
|
84 | |||
85 | if b'HGRCPATH' in encoding.environ: |
|
85 | if b'HGRCPATH' in encoding.environ: | |
86 | # assume HGRCPATH is all about user configs so environments can be |
|
86 | # assume HGRCPATH is all about user configs so environments can be | |
87 | # overridden. |
|
87 | # overridden. | |
88 | _rccomponents = [envrc] |
|
88 | _rccomponents = [envrc] | |
89 | for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): |
|
89 | for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): | |
90 | if not p: |
|
90 | if not p: | |
91 | continue |
|
91 | continue | |
92 | _rccomponents.extend((b'path', p) for p in _expandrcpath(p)) |
|
92 | _rccomponents.extend((b'path', p) for p in _expandrcpath(p)) | |
93 | else: |
|
93 | else: | |
94 | normpaths = lambda paths: [ |
|
94 | normpaths = lambda paths: [ | |
95 | (b'path', os.path.normpath(p)) for p in paths |
|
95 | (b'path', os.path.normpath(p)) for p in paths | |
96 | ] |
|
96 | ] | |
97 | _rccomponents = normpaths(defaultrcpath() + systemrcpath()) |
|
97 | _rccomponents = normpaths(defaultrcpath() + systemrcpath()) | |
98 | _rccomponents.append(envrc) |
|
98 | _rccomponents.append(envrc) | |
99 | _rccomponents.extend(normpaths(userrcpath())) |
|
99 | _rccomponents.extend(normpaths(userrcpath())) | |
100 | return _rccomponents |
|
100 | return _rccomponents | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | def defaultpagerenv(): |
|
103 | def defaultpagerenv(): | |
104 | '''return a dict of default environment variables and their values, |
|
104 | '''return a dict of default environment variables and their values, | |
105 | intended to be set before starting a pager. |
|
105 | intended to be set before starting a pager. | |
106 | ''' |
|
106 | ''' | |
107 | return {b'LESS': b'FRX', b'LV': b'-c'} |
|
107 | return {b'LESS': b'FRX', b'LV': b'-c'} |
General Comments 0
You need to be logged in to leave comments.
Login now