py3: use pycompat.sysargv in scmposix.systemrcpath()
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 21 Nov 2016 15:26:47 +0530
changeset 30476 5b0baa9f3362
parent 30475 2add671bf55b
child 30477 7f2b18c34c02
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.
mercurial/scmposix.py
--- a/mercurial/scmposix.py	Sun Nov 20 13:50:45 2016 -0800
+++ b/mercurial/scmposix.py	Mon Nov 21 15:26:47 2016 +0530
@@ -9,6 +9,7 @@
 from . import (
     encoding,
     osutil,
+    pycompat,
 )
 
 def _rcfiles(path):
@@ -30,7 +31,7 @@
         root = 'etc/mercurial'
     # old mod_python does not set sys.argv
     if len(getattr(sys, 'argv', [])) > 0:
-        p = os.path.dirname(os.path.dirname(sys.argv[0]))
+        p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
         if p != '/':
             path.extend(_rcfiles(os.path.join(p, root)))
     path.extend(_rcfiles('/' + root))