Patchwork [3,of,7] py3: make scmpoxis.systemrcpath() return bytes

login
register
mail settings
Submitter Pulkit Goyal
Date Nov. 2, 2016, 10:15 p.m.
Message ID <0b45aa3edc2c725eaa82.1478124917@pulkit-goyal>
Download mbox | patch
Permalink /patch/17293/
State Not Applicable
Headers show

Comments

Pulkit Goyal - Nov. 2, 2016, 10:15 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1478119178 -19800
#      Thu Nov 03 02:09:38 2016 +0530
# Node ID 0b45aa3edc2c725eaa82dde9df39a17eb8585ff0
# Parent  f87503dd04ee704ed0c13d6ec9673fe7d946fd6c
py3: make scmpoxis.systemrcpath() return bytes

The variable `p` is a str on Python 3 which is not bytes. We should convert
it to bytes because
1. root is bytes and we want the final output in bytes
2. to make the if condition works fine because in py3 its p != b'/'

So even if p is '/' but left as a str on py3, will make the condition false.
This patch ensures that scmposix.systemrcpath() return bytes and also
scmposix._rcfiles() returns and accepts bytes. The later is used in
scmposix.py only.

Patch

diff -r f87503dd04ee -r 0b45aa3edc2c mercurial/scmposix.py
--- a/mercurial/scmposix.py	Thu Nov 03 01:55:44 2016 +0530
+++ b/mercurial/scmposix.py	Thu Nov 03 02:09:38 2016 +0530
@@ -27,6 +27,8 @@ 
     # old mod_python does not set sys.argv
     if len(getattr(sys, 'argv', [])) > 0:
         p = os.path.dirname(os.path.dirname(sys.argv[0]))
+        if not isinstance(p, bytes):
+            p = p.encode('utf-8')
         if p != '/':
             path.extend(_rcfiles(os.path.join(p, root)))
     path.extend(_rcfiles('/' + root))