comparison mercurial/scmposix.py @ 30467:5b0baa9f3362

py3: use pycompat.sysargv in scmposix.systemrcpath() sys.argv returns unicodes on Python 3. We have pycompat.sysargv which returns bytes encoded using os.fsencode(). After this patch scmposix.systemrcpath() returns bytes in Python 3 world. This change is also a part of making `hg version` run in Python 3.
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 21 Nov 2016 15:26:47 +0530
parents 365812902904
children 16b5df5792a8
comparison
equal deleted inserted replaced
30466:2add671bf55b 30467:5b0baa9f3362
7 import sys 7 import sys
8 8
9 from . import ( 9 from . import (
10 encoding, 10 encoding,
11 osutil, 11 osutil,
12 pycompat,
12 ) 13 )
13 14
14 def _rcfiles(path): 15 def _rcfiles(path):
15 rcs = [os.path.join(path, 'hgrc')] 16 rcs = [os.path.join(path, 'hgrc')]
16 rcdir = os.path.join(path, 'hgrc.d') 17 rcdir = os.path.join(path, 'hgrc.d')
28 root = 'lib/mercurial' 29 root = 'lib/mercurial'
29 else: 30 else:
30 root = 'etc/mercurial' 31 root = 'etc/mercurial'
31 # old mod_python does not set sys.argv 32 # old mod_python does not set sys.argv
32 if len(getattr(sys, 'argv', [])) > 0: 33 if len(getattr(sys, 'argv', [])) > 0:
33 p = os.path.dirname(os.path.dirname(sys.argv[0])) 34 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
34 if p != '/': 35 if p != '/':
35 path.extend(_rcfiles(os.path.join(p, root))) 36 path.extend(_rcfiles(os.path.join(p, root)))
36 path.extend(_rcfiles('/' + root)) 37 path.extend(_rcfiles('/' + root))
37 return path 38 return path
38 39