SVN 错误:无法将字符串从本机编码转换为“UTF-8”
我有一个提交后挂钩脚本,当提交到存储库时,该脚本会执行工作副本的 SVN 更新。
当用户使用 TortoiseSVN 从 Windows 计算机提交到存储库时,他们会收到以下错误:
post-commit hook failed (exit code 1) with output:
svn: Error converting entry in directory '/home/websites/devel/website/guides/Images' to UTF-8
svn: Can't convert string from native encoding to 'UTF-8':
svn: Teneriffa-S?\195?\188d.jpg
上面有问题的文件是:Teneriffa-Süd.jpg
注意带重音的 u。这是因为该网站是德语的,并且文件是用德语拼写的。
在 Linux 命令行上对工作副本执行更新时,不会遇到错误。仅当 Windows SVN 客户端通过提交执行提交后挂钩时,才会存在上述错误。
问题:
- 为什么 SVN 会尝试更改文件的编码?
- 文件名是否允许包含 Windows 标准 ASCII 之外的字符?
更新:
事实证明,当从 Windows 计算机(通过 Samba)查看时,相关文件的文件名正确显示为 Teneriffa-Süd.jpg
,但当我从 Linux 服务器查看文件名(使用 SSH 和PuTTY) 文件所在位置我得到 Teneriffa-Süd.jpg
I've got a post-commit hook script that performs a SVN update of a working copy when commits are made to the repository.
When users commit to the repository from their Windows machines using TortoiseSVN they get the following error:
post-commit hook failed (exit code 1) with output:
svn: Error converting entry in directory '/home/websites/devel/website/guides/Images' to UTF-8
svn: Can't convert string from native encoding to 'UTF-8':
svn: Teneriffa-S?\195?\188d.jpg
The file in question above is: Teneriffa-Süd.jpg
notice the accented u. This is because the site is German and the files have been spelt in German.
When executing a update on the working copy at the Linux command-line no errors are encountered. The above error only exists when the post-commit hook is executed via a commit by a Windows SVN client.
Questions:
- Why would SVN try to change the encoding of a file?
- Are filenames allowed to contain chars that are outside the Windows standard ASCII ones?
Update:
It turns out that the file in question's filename correctly displays as Teneriffa-Süd.jpg
when viewed from a Windows machine (via Samba) but when I view the filename from the Linux server (using SSH and PuTTY) where the file resides I get Teneriffa-Süd.jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
另一个例子:
(...现在一切都很好)
Yet another example:
(... and all is fine now)
编辑添加:
呃。我误解了症状。 svn 服务器以 utf-8 存储所有内容(看起来它成功地做到了这一点)。
post-commit 挂钩是无法从 UTF-8 转换的位。如果我正确理解你的意思,服务器上的提交后挂钩会触发对共享驱动器的 svn 更新(因此 svn 服务器会启动一个 svn 客户端......)?这意味着需要修复的配置是服务器上客户端的配置。
检查执行 svn 服务器的环境中的 LANG / LC_ALL。。碰巧,挂钩在 真空环境(参见提示)。所以你应该在钩子本身中设置变量。另请参阅此页面了解有关 svn 如何处理本地化的信息
Edit to add:
Ugh. I misunderstood the symptoms. the svn server stores everything in utf-8 (and it seems that it did that successfully).
The post-commit hook is the bit that fails to convert from UTF-8. If I understand what you're saying correctly, the post-commit hook on the server triggers an svn update to a shared drive (the svn server therefore starts an svn client to itself...) ? This means that the configuration that needs to be fixed is the one for the client on the server.
Check the LANG / LC_ALL on the environment executing the svn server.. As it happens, the hooks are run in a vacuum environment (see Tip). So you should set the variable in the hook itself.See also this page for info on how svn handles localisation
如果错误是 -
则执行此操作。
(这意味着系统在该文件夹中存在一些以“Fenerbah”开头的文件名。)
因此您可以看到该名称中存在特殊字符,并且 SVN 不支持该字符。
If Error is -
Then do this.
(This means that the system has some file name starting with "Fenerbah" in that folder.)
So you can see that there is a special character in the name and it is not supported by SVN.
不要忘记在您的系统中生成这些区域设置
(作为根用户)
例如 Ru
Don't forget to generate those locales in your system
(as root)
example for Ru
把它放在你的提交后
导出 LANG=xxxxx(您的语言)
put this in your post-commit
export LANG=xxxxx (your lang)
只需在执行任何 svn 命令之前在脚本中使用以下行即可。
用户适当的语言代码,在下面的示例中我使用日语
Just use the following line in your script before executing any svn command.
User appropriate language codes, in following example I used japanese
似乎所有 LC_ 变量末尾都需要 .UTF8。例如,我碰巧定义了 LC_ALL、LC_TIME 和 LC_CTYPE。设置 LC_CTYPE 后问题没有解决,所以我还需要输入 LC_ALL 然后它就工作了:
为了避免再次出现问题,我将文件复制到另一个名称,从 svn 中删除旧的,添加新的到svn,并向协作者发送消息不要这样做。
It seems that all LC_ varables need .UTF8 at the end. For example, I happened to have LC_ALL, LC_TIME, and LC_CTYPE defined. After setting LC_CTYPE the problem was not solved, so I needed to type LC_ALL as well and then it worked:
In order to avoid the problem again, I copied the file to a different name, removed the old one from svn, added new one to svn, and send a message to a collaborator not to do this.
它将编码更改为位置中立编码,以防有人使用不同的编码检查它。
解决此问题的最佳方法是确保您的系统尽可能使用 UTF-8(检查
$LANG
)。It changes the encoding to a location-neutral encoding in case someone with a different encoding checks it out.
Of course. But it's not "Windows" ASCII (Windows actually uses some strange encoding like CP1251 or so).
The best way to fix this is to make sure that your system uses UTF-8 whenever possible (check
$LANG
).在目录上运行“svn add”时我遇到了类似的问题,但解决方案不同。我无法使用 printf 看到“十六进制”数字(实际上 svn 没有显示十六进制输出),但是这个命令允许我查看结果,并修复它:
我认为,一般来说,在命令之前粘贴 LC_ALL=C允许您查看有问题的文件...并且比粘贴大量 \x72 内容(显然可能不可用)容易得多。
I got a similar problem when running "svn add" on a directory, but the solution was different. I couldn't see the "hex" digits using printf (actually no hex output was shown by svn), but this command allowed me to see the results, and fix it:
I think, in general, sticking LC_ALL=C before your command allows you to see the offending files... and is a lot easier than pasting in a lot of \x72 stuff (which apparently may not be available).
有关信息,
当我的存储库 URL 为:
我更改了存储库的 URL:
现在一切都很完美。
我认为这些信息对某些人有用。
For information, I got this error on commit
native encoding to 'UTF-8'
with a windows client tortoise svn,when my URL of repository was :
I changed my URL of repository for :
and now all is perferct.
I think this information will be useful to some.
就我而言,我在 ~/.subversion/config 中进行了如下设置
<代码>
日志编码 = ...
评论
它有效。
In my case, I had the setting in ~/.subversion/config as below
log-encoding = ...
Commenting it worked.