comparison hgext/histedit.py @ 42659:701341f57ceb stable

curses: do not setlocale() at import time (issue5261) setlocale() can break date formatting/parsing functions because they are locale dependent. We should avoid doing setlocale() as possible. This patch moves setlocale() just before curses.wrapper(), which function is documented to "initialize curses." I don't know the details about the curses initialization, but I *think* this would work as well. Maybe we can extract a curses setup function later. https://www.mercurial-scm.org/pipermail/mercurial-devel/2019-February/128788.html
author Yuya Nishihara <yuya@tcha.org>
date Thu, 25 Jul 2019 21:28:29 +0900
parents db5560c07a28
children 699102b10530
comparison
equal deleted inserted replaced
42649:7fae3b0bd893 42659:701341f57ceb
199 except ImportError: 199 except ImportError:
200 fcntl = None 200 fcntl = None
201 termios = None 201 termios = None
202 202
203 import functools 203 import functools
204 import locale
204 import os 205 import os
205 import struct 206 import struct
206 207
207 from mercurial.i18n import _ 208 from mercurial.i18n import _
208 from mercurial import ( 209 from mercurial import (
945 return repo[roots[0]].node() 946 return repo[roots[0]].node()
946 947
947 # Curses Support 948 # Curses Support
948 try: 949 try:
949 import curses 950 import curses
950
951 # Curses requires setting the locale or it will default to the C
952 # locale. This sets the locale to the user's default system
953 # locale.
954 import locale
955 locale.setlocale(locale.LC_ALL, r'')
956 except ImportError: 951 except ImportError:
957 curses = None 952 curses = None
958 953
959 KEY_LIST = ['pick', 'edit', 'fold', 'drop', 'mess', 'roll'] 954 KEY_LIST = ['pick', 'edit', 'fold', 'drop', 'mess', 'roll']
960 ACTION_LABELS = { 955 ACTION_LABELS = {
1536 node.short(root)) 1531 node.short(root))
1537 1532
1538 ctxs = [] 1533 ctxs = []
1539 for i, r in enumerate(revs): 1534 for i, r in enumerate(revs):
1540 ctxs.append(histeditrule(repo[r], i)) 1535 ctxs.append(histeditrule(repo[r], i))
1536 # Curses requires setting the locale or it will default to the C
1537 # locale. This sets the locale to the user's default system
1538 # locale.
1539 locale.setlocale(locale.LC_ALL, r'')
1541 rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs)) 1540 rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs))
1542 curses.echo() 1541 curses.echo()
1543 curses.endwin() 1542 curses.endwin()
1544 if rc is False: 1543 if rc is False:
1545 ui.write(_("histedit aborted\n")) 1544 ui.write(_("histedit aborted\n"))
2321 2320
2322 def extsetup(ui): 2321 def extsetup(ui):
2323 cmdutil.summaryhooks.add('histedit', summaryhook) 2322 cmdutil.summaryhooks.add('histedit', summaryhook)
2324 statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True, 2323 statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True,
2325 continueflag=True, abortfunc=hgaborthistedit) 2324 continueflag=True, abortfunc=hgaborthistedit)
2326