Patchwork [2,of,3,STABLE] py3: keep "keypressed" a native str in crecord

login
register
mail settings
Submitter Denis Laxalde
Date Nov. 6, 2019, 4:23 p.m.
Message ID <5802765e3828e3b3f139.1573057408@steppe.local>
Download mbox | patch
Permalink /patch/42806/
State New
Headers show

Comments

Denis Laxalde - Nov. 6, 2019, 4:23 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1573055581 -3600
#      Wed Nov 06 16:53:01 2019 +0100
# Branch stable
# Node ID 5802765e3828e3b3f1396b92ed7ef18a1eca6456
# Parent  ae3e67359e0bf045ae1bb797d8f4e043fa55042b
py3: keep "keypressed" a native str in crecord

This will help in the next changeset by avoiding a decode step. Also,
the actual bytes conversion seems superfluous since values coming from
curses's getkey() will be a native string. As a consequence, we open the
"testcommands" file (used in test-interactive-curses.t) in text mode.

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -24,7 +24,6 @@  from . import (
     encoding,
     error,
     patch as patchmod,
-    pycompat,
     scmutil,
     util,
 )
@@ -607,8 +606,8 @@  def testchunkselector(testfn, ui, header
 
     chunkselector.stdscr = dummystdscr()
     if testfn and os.path.exists(testfn):
-        testf = open(testfn, b'rb')
-        testcommands = [x.rstrip(b'\n') for x in testf.readlines()]
+        testf = open(testfn, 'r')
+        testcommands = [x.rstrip('\n') for x in testf.readlines()]
         testf.close()
         while True:
             if chunkselector.handlekeypressed(testcommands.pop(0), test=True):
@@ -1887,60 +1886,59 @@  are you sure you want to review/edit and
 
         Return true to exit the main loop.
         """
-        keypressed = pycompat.bytestr(keypressed)
-        if keypressed in [b"k", b"KEY_UP"]:
+        if keypressed in ["k", "KEY_UP"]:
             self.uparrowevent()
-        elif keypressed in [b"K", b"KEY_PPAGE"]:
+        elif keypressed in ["K", "KEY_PPAGE"]:
             self.uparrowshiftevent()
-        elif keypressed in [b"j", b"KEY_DOWN"]:
+        elif keypressed in ["j", "KEY_DOWN"]:
             self.downarrowevent()
-        elif keypressed in [b"J", b"KEY_NPAGE"]:
+        elif keypressed in ["J", "KEY_NPAGE"]:
             self.downarrowshiftevent()
-        elif keypressed in [b"l", b"KEY_RIGHT"]:
+        elif keypressed in ["l", "KEY_RIGHT"]:
             self.rightarrowevent()
-        elif keypressed in [b"h", b"KEY_LEFT"]:
+        elif keypressed in ["h", "KEY_LEFT"]:
             self.leftarrowevent()
-        elif keypressed in [b"H", b"KEY_SLEFT"]:
+        elif keypressed in ["H", "KEY_SLEFT"]:
             self.leftarrowshiftevent()
-        elif keypressed in [b"q"]:
+        elif keypressed in ["q"]:
             raise error.Abort(_(b'user quit'))
-        elif keypressed in [b'a']:
+        elif keypressed in ['a']:
             self.toggleamend(self.opts, test)
-        elif keypressed in [b"c"]:
+        elif keypressed in ["c"]:
             return True
-        elif keypressed in [b"r"]:
+        elif keypressed in ["r"]:
             if self.reviewcommit():
                 self.opts[b'review'] = True
                 return True
-        elif test and keypressed in [b'R']:
+        elif test and keypressed in ["R"]:
             self.opts[b'review'] = True
             return True
-        elif keypressed in [b' ', b'x']:
+        elif keypressed in [" ", "x"]:
             self.toggleapply()
-        elif keypressed in [b'\n', b'KEY_ENTER']:
+        elif keypressed in ["\n", "KEY_ENTER"]:
             self.toggleapply()
             self.nextsametype(test=test)
-        elif keypressed in [b'X']:
+        elif keypressed in ["X"]:
             self.toggleallbetween()
-        elif keypressed in [b'A']:
+        elif keypressed in ["A"]:
             self.toggleall()
-        elif keypressed in [b'e']:
+        elif keypressed in ["e"]:
             self.toggleedit(test=test)
-        elif keypressed in [b"f"]:
+        elif keypressed in ["f"]:
             self.togglefolded()
-        elif keypressed in [b"F"]:
+        elif keypressed in ["F"]:
             self.togglefolded(foldparent=True)
-        elif keypressed in [b"m"]:
+        elif keypressed in ["m"]:
             self.commitMessageWindow()
-        elif keypressed in [b"g", b"KEY_HOME"]:
+        elif keypressed in ["g", "KEY_HOME"]:
             self.handlefirstlineevent()
-        elif keypressed in [b"G", b"KEY_END"]:
+        elif keypressed in ["G", "KEY_END"]:
             self.handlelastlineevent()
-        elif keypressed in [b"?"]:
+        elif keypressed in ["?"]:
             self.helpwindow()
             self.stdscr.clear()
             self.stdscr.refresh()
-        elif curses.unctrl(keypressed) in [b"^L"]:
+        elif curses.unctrl(keypressed) in ["^L"]:
             # scroll the current line to the top of the screen, and redraw
             # everything
             self.scrolllines(self.selecteditemstartline)