Patchwork D6777: py3: go back to using strings for paths in statprof.py

login
register
mail settings
Submitter phabricator
Date Aug. 30, 2019, 7:03 p.m.
Message ID <differential-rev-PHID-DREV-iib7qtfpv4luqvx7bpt5-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41444/
State Superseded
Headers show

Comments

phabricator - Aug. 30, 2019, 7:03 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The code before this paths raises this:
  
    TypeError: a bytes-like object is required, not 'str'
  
  The issue is that we convert to bytes, then call rsplit() on the bytes
  with os.sep, which is a string. It seems statprof.py is using strings
  for paths and 2912b06905dc <https://phab.mercurial-scm.org/rHG2912b06905dceb4fd668cd0a8d815ac9a001664b> (py3: use pycompat.fsencode() to convert
  __file__ to bytes, 2017-02-20) just went too far by using fsencode()
  there.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6777

AFFECTED FILES
  mercurial/statprof.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Aug. 30, 2019, 10:22 p.m.
martinvonz added a comment.
martinvonz planned changes to this revision.


  There's a lot more that's needed for `python3 hg --config profiling.statformat=chrome --profile` to work, so I'll probably put more changes in this patch soon.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6777/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6777

To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/statprof.py b/mercurial/statprof.py
--- a/mercurial/statprof.py
+++ b/mercurial/statprof.py
@@ -766,7 +766,7 @@ 
 
     if path in _pathcache:
         return _pathcache[path]
-    hgpath = pycompat.fsencode(encoding.__file__).rsplit(os.sep, 2)[0]
+    hgpath = encoding.__file__.rsplit(os.sep, 2)[0]
     for p in [hgpath] + sys.path:
         prefix = p + os.sep
         if path.startswith(prefix):