简体   繁体   English

如何在Mercurial存储库中找到所有有冲突的合并?

[英]How can I find all the merges that had conflicts in a Mercurial repository?

I am working on a research to study merges in open source projects. 我正在研究开放源代码项目中的合并。

I recently asked How can I find all the commits that have multiple parents in a Mercurial repository? 我最近问我如何在Mercurial存储库中找到所有具有多个父项的提交? , and got a very good answer. ,得到了很好的答案。

Now I need to narrow my query to only find the commits that had conflicts. 现在,我需要缩小查询范围,以仅查找具有冲突的提交。

With conflicts I mean that the same file was modified in the two contributing commits. 发生冲突时,我的意思是在两个贡献的提交中修改了相同的文件。

Also, it would be very useful if I can find a mercurial or bash (grep, awk?) command that gives me only those commits in which the same line was modified by the two contributors. 另外,如果我可以找到一个Mercurial或bash(grep,awk?)命令,该命令只给我那些由两个贡献者修改了同一行的提交,那将非常有用。

The idea is to find commits that cannot be auto-resolved. 这个想法是找到无法自动解决的提交。

So, How can I find all the merges that had conflicts in a Mercurial repository? 因此,如何找到Mercurial存储库中所有有冲突的合并?

There is no simple way to find these as there is nothing recorded in the merge to indicate whether the merge had conflicts or not. 没有简单的方法可以找到这些,因为在合并中没有记录任何记录来指示合并是否存在冲突。

Note that a file that was modified in two branches does not necessarily constitute a conflict, it will only lead to a conflict if the file is: 请注意,在两个分支中修改的文件不一定构成冲突,只有在以下情况下才会导致冲突:

  1. Unmergeable (ie. binary or similar) 不可合并(即二进制或类似名称)
  2. or, at least one area in the file was changed in both branches 或者,两个分支中文件的至少一个区域已更改

If you change the top of the file in one branch, and the bottom in another, and they are sufficiently far away from each other (usually a couple of lines between changes are enough), then this will merge without a conflict. 如果在一个分支中更改文件的顶部,在另一个分支中更改文件的底部,并且它们之间的距离足够远(通常,更改之间的两行就足够了),那么这将合并而不会发生冲突。

Your only option is to replay each merge that contains a file that was changed in both branches, making a note of which merges that mercurial cannot merge without conflict. 您唯一的选择是重播包含两个分支中都已更改的文件的每个合并,并记下合并,mercurial无法合并而不会发生冲突。

Also, I don't know of any way to use the built-in query syntax to find merges where the same file was changed in both branches. 另外,我不知道有什么方法可以使用内置查询语法查找在两个分支中更改了相同文件的合并。 I think you'll have to go dig in the log yourself (that is, with some code). 我认为您必须自己去挖掘日志(即使用一些代码)。

For each merge revision, you can retrieve the list of changed files, relative to the first and second parent revisions. 对于每个合并修订,您可以检索相对于第一个和第二个父修订版本的已更改文件的列表。 Files that appear in both lists are presumably conflicts. 出现在两个列表中的文件可能是冲突的。

Here's a sample: 这是一个示例:

for rev in $(hg log -r "merge()" --template '{rev}\n'); do
    hg status --rev "p1($rev)" --rev $rev --no-status | sort > /tmp/p1
    hg status --rev "p2($rev)" --rev $rev --no-status | sort > /tmp/p2
    echo Conflicts in $rev:
    comm -1 -2 /tmp/p1 /tmp/p2
done

Note: this probably won't cope with files being renamed. 注意:这可能无法解决文件被重命名的问题。 You could try adding "--copies" to the "hg status" calls. 您可以尝试将“-副本”添加到“汞状态”调用中。

You can use the filters to isolate all merged files and from that their parents. 您可以使用过滤器来隔离所有合并的文件及其父文件。 But you would then need to diff the parents to see if there are any merge conflicts. 但是,然后您需要与父项进行区分,以查看是否存在任何合并冲突。

  1. Yes, you have to replay each merge between merge-parents 是的,您必须重播合并父母之间的每个合并
  2. After merge check return-code of merge 合并后检查合并返回码

Returns 0 on success, 1 if there are unresolved files. 成功返回0,如果有未解决的文件,则返回1。

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

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