Show More
@@ -1,64 +1,62 | |||||
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 | osutil, |
|
14 | osutil, | |
15 | pycompat, |
|
15 | pycompat, | |
16 | util, |
|
16 | util, | |
17 | ) |
|
17 | ) | |
18 |
|
18 | |||
19 | if pycompat.osname == 'nt': |
|
19 | if pycompat.osname == 'nt': | |
20 | from . import scmwindows as scmplatform |
|
20 | from . import scmwindows as scmplatform | |
21 | else: |
|
21 | else: | |
22 | from . import scmposix as scmplatform |
|
22 | from . import scmposix as scmplatform | |
23 |
|
23 | |||
24 | systemrcpath = scmplatform.systemrcpath |
|
24 | systemrcpath = scmplatform.systemrcpath | |
25 | userrcpath = scmplatform.userrcpath |
|
25 | userrcpath = scmplatform.userrcpath | |
26 |
|
26 | |||
27 |
def |
|
27 | def defaultrcpath(): | |
28 | '''return default os-specific hgrc search path''' |
|
28 | '''return rc paths in default.d''' | |
29 | path = [] |
|
29 | path = [] | |
30 | defaultpath = os.path.join(util.datapath, 'default.d') |
|
30 | defaultpath = os.path.join(util.datapath, 'default.d') | |
31 | if os.path.isdir(defaultpath): |
|
31 | if os.path.isdir(defaultpath): | |
32 | for f, kind in osutil.listdir(defaultpath): |
|
32 | for f, kind in osutil.listdir(defaultpath): | |
33 | if f.endswith('.rc'): |
|
33 | if f.endswith('.rc'): | |
34 | path.append(os.path.join(defaultpath, f)) |
|
34 | path.append(os.path.join(defaultpath, f)) | |
35 | path.extend(systemrcpath()) |
|
|||
36 | path.extend(userrcpath()) |
|
|||
37 | path = [os.path.normpath(f) for f in path] |
|
|||
38 | return path |
|
35 | return path | |
39 |
|
36 | |||
40 | _rcpath = None |
|
37 | _rcpath = None | |
41 |
|
38 | |||
42 | def rcpath(): |
|
39 | def rcpath(): | |
43 | '''return hgrc search path. if env var HGRCPATH is set, use it. |
|
40 | '''return hgrc search path. if env var HGRCPATH is set, use it. | |
44 | for each item in path, if directory, use files ending in .rc, |
|
41 | for each item in path, if directory, use files ending in .rc, | |
45 | else use item. |
|
42 | else use item. | |
46 | make HGRCPATH empty to only look in .hg/hgrc of current repo. |
|
43 | make HGRCPATH empty to only look in .hg/hgrc of current repo. | |
47 | if no HGRCPATH, use default os-specific path.''' |
|
44 | if no HGRCPATH, use default os-specific path.''' | |
48 | global _rcpath |
|
45 | global _rcpath | |
49 | if _rcpath is None: |
|
46 | if _rcpath is None: | |
50 | if 'HGRCPATH' in encoding.environ: |
|
47 | if 'HGRCPATH' in encoding.environ: | |
51 | _rcpath = [] |
|
48 | _rcpath = [] | |
52 | for p in encoding.environ['HGRCPATH'].split(pycompat.ospathsep): |
|
49 | for p in encoding.environ['HGRCPATH'].split(pycompat.ospathsep): | |
53 | if not p: |
|
50 | if not p: | |
54 | continue |
|
51 | continue | |
55 | p = util.expandpath(p) |
|
52 | p = util.expandpath(p) | |
56 | if os.path.isdir(p): |
|
53 | if os.path.isdir(p): | |
57 | for f, kind in osutil.listdir(p): |
|
54 | for f, kind in osutil.listdir(p): | |
58 | if f.endswith('.rc'): |
|
55 | if f.endswith('.rc'): | |
59 | _rcpath.append(os.path.join(p, f)) |
|
56 | _rcpath.append(os.path.join(p, f)) | |
60 | else: |
|
57 | else: | |
61 | _rcpath.append(p) |
|
58 | _rcpath.append(p) | |
62 | else: |
|
59 | else: | |
63 | _rcpath = osrcpath() |
|
60 | paths = defaultrcpath() + systemrcpath() + userrcpath() | |
|
61 | _rcpath = pycompat.maplist(os.path.normpath, paths) | |||
64 | return _rcpath |
|
62 | return _rcpath |
General Comments 0
You need to be logged in to leave comments.
Login now