如何防止BOM从Perforce unicode文件中删除 [英] How to keep BOM from removal from Perforce unicode files
问题描述
我已将具有.NET和SQL源的整个分支转换为具有BOM表的 UTF-8 ,并在同一操作中将其Perforce文件类型更改为 Unicode . (编码上的差异可能令人困惑,但是在Perforce中, Unicode 文件类型表示UTF-8文件的内容.)但是后来我发现Perforce默默地从UTF-8文件中消除了BOM标记.是否可以将Perforce设置为在 Unicode 文件类型的文件中保留UTF-8 BOM标记?我找不到记录.
I have converted entire branch with .NET and SQL sources to UTF-8 with BOM, having their Perforce file type changed to Unicode in the same operation. (Encoding difference might sound confusing, but in Perforce, Unicode file type denotes UTF-8 file content.) But later I have found out that Perforce silently elliminates BOM marker from UTF-8 files. Is it possible to set Perforce to keep UTF-8 BOM markers in files of Unicode file type? I can't find it documented.
Perforce服务器已切换为 Unicode 模式,连接编码为 UTF-8 ,没有BOM(但使用BOM将其更改为 UTF-8 没什么区别.)
Perforce server is switched to Unicode mode, connection encoding is UTF-8 no BOM (but changing it to UTF-8 with BOM doesn't make any difference).
示例:
- 从Perforce签出源文件
- 将文件类型更改为 Unicode
- 将文件内容转换为带BOM的UTF-8"格式
- 提交文件(现在文件仍将BOM保留在前3个字节中)
- 从工作区中删除文件
- 获取文件的最新修订版(现在文件开头不包含BOM)
- check out a source file from Perforce
- change file type to Unicode
- convert file content to format "UTF-8 with BOM"
- submit the file (now the file still keeps BOM in first 3 bytes)
- remove the file from workspace
- get the latest revision of the file (now the file doesn't contain BOM at the beginning)
推荐答案
好的,Hans Passant的评论鼓励我重新检查P4CHARSET,最后,答案包括两个部分:
OK, Hans Passant's comment encouraged me to re-examine P4CHARSET and finally, the answer has two parts:
对于Perforce命令行访问,设置P4CHARSET
变量可控制行为.要启用将BOM添加到 Unicode 类型的文件中,请使用命令
For Perforce command line access, setting of P4CHARSET
variable controls the behavior. To enable adding BOM to files of Unicode type, use command
p4 set P4CHARSET=utf8-bom
要使这些文件没有 BOM,请使用
In order to have these files without BOM, use
p4 set P4CHARSET=utf8
对于P4V Perforce Visual Client ,可以通过菜单Connection
> Choose Character Encoding...
更改设置.使用值Unicode (UTF-8)
启用添加BOM表,使用Unicode (UTF-8, no BOM)
禁止添加BOM表.
For P4V The Perforce Visual Client, the setting can be changed via menu Connection
> Choose Character Encoding...
. Use value Unicode (UTF-8)
to enable adding BOM and Unicode (UTF-8, no BOM)
to suppress it.
- 如果菜单项
Choose Character Encoding...
被禁用,请确保以下内容(然后再次检查)- P4V与服务器打开并正常工作
- 包含仓库/工作区树的窗格被聚焦(在内部单击以重新确保它)
- if menu item
Choose Character Encoding...
is disabled, ensure the following (and then check again)- P4V has connection to server open and working
- pane containing depot/workspace tree is focused (click inside to re-ensure this)
注释:
- 如果您通常同时结合使用上述两种方式来访问Perforce ,则需要同时应用这两种解决方案,否则您将不断得到不同的结果
- 如果要立即向现有文件中添加BOM表或从现有文件中删除BOM表,请调整上述设置,然后从工作区中删除文件并再次添加它们(请参见步骤 5 和问题中发布的示例的 6 ).其他更改文件内容(集成,合并等)的服务器操作也将执行类似的操作
- 有关其他编码选项及其对BOM的影响,请参见 P4D,Perforce Server和Perforce客户端应用程序的国际化说明
- if you usually combine both above ways to access Perforce, you need to apply both solutions, otherwise you will keep getting mixed results
- if you want to instantly add/remove BOM to/from existing files, adjust the above settings, then remove files from workspace and add them again (see steps 5 and 6 of example posted in the question). Other server actions changing content of files (integrating, merging etc.) will do the similar
- for other encoding options and their impact on BOM, see the second table in Internationalization Notes for P4D, the Perforce Server and Perforce client applications
这篇关于如何防止BOM从Perforce unicode文件中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!