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
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.
source share