简体   繁体   English

如何防止BOM从Perforce unicode文件中删除

[英]How to keep BOM from removal from Perforce unicode files

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. 我已经将带有.NET和SQL源的整个分支转换为带有BOM的UTF-8,在同一操作中将Perforce文件类型更改为Unicode (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. (编码差异可能听起来令人困惑,但在Perforce中, Unicode文件类型表示UTF-8文件内容。)但后来我发现Perforce默默地从UTF-8文件中消除了BOM标记。 Is it possible to set Perforce to keep UTF-8 BOM markers in files of Unicode file type? 是否可以设置Perforce以将UTF-8 BOM标记保存在Unicode文件类型的文件中? I can't find it documented. 我找不到记录。

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模式,连接编码是UTF-8没有BOM(但将其更改为带有BOM的UTF-8没有任何区别)。

Example: 例:

  1. check out a source file from Perforce 从Perforce中查看源文件
  2. change file type to Unicode 将文件类型更改为Unicode
  3. convert file content to format "UTF-8 with BOM" 将文件内容转换为“带BOM的UTF-8”格式
  4. submit the file (now the file still keeps BOM in first 3 bytes) 提交文件(现在文件仍保留前3个字节的BOM)
  5. remove the file from workspace 从工作区中删除文件
  6. get the latest revision of the file (now the file doesn't contain BOM at the beginning) 获取文件的最新版本(现在文件开头不包含BOM)

OK, Hans Passant's comment encouraged me to re-examine P4CHARSET and finally, the answer has two parts: 好吧,Hans Passant的评论鼓励我重新审视P4CHARSET,最后,答案分为两部分:


For Perforce command line access , setting of P4CHARSET variable controls the behavior. 对于Perforce命令行访问P4CHARSET变量的设置控制行为。 To enable adding BOM to files of Unicode type, use command 要启用将BOM添加到Unicode类型的文件,请使用命令

p4 set P4CHARSET=utf8-bom

In order to have these files without BOM, use 为了使这些文件没有 BOM,请使用

p4 set P4CHARSET=utf8

For P4V The Perforce Visual Client , the setting can be changed via menu Connection > Choose Character Encoding... . 对于P4V Perforce Visual Client ,可以通过菜单Connection > Choose Character Encoding...更改设置。 Use value Unicode (UTF-8) to enable adding BOM and Unicode (UTF-8, no BOM) to suppress it. 使用值Unicode (UTF-8)可以添加BOM和Unicode (UTF-8, no BOM)来抑制它。

  • if menu item Choose Character Encoding... is disabled, ensure the following (and then check again) 如果菜单项Choose Character Encoding...被禁用,请确保以下(然后再次检查)
    • P4V has connection to server open and working P4V已连接到服务器打开和工作
    • pane containing depot/workspace tree is focused (click inside to re-ensure this) 包含软件仓库/工作区树的窗格是聚焦的(单击里面重新确保这一点)

Notes: 笔记:

  • if you usually combine both above ways to access Perforce , you need to apply both solutions, otherwise you will keep getting mixed results 如果您通常结合以上两种方式来访问Perforce ,则需要应用这两种解决方案,否则您将不断获得混合结果
  • 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). 如果要立即向现有文件添加/删除BOM ,请调整上述设置,然后从工作区中删除文件并再次添加(请参阅问题中发布的示例中的步骤56 )。 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的影响 ,请参阅P4D国际化说明中的第二个表,Perforce Server和Perforce客户端应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM