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('.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): |
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 ('EDITOR', 'ui', 'editor'), |
50 (b'EDITOR', b'ui', b'editor'), |
51 ('VISUAL', 'ui', 'editor'), |
51 (b'VISUAL', b'ui', b'editor'), |
52 ('PAGER', 'pager', '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], '$%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.d''' |
63 '''return rc paths in default.d''' |
64 path = [] |
64 path = [] |
65 defaultpath = os.path.join(util.datapath, 'default.d') |
65 defaultpath = os.path.join(util.datapath, b'default.d') |
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 |
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 = ('items', envrcitems()) |
83 envrc = (b'items', envrcitems()) |
84 |
84 |
85 if '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['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(('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: [('path', os.path.normpath(p)) for p in paths] |
94 normpaths = lambda paths: [ |
|
95 (b'path', os.path.normpath(p)) for p in paths |
|
96 ] |
95 _rccomponents = normpaths(defaultrcpath() + systemrcpath()) |
97 _rccomponents = normpaths(defaultrcpath() + systemrcpath()) |
96 _rccomponents.append(envrc) |
98 _rccomponents.append(envrc) |
97 _rccomponents.extend(normpaths(userrcpath())) |
99 _rccomponents.extend(normpaths(userrcpath())) |
98 return _rccomponents |
100 return _rccomponents |
99 |
101 |
100 |
102 |
101 def defaultpagerenv(): |
103 def defaultpagerenv(): |
102 '''return a dict of default environment variables and their values, |
104 '''return a dict of default environment variables and their values, |
103 intended to be set before starting a pager. |
105 intended to be set before starting a pager. |
104 ''' |
106 ''' |
105 return {'LESS': 'FRX', 'LV': '-c'} |
107 return {b'LESS': b'FRX', b'LV': b'-c'} |