Mercurial的showconfig是否正确编码?

2024-09-29 19:33:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用hg showconfig获取Mercurial存储库的根路径,然后检索bundle.mainreporoot。根路径有非ASCII字符,它是D:\maçã\asd。在

hg showconfig的输出是:

...
bundle.mainreporoot=D:\maþÒ\asd
...

我在一个编码为cp850的windows7powershell中运行这个。我想告诉Mercurial用正确的编码cp850输出showconfig。我试过例如hg showconfig --encoding cp850,但没有成功。在

字符þ在cp850 \xE7中,它看起来像是ç的unicode代码点U+00E7(我需要的正确字符),也是cp1252中的ç。在


Tags: 路径编码asciihg字符mercurialencodingbundle
1条回答
网友
1楼 · 发布于 2024-09-29 19:33:23

在运行命令之前更改代码页有帮助。美国Windows使用cp437作为控制台,Windows-1252用于非Unicode GUI程序。不管出于什么原因,Mercurial正在使用cp1252。如果您不使用我们的Windows,您可能需要一个不同的代码页。在

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS W:\maçã\asd> hg showconfig bundle.mainreporoot
W:\maτπ\asd
PS W:\maçã\asd> chcp 1252
Active code page: 1252
PS W:\maçã\asd> hg showconfig bundle.mainreporoot
W:\maçã\asd

编辑

根据Python3,您看到的三个不同的字符串是Mercurial返回的cp1252,并在控制台中解码为cp850或cp437:

^{pr2}$

您的pastebin代码是cp850解码为cp1252:

>>> 'maçã'.encode('cp850').decode('cp1252')
'ma‡Æ'

相关问题 更多 >

    热门问题