简体   繁体   English

为什么Mercurial不能将我的XML文件与Beyond Compare合并?

[英]Why won't Mercurial merge my XML files with Beyond Compare?

We have a bunch of XML files in our Mercurial repository. 我们的Mercurial存储库中有一堆XML文件。 When we merge changes in those files from one branch to another, Mercurial complains that some of our XML files are binary , and asks me to choose between the local and other versions of the file. 当我们将这些文件中的更改从一个分支合并到另一个分支时, Mercurial抱怨我们的某些XML文件是二进制文件 ,并要求我在文件的本地版本和其他版本之间进行选择。

I've discovered that Mercurial thinks any file with a NULL byte in it is binary, and some of our XML files are encoded as UTF-16, so contain a lot of NULL bytes. 我发现Mercurial认为其中任何带有NULL字节的文件都是二进制文件,并且我们的某些XML文件编码为UTF-16,因此包含很多NULL字节。 My default merge tool is Beyond Compare , which can handle UTF-16 encoded files. 我的默认合并工具是Beyond Compare ,它可以处理UTF-16编码的文件。 I've configured Mercurial as recommended on the Beyond Compare website , but during the merge, Mercurial says: 我已经按照Beyond Compare网站上的建议配置了Mercurial,但是在合并过程中,Mercurial表示:

tool bcomp can't handle binary 工具bcomp无法处理二进制文件

What gives? 是什么赋予了? Why does Mercurial think Beyond Compare can't merge my file? 为什么Mercurial认为Beyond Compare无法合并我的文件?

The recommended Mercurial configuration to use Beyond Compare as a merge program looks like this: 推荐的Mercurial配置使用Beyond Compare作为合并程序,如下所示:

[merge-tools]
bcomp.executable = C:\Program Files\Beyond Compare 3\BComp.exe
bcomp.args = $local $other $base $output
bcomp.priority = 1
bcomp.premerge = True
bcomp.gui = True

[ui]
merge = bcomp

According to the Mercurial docs on merge tools , there is a binary option that is False by default. 根据Mercurial关于合并工具的文档 ,有一个binary选项默认为False When binary=True , it tells Mercurial the tool can merge binary files. binary=True ,它告诉Mercurial该工具可以合并二进制文件。 When I turn that option on, however, Mercurial still won't let Beyond Compare merge the XML files. 但是,当我打开该选项时,Mercurial仍然不会让Beyond Compare合并XML文件。

A little more research turns up the premerge option. 更多的研究发现了premerge选项。 When premerge=True , Mercurial merges internally first , and use the merge tool only if there are conflicts to be resolved. premerge=True ,Mercurial 首先在内部进行合并,并且仅在存在要解决的冲突时才使用合并工具。 Unfortunately, Mercurial always fails to merge a binary file. 不幸的是,Mercurial始终无法合并二进制文件。 When a pre-merge fails, Mercurial stops the merge for that file and never launches the merge tool. 当预合并失败时,Mercurial停止该文件的合并,并且从不启动合并工具。

The solution would seem to be, then, to also set the premerge option to False . 因此,解决方案似乎是还将premerge选项设置为False Unfortunately, the pre-merge is very helpful because 90% of the time, there aren't any conflicts, and never see your merge tool. 不幸的是,预合并非常有帮助,因为90%的时间里没有任何冲突,并且从未看到过合并工具。 With premerge set to False , every time a merge is needed, Beyond Compare opens. 将premerge设置为False ,每次需要合并时,就会打开Beyond Compare。 This gets very tedious. 这变得非常乏味。

To solve this, I created a second Beyond Compare merge tool configuration which gets used to merge binary files . 为了解决这个问题, 我创建了第二个Beyond Compare合并工具配置,该配置用于合并二进制文件 I set its priority lower than the default bcomp tool, so it only gets called when the main bcomp tool fails, which is usually just for binary files. 我将其优先级设置为低于默认的bcomp工具,因此只有在主bcomp工具出现故障时才会调用它,通常仅适用于二进制文件。 I added these lines to the merge-tools section of my mercurial.ini file: 我将这些行添加到了mercurial.ini文件的merge-tools部分中:

bcompbin.executable = C:\Program Files (x86)\Beyond Compare 3\BCompare.exe
bcompbin.args = $local $other $base $output
bcompbin.gui = True
bcompbin.premerge = False
bcompbin.binary = True

One of the side-effects of this is that Beyond Compare will launch to merge binary files for which it can't handle. 这样做的副作用之一是,“超越比较”将启动以合并它无法处理的二进制文件。 I haven't encountered that situation yet, so don't know how to handle it. 我还没有遇到这种情况,所以不知道如何处理。 I would probably just temporarily comment out my bcompbin merge tool. 我可能只是暂时注释掉我的bcompbin合并工具。

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

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