Mercurial > hg
diff 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 |
line wrap: on
line diff
--- a/hgext/histedit.py Mon Jul 22 19:10:59 2019 -0700 +++ b/hgext/histedit.py Thu Jul 25 21:28:29 2019 +0900 @@ -201,6 +201,7 @@ termios = None import functools +import locale import os import struct @@ -947,12 +948,6 @@ # Curses Support try: import curses - - # Curses requires setting the locale or it will default to the C - # locale. This sets the locale to the user's default system - # locale. - import locale - locale.setlocale(locale.LC_ALL, r'') except ImportError: curses = None @@ -1538,6 +1533,10 @@ ctxs = [] for i, r in enumerate(revs): ctxs.append(histeditrule(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, r'') rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs)) curses.echo() curses.endwin() @@ -2323,4 +2322,3 @@ cmdutil.summaryhooks.add('histedit', summaryhook) statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True, continueflag=True, abortfunc=hgaborthistedit) -