Patchwork [1,of,3] py3: use pycompat.sysargv in scmposix.systemrcpath()

login
register
mail settings
Submitter Pulkit Goyal
Date Nov. 21, 2016, 10:56 a.m.
Message ID <05e95034383d926a46bf.1479725764@pulkit-goyal>
Download mbox | patch
Permalink /patch/17664/
State Accepted
Headers show

Comments

Pulkit Goyal - Nov. 21, 2016, 10:56 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1479722207 -19800
#      Mon Nov 21 15:26:47 2016 +0530
# Node ID 05e95034383d926a46bf5dd72182a0f4ca8d6c62
# Parent  da2be40326918d65953cd6c44babc90fd3292346
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.

Patch

diff -r da2be4032691 -r 05e95034383d mercurial/scmposix.py
--- a/mercurial/scmposix.py	Sun Nov 20 16:56:21 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))