##// END OF EJS Templates
config: don't read the same config file twice...
Mads Kiilerich -
r22583:23c995ed default
parent child Browse files
Show More
@@ -1,32 +1,33
1 1 import sys, os
2 2 import osutil
3 3
4 4 def _rcfiles(path):
5 5 rcs = [os.path.join(path, 'hgrc')]
6 6 rcdir = os.path.join(path, 'hgrc.d')
7 7 try:
8 8 rcs.extend([os.path.join(rcdir, f)
9 9 for f, kind in osutil.listdir(rcdir)
10 10 if f.endswith(".rc")])
11 11 except OSError:
12 12 pass
13 13 return rcs
14 14
15 15 def systemrcpath():
16 16 path = []
17 17 if sys.platform == 'plan9':
18 18 root = 'lib/mercurial'
19 19 else:
20 20 root = 'etc/mercurial'
21 21 # old mod_python does not set sys.argv
22 22 if len(getattr(sys, 'argv', [])) > 0:
23 23 p = os.path.dirname(os.path.dirname(sys.argv[0]))
24 path.extend(_rcfiles(os.path.join(p, root)))
24 if p != '/':
25 path.extend(_rcfiles(os.path.join(p, root)))
25 26 path.extend(_rcfiles('/' + root))
26 27 return path
27 28
28 29 def userrcpath():
29 30 if sys.platform == 'plan9':
30 31 return [os.environ['home'] + '/lib/hgrc']
31 32 else:
32 33 return [os.path.expanduser('~/.hgrc')]
@@ -1,46 +1,46
1 1 import os
2 2 import osutil
3 3 import util
4 4 import _winreg
5 5
6 6 def systemrcpath():
7 7 '''return default os-specific hgrc search path'''
8 8 rcpath = []
9 9 filename = util.executablepath()
10 10 # Use mercurial.ini found in directory with hg.exe
11 11 progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
12 12 if os.path.isfile(progrc):
13 13 rcpath.append(progrc)
14 14 return rcpath
15 15 # Use hgrc.d found in directory with hg.exe
16 16 progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
17 17 if os.path.isdir(progrcd):
18 18 for f, kind in osutil.listdir(progrcd):
19 19 if f.endswith('.rc'):
20 20 rcpath.append(os.path.join(progrcd, f))
21 21 return rcpath
22 22 # else look for a system rcpath in the registry
23 23 value = util.lookupreg('SOFTWARE\\Mercurial', None,
24 24 _winreg.HKEY_LOCAL_MACHINE)
25 25 if not isinstance(value, str) or not value:
26 26 return rcpath
27 27 value = util.localpath(value)
28 28 for p in value.split(os.pathsep):
29 29 if p.lower().endswith('mercurial.ini'):
30 30 rcpath.append(p)
31 31 elif os.path.isdir(p):
32 32 for f, kind in osutil.listdir(p):
33 33 if f.endswith('.rc'):
34 34 rcpath.append(os.path.join(p, f))
35 35 return rcpath
36 36
37 37 def userrcpath():
38 38 '''return os-specific hgrc search path to the user dir'''
39 39 home = os.path.expanduser('~')
40 40 path = [os.path.join(home, 'mercurial.ini'),
41 41 os.path.join(home, '.hgrc')]
42 42 userprofile = os.environ.get('USERPROFILE')
43 if userprofile:
43 if userprofile and userprofile != home:
44 44 path.append(os.path.join(userprofile, 'mercurial.ini'))
45 45 path.append(os.path.join(userprofile, '.hgrc'))
46 46 return path
General Comments 0
You need to be logged in to leave comments. Login now