changeset 40214:b456b2e0ad9f

py3: make test-contrib-perf.t work on python 3 Differential Revision: https://phab.mercurial-scm.org/D5025
author Pulkit Goyal <pulkit@yandex-team.ru>
date Sat, 13 Oct 2018 03:46:57 +0300
parents 83912321bf09
children 4d6019c0e0ef
files contrib/perf.py contrib/python3-whitelist
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Sat Oct 13 03:32:12 2018 +0300
+++ b/contrib/perf.py	Sat Oct 13 03:46:57 2018 +0300
@@ -75,6 +75,7 @@
     _byteskwargs = pycompat.byteskwargs  # since 4.1 (or fbc3f73dc802)
     _sysstr = pycompat.sysstr         # since 4.0 (or 2219f4f82ede)
     _xrange = pycompat.xrange         # since 4.8 (or 7eba8f83129b)
+    fsencode = pycompat.fsencode      # since 3.9 (or f4a5e0e86a7e)
     if pycompat.ispy3:
         _maxint = sys.maxsize  # per py3 docs for replacing maxint
     else:
@@ -83,6 +84,7 @@
     import inspect
     getargspec = inspect.getargspec
     _byteskwargs = identity
+    fsencode = identity               # no py3 support
     _maxint = sys.maxint              # no py3 support
     _sysstr = lambda x: x             # no py3 support
     _xrange = xrange
@@ -968,7 +970,7 @@
 def perfstartup(ui, repo, **opts):
     opts = _byteskwargs(opts)
     timer, fm = gettimer(ui, opts)
-    cmd = sys.argv[0]
+    cmd = fsencode(sys.argv[0])
     def d():
         if os.name != r'nt':
             os.system(b"HGRCPATH= %s version -q > /dev/null" % cmd)
@@ -1387,17 +1389,18 @@
     opts = _byteskwargs(opts)
     timer, fm = gettimer(ui, opts)
     options = {
-        b'w': b'ignore_all_space',
-        b'b': b'ignore_space_change',
-        b'B': b'ignore_blank_lines',
+        'w': 'ignore_all_space',
+        'b': 'ignore_space_change',
+        'B': 'ignore_blank_lines',
         }
 
-    for diffopt in (b'', b'w', b'b', b'B', b'wB'):
+    for diffopt in ('', 'w', 'b', 'B', 'wB'):
         opts = dict((options[c], b'1') for c in diffopt)
         def d():
             ui.pushbuffer()
             commands.diff(ui, repo, **opts)
             ui.popbuffer()
+        diffopt = diffopt.encode('ascii')
         title = b'diffopts: %s' % (diffopt and (b'-' + diffopt) or b'none')
         timer(d, title)
     fm.end()
@@ -1773,7 +1776,7 @@
     data = segmentforrevs(chain[0], chain[-1])[1]
     rawchunks = getrawchunks(data, chain)
     bins = r._chunks(chain)
-    text = str(bins[0])
+    text = bytes(bins[0])
     bins = bins[1:]
     text = mdiff.patches(text, bins)
 
--- a/contrib/python3-whitelist	Sat Oct 13 03:32:12 2018 +0300
+++ b/contrib/python3-whitelist	Sat Oct 13 03:46:57 2018 +0300
@@ -85,6 +85,7 @@
 test-contrib-check-code.t
 test-contrib-check-commit.t
 test-contrib-dumprevlog.t
+test-contrib-perf.t
 test-contrib-testparseutil.t
 test-convert-authormap.t
 test-convert-clonebranches.t