How to identify criss cross merges in Git and Mercurial?

I would like to indicate the amount of criss cross merges that exists in some open source Git and Mercurial projects for research purposes only. Any suggestions on how to do this?

Cross crossing can be determined if the merger has two different common ancestors. He is developing a new Mercurial merge strategy called consensus merging , which will extend the code ancestor.ancestor () to bring back all of the largest common ancestors. I could not find this new code yet, but it will help a lot.

I don't know Git enough, but it certainly has something similar.

+4
source share
1 answer

I assume that you want to get the number of cross-cross-merges between any branches in the repository, and not the number of times when two branches were crossed. In this case, the following shell script should be used for Git:

#!/bin/sh # Get the list of branches and convert it to an array. branches=$(git for-each-ref --format='%(refname:short)' refs/heads/) branches=( $branches ) N=${#branches[*]} cc_merges=0 # Loop over all combinations of two branches. for ((i=0; i<N-1; ++i)); do for ((k=i+1; k<N; ++k)); do a=${branches[$i]} b=${branches[$k]} bases=$(git merge-base --all $a $b | wc -l) if [ $bases -gt 1 ]; then let "cc_merges += 1" fi done done echo "Number of criss-cross merges in repository: $cc_merges" 

For Mercurial, both its ancestor() revset and the debugancestor command, unfortunately, only list the most common common ancestor, not a list of all ancestors, so I cannot offer a solution here.

+1
source

All Articles