I wrote a `git-state` command for this:
https://gitlab.com/mikegerwitz/git-supp/tree/master#git-state
At the very least, it may be useful as a starting point.
While I use it extensively on large projects, I find that the merge commit can do just as well. Of course, that doesn't help you outside context of the merge commit---bisecting, for example---unless you are okay with discovering the merge commit that introduced it into the mainline. That can still be scripted.