Show More
@@ -201,7 +201,6 b' except ImportError:' | |||
|
201 | 201 | termios = None |
|
202 | 202 | |
|
203 | 203 | import functools |
|
204 | import locale | |
|
205 | 204 | import os |
|
206 | 205 | import struct |
|
207 | 206 | |
@@ -1710,11 +1709,8 b' def _chistedit(ui, repo, freeargs, opts)' | |||
|
1710 | 1709 | ctxs = [] |
|
1711 | 1710 | for i, r in enumerate(revs): |
|
1712 | 1711 | ctxs.append(histeditrule(ui, repo[r], i)) |
|
1713 | # Curses requires setting the locale or it will default to the C | |
|
1714 | # locale. This sets the locale to the user's default system | |
|
1715 | # locale. | |
|
1716 | locale.setlocale(locale.LC_ALL, '') | |
|
1717 | rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs)) | |
|
1712 | with util.with_lc_ctype(): | |
|
1713 | rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs)) | |
|
1718 | 1714 | curses.echo() |
|
1719 | 1715 | curses.endwin() |
|
1720 | 1716 | if rc is False: |
@@ -10,7 +10,6 b'' | |||
|
10 | 10 | |
|
11 | 11 | from __future__ import absolute_import |
|
12 | 12 | |
|
13 | import locale | |
|
14 | 13 | import os |
|
15 | 14 | import re |
|
16 | 15 | import signal |
@@ -574,14 +573,12 b' def chunkselector(ui, headerlist, operat' | |||
|
574 | 573 | """ |
|
575 | 574 | ui.write(_(b'starting interactive selection\n')) |
|
576 | 575 | chunkselector = curseschunkselector(headerlist, ui, operation) |
|
577 | # This is required for ncurses to display non-ASCII characters in | |
|
578 | # default user locale encoding correctly. --immerrr | |
|
579 | locale.setlocale(locale.LC_ALL, '') | |
|
580 | 576 | origsigtstp = sentinel = object() |
|
581 | 577 | if util.safehasattr(signal, b'SIGTSTP'): |
|
582 | 578 | origsigtstp = signal.getsignal(signal.SIGTSTP) |
|
583 | 579 | try: |
|
584 | curses.wrapper(chunkselector.main) | |
|
580 | with util.with_lc_ctype(): | |
|
581 | curses.wrapper(chunkselector.main) | |
|
585 | 582 | if chunkselector.initexc is not None: |
|
586 | 583 | raise chunkselector.initexc |
|
587 | 584 | # ncurses does not restore signal handler for SIGTSTP |
@@ -22,6 +22,7 b' import errno' | |||
|
22 | 22 | import gc |
|
23 | 23 | import hashlib |
|
24 | 24 | import itertools |
|
25 | import locale | |
|
25 | 26 | import mmap |
|
26 | 27 | import os |
|
27 | 28 | import platform as pyplatform |
@@ -3626,3 +3627,32 b' def uvarintdecodestream(fh):' | |||
|
3626 | 3627 | if not (byte & 0x80): |
|
3627 | 3628 | return result |
|
3628 | 3629 | shift += 7 |
|
3630 | ||
|
3631 | ||
|
3632 | # Passing the '' locale means that the locale should be set according to the | |
|
3633 | # user settings (environment variables). | |
|
3634 | # Python sometimes avoids setting the global locale settings. When interfacing | |
|
3635 | # with C code (e.g. the curses module or the Subversion bindings), the global | |
|
3636 | # locale settings must be initialized correctly. Python 2 does not initialize | |
|
3637 | # the global locale settings on interpreter startup. Python 3 sometimes | |
|
3638 | # initializes LC_CTYPE, but not consistently at least on Windows. Therefore we | |
|
3639 | # explicitly initialize it to get consistent behavior if it's not already | |
|
3640 | # initialized. Since CPython commit 177d921c8c03d30daa32994362023f777624b10d, | |
|
3641 | # LC_CTYPE is always initialized. If we require Python 3.8+, we should re-check | |
|
3642 | # if we can remove this code. | |
|
3643 | @contextlib.contextmanager | |
|
3644 | def with_lc_ctype(): | |
|
3645 | oldloc = locale.setlocale(locale.LC_CTYPE, None) | |
|
3646 | if oldloc == 'C': | |
|
3647 | try: | |
|
3648 | try: | |
|
3649 | locale.setlocale(locale.LC_CTYPE, '') | |
|
3650 | except locale.Error: | |
|
3651 | # The likely case is that the locale from the environment | |
|
3652 | # variables is unknown. | |
|
3653 | pass | |
|
3654 | yield | |
|
3655 | finally: | |
|
3656 | locale.setlocale(locale.LC_CTYPE, oldloc) | |
|
3657 | else: | |
|
3658 | yield |
General Comments 0
You need to be logged in to leave comments.
Login now