Subject: merge-base --is-ancestor A B is unreasonably slow with unrelated history B

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Tue, 09 Jan 2018 16:17:41 +0100

This is a pathological case I don't have time to dig into right now:

    git branch -D orphan;
    git checkout --orphan orphan &&
    git reset --hard &&
    touch foo &&
    git add foo &&
    git commit -m"foo" &&
    time git merge-base --is-ancestor master orphan

This takes around 5 seconds on linux.git to return 1. Which is around
the same time it takes to run current master against the first commit in
linux.git:

    git merge-base --is-ancestor 1da177e4c3f4 master

This is obviously a pathological case, but maybe we should work slightly
harder on the RHS of and discover that it itself is an orphan commit.

I ran into this while writing a hook where we'd like to do:

    git diff $master...topic

Or not, depending on if the topic is an orphan or just something
recently branched off, figured I could use --is-ancestor as on
optimization, and then discovered it's not much of an optimization.