Patchwork [2,of,2,stable] curses: do not initialize LC_ALL to user settings (issue6358)

login
register
mail settings
Submitter Manuel Jacob
Date June 26, 2020, 7:39 a.m.
Message ID <0a2e20956b859460c5ab.1593157195@tmp>
Download mbox | patch
Permalink /patch/46575/
State New
Headers show

Comments

Manuel Jacob - June 26, 2020, 7:39 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1593157054 -7200
#      Fri Jun 26 09:37:34 2020 +0200
# Branch stable
# Node ID 0a2e20956b859460c5ab22877f46c50030ab0120
# Parent  314f194471625fe63adb3e76f9315e82e7f2994b
# EXP-Topic init_locale
curses: do not initialize LC_ALL to user settings (issue6358)

701341f57ceb moved the setlocale() call to right before curses was used. This
didn’t fully solve the problem it was supposed to solve (locale-dependent
functions, like date formatting/parsing), but only postponed it.

Initializing LC_CTYPE seems to be sufficient for curses to work correctly.
Luckily this is already done at interpreter startup on modern Python versions
and, since recently, by Mercurial in the pycompat module in all other cases.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1710,10 +1710,6 @@ 
         ctxs = []
         for i, r in enumerate(revs):
             ctxs.append(histeditrule(ui, repo[r], i))
-        # Curses requires setting the locale or it will default to the C
-        # locale. This sets the locale to the user's default system
-        # locale.
-        locale.setlocale(locale.LC_ALL, '')
         rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs))
         curses.echo()
         curses.endwin()
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -574,9 +574,6 @@ 
     """
     ui.write(_(b'starting interactive selection\n'))
     chunkselector = curseschunkselector(headerlist, ui, operation)
-    # This is required for ncurses to display non-ASCII characters in
-    # default user locale encoding correctly.  --immerrr
-    locale.setlocale(locale.LC_ALL, '')
     origsigtstp = sentinel = object()
     if util.safehasattr(signal, b'SIGTSTP'):
         origsigtstp = signal.getsignal(signal.SIGTSTP)