comparison mercurial/rcutil.py @ 31684:0be96ac9199a

rcutil: add a method to convert environment variables to config items Handling config and environ priorities has been messy. Partially because we don't have config layers - you either get all configs (sys + user), or none. Ideally, environ like $EDITOR, $PAGER should be able to override the system configs "ui.editor", "pager.pager". This patch provides the ability to convert them into config items, so they can be inserted into the middle config layer between system rc and user rc.
author Jun Wu <quark@fb.com>
date Sun, 26 Mar 2017 21:27:02 -0700
parents 00e569a2da97
children d83e51654c8a
comparison
equal deleted inserted replaced
31683:00e569a2da97 31684:0be96ac9199a
29 p = util.expandpath(path) 29 p = util.expandpath(path)
30 if os.path.isdir(p): 30 if os.path.isdir(p):
31 join = os.path.join 31 join = os.path.join
32 return [join(p, f) for f, k in osutil.listdir(p) if f.endswith('.rc')] 32 return [join(p, f) for f, k in osutil.listdir(p) if f.endswith('.rc')]
33 return [p] 33 return [p]
34
35 def envrcitems(env=None):
36 '''Return [(section, name, value, source)] config items.
37
38 The config items are extracted from environment variables specified by env,
39 used to override systemrc, but not userrc.
40
41 If env is not provided, encoding.environ will be used.
42 '''
43 if env is None:
44 env = encoding.environ
45 checklist = [
46 ('EDITOR', 'ui', 'editor'),
47 ('VISUAL', 'ui', 'editor'),
48 ('PAGER', 'pager', 'pager'),
49 ]
50 result = []
51 for envname, section, configname in checklist:
52 if envname not in env:
53 continue
54 result.append((section, configname, env[envname], '$%s' % envname))
55 return result
34 56
35 def defaultrcpath(): 57 def defaultrcpath():
36 '''return rc paths in default.d''' 58 '''return rc paths in default.d'''
37 path = [] 59 path = []
38 defaultpath = os.path.join(util.datapath, 'default.d') 60 defaultpath = os.path.join(util.datapath, 'default.d')