Mercurial merge strategy per file type

我的未来我决定 提交于 2019-12-31 01:27:12

问题


All:

I want to use kdiff to merge all files with a certain suffix (say *.c, *.h) and I want to do two things (turn off premerge and use internal:other) for all files with another suffix (say *.mdl). The purpose of this is to allow me to employ a type of 'clobber merge' for a specific file type (ie: un-mergable files like configurations, auto-generated C, models, etc..)

In my .hgrc I've tried:

[merge-tools]
kdiff3=
clobbermerge=internal:other
clobbermerge.premerge = False

[merge-patterns]
**.c = kdiff3
**.h = kdiff3
**.mdl = clobbermerge

but it still triggers kdiff3 for all files. Thoughts?

An extension of this would be to perform a 'clobber merge' on a directory - but once the syntax is clear for a file suffix, the dir should be easy.


回答1:


Merge tools can use any executable file. To set up a merge tool which always overwrites $base with $other, you can use the following:

[merge-tools]
clobbermerge.priority = 100
clobbermerge.premerge = False
clobbermerge.args = $other $output
clobbermerge.executable = <copy executable>

When using this strategy on Windows, there is one problem. You cannot simply replace <copy executable> with the copy shell command. For some reason, Mercurial fails to find shell commands in this context. I have not tried this on *nix.

To work around this problem, you can create a distribute a batch file that performs the copy. It simply needs to run: copy %1 %2. Once placed on your PATH, you can set clobbermerge.executable=clobber.bat.

If you have kdiff3 installed (comes with TortoiseHg on Windows), you can get the same results without the external batch file using a configuration like this:

[merge-tools]
clobbermerge.priority = 100
clobbermerge.premerge = False
clobbermerge.args = --auto $base $other $other -o $output
clobbermerge.executable = kdiff3

The key to this configuration is the args field:

  • --auto: tells kdiff3 not to open the GUI if there are no conflicts
  • $base $other $other: tells kdiff3 to only use $other
  • $output: tells kdiff3 the name of the output file



回答2:


According to this Mercurial MergeToolConfiguration page, you should put the interal:other directly after the match pattern:

[merge-patterns]
**.mdl = internal:other


来源:https://stackoverflow.com/questions/4962810/mercurial-merge-strategy-per-file-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!