扩展名为 .sql 的文件在 Mercurial 中被识别为二进制文件
我为数据库中的存储过程生成了一套完整的脚本。当我创建 Mercurial 存储库并添加这些文件时,它们都以二进制形式添加。显然,我仍然获得版本控制的好处,但失去了很多文本文件的效率、“比较”等。我验证这些文件确实只是文本。
它为什么要这样做?
我可以做什么来避免它?
有没有办法让 Hg 改变对这些文件的看法?
以下是变更集日志的片段:
496.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFindCustomerByMatchCode.StoredProcedure.sql has changed
497.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFindUnreconcilableChecks.StoredProcedure.sql has changed
498.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFixBadLabelSelected.StoredProcedure.sql has changed
499.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFixCCOPL.StoredProcedure.sql has changed
500.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFixCCOrderMoneyError.StoredProcedure.sql has changed
提前感谢您的帮助 吉姆
Possible Duplicate:
Why does Mercurial think my SQL files are binary?
I generated a complete set of scripts for the stored procedures in a database. When I created a Mercurial repository and added these files they were all added as binary. Obviously, I still get the benefits of versioning, but lose a lot of efficiency, 'diff'ing, etc... of text files. I verified that these files are indeed all just text.
Why is it doing this?
What can I do to avoid it?
IS there a way to get Hg to change it mind about these files?
Here is a snippet of changeset log:
496.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFindCustomerByMatchCode.StoredProcedure.sql has changed
497.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFindUnreconcilableChecks.StoredProcedure.sql has changed
498.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFixBadLabelSelected.StoredProcedure.sql has changed
499.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFixCCOPL.StoredProcedure.sql has changed
500.1 Binary file SQL/SfiData/Stored Procedures/dbo.pFixCCOrderMoneyError.StoredProcedure.sql has changed
Thanks in advance for your help
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了符合 Mercurial 的二进制文件视图,它实际上并不跟踪文件类型,这意味着用户无法将文件标记为二进制或非二进制。
正如 tonfa 和 Rudi 提到的,Mercurial 通过查看文件中是否有 NUL 字节来确定文件是否是二进制文件。对于 UTF-[16|32] 文件,几乎可以保证 NUL 字节。
要“修复”此问题,您必须确保文件使用 UTF-8 而不是 UTF-16 进行编码。理想情况下,您的数据库在导出时应该有一个 Unicode 编码设置。如果情况并非如此,另一种选择是编写一个预提交挂钩来执行此操作(请参阅如何在 Python 中将文件转换为 UTF-8 作为开始),但您必须非常小心要转换的文件。
In fitting with Mercurial's views on binary files, it does not actually track file types, which means that there is no way for a user to mark a file as binary or not binary.
As tonfa and Rudi mentioned, Mercurial determines whether a file is binary or not by seeing if there is a NUL byte anywhere in the file. In the case of UTF-[16|32] files, a NUL byte is pretty much guaranteed.
To "fix" this, you would have to ensure that the files are encoded with UTF-8 instead of UTF-16. Ideally, your database would have a setting for Unicode encoding when doing the export. If that's not the case, another option would be to write a precommit hook to do it (see How to convert a file to UTF-8 in Python for a start), but you would have to be very careful about which files you were converting.
我知道有点晚了,但我在评估 Kiln 时遇到了这个问题。在与 Fogbugz 的人讨论后,他们除了 SSMS 中的每个 *.sql 文件的“文件/另存为”之外无法给我答案(非常乏味),我决定看看编写一个快速脚本来转换*.sql 文件。
幸运的是,您可以使用一种 Microsoft 技术 (Powershell)(在某种程度上)克服另一种 Microsoft 技术 (SSMS) 的问题 - 使用 Powershell,更改到包含 *.sql 文件的目录,然后将以下内容复制并粘贴到 Powershell 中shell(或另存为 .ps1 脚本并从 Powershell 运行它 - 确保在尝试运行 .ps1 脚本之前运行命令“Set-ExecutionPolicy RemoteSigned”):
函数 Get-FileEncoding 由 http://poshcode.org/3227 虽然我不得不稍微修改它以适应 UC2 小端文件,SSMS 似乎已经保存了这些文件作为。我建议首先备份您的文件,因为它会覆盖原始文件 - 当然,您可以修改脚本,以便它保存文件的 UTF-8 版本,例如更改最后一行代码:
该脚本应该是也可以轻松修改以遍历子目录。
现在,您只需要记住在提交并推送更改之前,如果有任何新的 *.sql 文件,请运行此命令。任何已转换并随后在 SSMS 中打开的文件在保存时都将保留为 UTF-8。
I know it's a bit late, but I was evaluating Kiln and came across this problem. After discussion with the guys at Fogbugz who couldn't give me an answer other than "File/Save As" from SSMS for every *.sql file (very tedious), I decided to have a look at writing a quick script to convert the *.sql files.
Fortunately you can use one Microsoft technology (Powershell) to (sort of) overcome an issue with another Microsoft technology (SSMS) - using Powershell, change to the directory that contains your *.sql files and then copy and paste the following into the Powershell shell (or save as a .ps1 script and run it from Powershell - make sure to run the command "Set-ExecutionPolicy RemoteSigned" before trying to run a .ps1 script):
The function Get-FileEncoding is courtesy of http://poshcode.org/3227 although I had to modify it slightly to cater for UC2 little endian files which SSMS seems to have saved these as. I would recommend backing up your files first as it overwrites the original - you could, of course, modify the script so that it saves a UTF-8 version of the file instead e.g. change the last line of code to say:
The script should be easy to modify to traverse subdirectories as well.
Now you just need to remember to run this if there are any new *.sql files, before you commit and push your changes. Any files already converted and subsequently opened in SSMS will stay as UTF-8 when saved.