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

Plumbing version of 'git branch --contains' ?

From
CACrabtree, Andrew <andrew.crabtree@hp.com>
Date
Oct 22, 2014, 20:19 UTC
Message-ID
<B82B660D4887C042850326C2BC65FE035D58B11E@G9W0757.americas.hpqcorp.net>
I need to get a list of refs that can reach a certain SHA in in a script.
git branch --contains SHA 
would be great (runs in ~2 seconds), but not my preferred option for scripting.
I tried
 
for br in $(git for-each-ref --format='%(refname:short)' refs/heads/)
do
    git merge-base --is-ancestor $1 ${br}
    if [ $? -eq 0 ]
    then
            echo "${br}"
    fi
done
Which gives me perfect output, but takes 82 seconds to run in my environment.  
Is there an alternative I'm missing to give me the run time performance of 'git branch --contains' but with stable output suitable for parsing?

Thanks in advance, -Andrew

Next: Jeff King
Message 1 of 3 in “Plumbing version of 'git branch --contains' ?”
  1. Crabtree, AndrewOct 22, 2014
  2. Jeff KingOct 23, 2014
  3. Junio C HamanoOct 23, 2014

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.