mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  - DO NOT QUEUE THIS **
  
  I have no idea how this is supposed to be fixed for real, but it's likely
  related to the comment above where stdout is set about maybe needing a silly
  wrapper.  PEP 528[1] talks about not assuming the encoding of 
sys.stdout.buffer,
  but I thought the whole point of always using bytes was to avoid encoding.
  
  This hack allows TortoiseHg to work when built with py2exe on py3, by avoiding
  this:
  
    #!python
    ** Mercurial version (6.1.1+hg216.d8b5fd0ab640local20220412).  TortoiseHg 
version (6.1.1+26-204092cabbee)
    ** Command: --nofork workbench
    ** CWD: C:\Users\Administrator\Desktop
    ** Encoding: cp1252
    ** Extensions loaded: absorb, strip, tortoisehg.util.configitems
    ** Python version: 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) 
[MSC v.1929 64 bit (AMD64)]
    ** Windows version: sys.getwindowsversion(major=6, minor=2, build=9200, 
platform=2, service_pack='')
    ** Processor architecture: x64
    ** Qt-5.15.2 PyQt-5.15.6 QScintilla-2.13.1
    Traceback (most recent call last):
      File "tortoisehg\hgqt\repotab.pyc", line 355, in _onCurrentTabChanged
      File "tortoisehg\hgqt\repotab.pyc", line 406, in _createRepoWidget
      File "tortoisehg\hgqt\repowidget.pyc", line 228, in __init__
      File "tortoisehg\hgqt\repowidget.pyc", line 260, in setupUi
      File "tortoisehg\hgqt\repofilter.pyc", line 264, in __init__
      File "tortoisehg\hgqt\repofilter.pyc", line 554, in refresh
      File "tortoisehg\hgqt\repofilter.pyc", line 491, in _updateBranchFilter
      File "tortoisehg\util\hglib.pyc", line 237, in namedbranches
      File "mercurial\localrepo.pyc", line 2154, in branchmap
      File "mercurial\branchmap.pyc", line 72, in __getitem__
      File "mercurial\branchmap.pyc", line 81, in updatecache
      File "mercurial\repoview.pyc", line 421, in changelog
      File "mercurial\repoview.pyc", line 248, in filterrevs
      File "mercurial\repoview.pyc", line 104, in computehidden
      File "mercurial\repoview.pyc", line 43, in hideablerevs
      File "mercurial\obsolete.pyc", line 911, in getrevs
      File "mercurial\localrepo.pyc", line 118, in __get__
      File "mercurial\scmutil.pyc", line 1709, in __get__
      File "mercurial\localrepo.pyc", line 1723, in obsstore
      File "mercurial\obsolete.pyc", line 817, in makestore
      File "mercurial\ui.pyc", line 1855, in warn
      File "mercurial\ui.pyc", line 1330, in _writemsg
      File "mercurial\ui.pyc", line 2282, in _writemsgwith
      File "mercurial\ui.pyc", line 1273, in _write
      File "mercurial\ui.pyc", line 1298, in _writenobuf
      File "mercurial\windows.pyc", line 240, in write
      File "mercurial\utils\procutil.pyc", line 114, in write
      File "boot_common.py", line 74, in write
    TypeError: write() argument must be str, not memoryview
  
  [1] https://peps.python.org/pep-0528/

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/utils/procutil.py

CHANGE DETAILS

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -107,11 +107,11 @@
 
     def write(self, s):
         write1 = self.orig.write
-        m = memoryview(s)
-        total_to_write = len(s)
+        v = encoding.strfromlocal(s)
+        total_to_write = len(v)
         total_written = 0
         while total_written < total_to_write:
-            c = write1(m[total_written:])
+            c = write1(v[total_written:])
             if c:
                 total_written += c
         return total_written
@@ -147,11 +147,11 @@
 if sys.stdout is None:
     stdout = BadFile()
 else:
-    stdout = _make_write_all(sys.stdout.buffer)
+    stdout = _make_write_all(getattr(sys.stdout, 'buffer', sys.stdout))
 if sys.stderr is None:
     stderr = BadFile()
 else:
-    stderr = _make_write_all(sys.stderr.buffer)
+    stderr = _make_write_all(getattr(sys.stderr, 'buffer', sys.stderr))
 
 if pycompat.iswindows:
     # Work around Windows bugs.



To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to