Patchwork [1,of,7] py3: make util.datapath a bytes variable

mail settings
Submitter Pulkit Goyal
Date Nov. 2, 2016, 10:15 p.m.
Message ID <e23132d2c665e7886460.1478124915@pulkit-goyal>
Download mbox | patch
Permalink /patch/17291/
State Not Applicable
Headers show


Pulkit Goyal - Nov. 2, 2016, 10:15 p.m.
# HG changeset patch
# User Pulkit Goyal <>
# Date 1478113113 -19800
#      Thu Nov 03 00:28:33 2016 +0530
# Node ID e23132d2c665e788646000318a9880bf9c5a177f
# Parent  bb586966818986131068280bfd95fc96fbdaaa0d
py3: make util.datapath a bytes variable

Fixing things when a warning or error comes up was a good approach, but that
won't work in long time, because we will be having all the errors fixed
but no idea where we set which variable to bytes and which to unicodes.
Which function is returning bytes and which is returning unicodes.
We have to make sure if some variable is changed then its effects throughout
the repository are taken care.

In this patch we make util.datapath a bytes variables.

The line containing i18n.setdatapath is skipped for a reason.
i18n.setdatapath looks something like this.

def setdatapath(datapath):
    localedir = os.path.join(datapath, pycompat.sysstr('locale'))
    t = gettextmod.translation('hg', localedir, _languages, fallback=True)

Here we can't pass gettextmod.translation() bytes when we have _languages as
None in Python 3.5. But yeah we can pass 'hg' as bytes because the code which
returns TypeError deals with localedir variable only. So we need localedir to
be unicode to make gettextmod.translation() happy. If we pass the bytes
version of datapath we will have to convert localedir back to unicode as
util.datapath will always be a str. So skipped that line of code before
converting util.datapath to bytes to use in rest of the code.


diff -r bb5869668189 -r e23132d2c665 mercurial/
--- a/mercurial/	Tue Nov 01 15:40:21 2016 -0400
+++ b/mercurial/	Thu Nov 03 00:28:33 2016 +0530
@@ -940,6 +940,9 @@ 
+if not isinstance(datapath, bytes):
+    datapath = datapath.encode('utf-8')
 _hgexecutable = None
 def hgexecutable():