Mercurial 每种文件类型的合并策略

发布于 2024-10-16 14:54:01 字数 419 浏览 1 评论 0原文

全部:

我想使用 kdiff 合并具有特定后缀(例如 *.c、*.h)的所有文件,并且我想对具有另一个后缀(例如*.mdl)。这样做的目的是允许我对特定文件类型使用一种“破坏合并”(即:不可合并的文件,如配置、自动生成的 C、模型等。)

在我的 .hgrc 中,我已经尝试过:

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

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

但它仍然会触发所有文件的 kdiff3 。想法?

其扩展是在目录上执行“破坏合并” - 但是一旦文件后缀的语法清晰,目录就应该很容易。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榆西 2024-10-23 14:54:01

合并工具可以使用任何可执行文件。要设置始终用 $other 覆盖 $base 的合并工具,您可以使用以下方法:

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

在 Windows 上使用此策略时,存在一个问题。您不能简单地将 替换为 copy shell 命令。由于某种原因,Mercurial 无法在此上下文中找到 shell 命令。我还没有在 *nix 上尝试过这个。

要解决此问题,您可以创建一个分发执行复制的批处理文件。它只需要运行:copy %1 %2。一旦放置在您的 PATH 中,您就可以设置 clobbermerge.executable=clobber.bat

如果您安装了 kdiff3(Windows 上的 TortoiseHg 附带),则无需使用外部批处理文件,使用如下配置即可获得相同的结果:

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

配置的关键是 args 字段:

  • 此 --auto:告诉kdiff3如果没有冲突就不要打开GUI
  • $base $other $other:告诉kdiff3只使用$other
  • $output:告诉 kdiff3 输出文件的名称

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
撧情箌佬 2024-10-23 14:54:01

根据此 Mercurial MergeToolConfiguration 页面,您应该将 interal:other< /code> 直接在匹配模式之后:

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

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

[merge-patterns]
**.mdl = internal:other
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文