comparison mercurial/rcutil.py @ 31680:448889f9a36c

rcutil: split osrcpath to return default.d paths (API) After this change, there are 3 rcpath functions: - defaultrcpath - systemrcpath - userrcpath This will allow us to insert another config layer in the middle.
author Jun Wu <quark@fb.com>
date Sun, 26 Mar 2017 20:21:32 -0700
parents 0f8ba0bc1154
children 294728f2a908
comparison
equal deleted inserted replaced
31679:0f8ba0bc1154 31680:448889f9a36c
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 osrcpath(): 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():
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