Show More
@@ -201,7 +201,6 except ImportError: | |||||
201 | termios = None |
|
201 | termios = None | |
202 |
|
202 | |||
203 | import functools |
|
203 | import functools | |
204 | import locale |
|
|||
205 | import os |
|
204 | import os | |
206 | import struct |
|
205 | import struct | |
207 |
|
206 | |||
@@ -1710,10 +1709,7 def _chistedit(ui, repo, freeargs, opts) | |||||
1710 | ctxs = [] |
|
1709 | ctxs = [] | |
1711 | for i, r in enumerate(revs): |
|
1710 | for i, r in enumerate(revs): | |
1712 | ctxs.append(histeditrule(ui, repo[r], i)) |
|
1711 | ctxs.append(histeditrule(ui, repo[r], i)) | |
1713 | # Curses requires setting the locale or it will default to the C |
|
1712 | with util.with_lc_ctype(): | |
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)) |
|
1713 | rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs)) | |
1718 | curses.echo() |
|
1714 | curses.echo() | |
1719 | curses.endwin() |
|
1715 | curses.endwin() |
@@ -10,7 +10,6 | |||||
10 |
|
10 | |||
11 | from __future__ import absolute_import |
|
11 | from __future__ import absolute_import | |
12 |
|
12 | |||
13 | import locale |
|
|||
14 | import os |
|
13 | import os | |
15 | import re |
|
14 | import re | |
16 | import signal |
|
15 | import signal | |
@@ -574,13 +573,11 def chunkselector(ui, headerlist, operat | |||||
574 | """ |
|
573 | """ | |
575 | ui.write(_(b'starting interactive selection\n')) |
|
574 | ui.write(_(b'starting interactive selection\n')) | |
576 | chunkselector = curseschunkselector(headerlist, ui, operation) |
|
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 | origsigtstp = sentinel = object() |
|
576 | origsigtstp = sentinel = object() | |
581 | if util.safehasattr(signal, b'SIGTSTP'): |
|
577 | if util.safehasattr(signal, b'SIGTSTP'): | |
582 | origsigtstp = signal.getsignal(signal.SIGTSTP) |
|
578 | origsigtstp = signal.getsignal(signal.SIGTSTP) | |
583 | try: |
|
579 | try: | |
|
580 | with util.with_lc_ctype(): | |||
584 | curses.wrapper(chunkselector.main) |
|
581 | curses.wrapper(chunkselector.main) | |
585 | if chunkselector.initexc is not None: |
|
582 | if chunkselector.initexc is not None: | |
586 | raise chunkselector.initexc |
|
583 | raise chunkselector.initexc |
@@ -22,6 +22,7 import errno | |||||
22 | import gc |
|
22 | import gc | |
23 | import hashlib |
|
23 | import hashlib | |
24 | import itertools |
|
24 | import itertools | |
|
25 | import locale | |||
25 | import mmap |
|
26 | import mmap | |
26 | import os |
|
27 | import os | |
27 | import platform as pyplatform |
|
28 | import platform as pyplatform | |
@@ -3626,3 +3627,32 def uvarintdecodestream(fh): | |||||
3626 | if not (byte & 0x80): |
|
3627 | if not (byte & 0x80): | |
3627 | return result |
|
3628 | return result | |
3628 | shift += 7 |
|
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