git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jan 9, 2018, 15:17 UTC
Message-ID
<87608bawoa.fsf@evledraar.gmail.com>
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.

Next: Junio C Hamano
Message 1 of 4 in “merge-base --is-ancestor A B is unreasonably slow with unrelated history B”
  1. Ævar Arnfjörð BjarmasonJan 9, 2018
  2. Junio C HamanoJan 9, 2018
  3. Derrick StoleeJan 9, 2018
  4. Ævar Arnfjörð BjarmasonJan 10, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.