[PATCH 1 of 2] curses: back out d2227d4c9e6b (do not initialize LC_ALL to user settings)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1 of 2] curses: back out d2227d4c9e6b (do not initialize LC_ALL to user settings)

Manuel Jacob
# HG changeset patch
# User Manuel Jacob <[hidden email]>
# Date 1593359354 -7200
#      Sun Jun 28 17:49:14 2020 +0200
# Node ID b7e0d1cf9aa1d122075eb9100702aa20686fa42b
# Parent  47a07bbf400a24ef48bcaf0e7a4c15365c3a000b
curses: back out d2227d4c9e6b (do not initialize LC_ALL to user settings)

The changeset was based on a25343d16ebe, which will be backed out, too.
Another fix for the problem will be resubmitted to the stable branch.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -201,6 +201,7 @@
     termios = None
 
 import functools
+import locale
 import os
 import struct
 
@@ -1710,6 +1711,10 @@
         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
@@ -10,6 +10,7 @@
 
 from __future__ import absolute_import
 
+import locale
 import os
 import re
 import signal
@@ -565,6 +566,9 @@
     """
     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)

_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 2 of 2] compat: back out a25343d16ebe (initialize LC_CTYPE locale on all Python ...)

Manuel Jacob
# HG changeset patch
# User Manuel Jacob <[hidden email]>
# Date 1593359549 -7200
#      Sun Jun 28 17:52:29 2020 +0200
# Node ID 717366b883b337f456113dc815eaa0ec17f7f990
# Parent  b7e0d1cf9aa1d122075eb9100702aa20686fa42b
compat: back out a25343d16ebe (initialize LC_CTYPE locale on all Python ...)

As Yuya Nishihara pointed out, setting LC_CTYPE changes the behavior of some
str methods on Python 2.

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -13,7 +13,6 @@
 import getopt
 import inspect
 import json
-import locale
 import os
 import shlex
 import sys
@@ -94,26 +93,6 @@
     return _rapply(f, xs)
 
 
-# Passing the '' locale means that the locale should be set according to the
-# user settings (environment variables).
-# Python sometimes avoids setting the global locale settings. When interfacing
-# with C code (e.g. the curses module or the Subversion bindings), the global
-# locale settings must be initialized correctly. Python 2 does not initialize
-# the global locale settings on interpreter startup. Python 3 sometimes
-# initializes LC_CTYPE, but not consistently at least on Windows. Therefore we
-# explicitly initialize it to get consistent behavior if it's not already
-# initialized. Since CPython commit 177d921c8c03d30daa32994362023f777624b10d,
-# LC_CTYPE is always initialized. If we require Python 3.8+, we should re-check
-# if we can remove this code.
-if locale.setlocale(locale.LC_CTYPE, None) == 'C':
-    try:
-        locale.setlocale(locale.LC_CTYPE, '')
-    except locale.Error:
-        # The likely case is that the locale from the environment variables is
-        # unknown.
-        pass
-
-
 if ispy3:
     import builtins
     import codecs

_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1 of 2] curses: back out d2227d4c9e6b (do not initialize LC_ALL to user settings)

Yuya Nishihara
In reply to this post by Manuel Jacob
On Sun, 28 Jun 2020 17:54:32 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <[hidden email]>
> # Date 1593359354 -7200
> #      Sun Jun 28 17:49:14 2020 +0200
> # Node ID b7e0d1cf9aa1d122075eb9100702aa20686fa42b
> # Parent  47a07bbf400a24ef48bcaf0e7a4c15365c3a000b
> curses: back out d2227d4c9e6b (do not initialize LC_ALL to user settings)

Queued, thanks.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel