About encoding manipulation in Mercurial
LAO Zhongcheng
laozc at bhh.com.cn
Tue May 12 00:18:25 CDT 2009
Matt Mackall wrote:
> On Mon, May 11, 2009 at 04:38:27PM +0800, LAO Zhongcheng wrote:
>
>> Hi,
>> I'm a newbie in Python.
>>
>> Is the file mercurial/changelog.py the core API of Mercurial.
>> I found there are some callings to fromlocal
>> in the line listed below of changelog#add method.
>> 208 user, desc = util.fromlocal(user), util.fromlocal(desc)
>>
>> I suppose that if a Mercurial extension is going to call this method,
>> it has to pass a username and description in default locale
>> (system locale or HGENCODING environment).
>> Am I right?
>>
>
> Correct. However, you should -not- try to coerce user or desc to local
> encoding if for some reason they're not in local encoding. Instead,
> you should temporarily change util._encoding.
>
>
Do you mean that before I change util._encoding to UTF-8 before calling
the API,
then calls it, and restore it to the old one at the end?
I don't think it is a good idea for practise.
I expect Mercurial provides a much easier way like:
1) Enforing any call to core API to be in UTF-8. Outside the core API
(command line front-end / extension), use a wrapping implementation if
you accept user input
(either editor or command line) and performs a conversion on your own.
2) Provides an argument easy to switch between UTF-8 and local encoding
assumptions.
This will be helpful when you implement an extension being encoding-aware.
Johnson Lau
More information about the Mercurial
mailing list