All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Crabtree, Andrew" <andrew.crabtree@hp.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Plumbing version of 'git branch --contains' ?
Date: Thu, 23 Oct 2014 10:19:22 -0700	[thread overview]
Message-ID: <20141023171921.GA25061@peff.net> (raw)
In-Reply-To: <B82B660D4887C042850326C2BC65FE035D58B11E@G9W0757.americas.hpqcorp.net>

On Wed, Oct 22, 2014 at 08:19:07PM +0000, Crabtree, Andrew wrote:

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

Right. There's some setup work that happens in `git branch --contains`
that we end up repeating.

> 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?

Sadly, no, there isn't currently. The right tool would be `git
for-each-ref --contains`, but it doesn't exist yet. I was working
towards it, but got stopped on factoring out a `--contains` traversal
suitable for both `git tag` and `git branch` (they currently are
different and make performance tradeoffs based on the expected depth of
the merge bases, which is usually different between tags and
branches)[1].  That's work I'd love to resume, but I haven't gotten
around to it yet.

-Peff

[1] http://thread.gmane.org/gmane.comp.version-control.git/252472

  reply	other threads:[~2014-10-23 17:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22 20:19 Plumbing version of 'git branch --contains' ? Crabtree, Andrew
2014-10-23 17:19 ` Jeff King [this message]
2014-10-23 18:07   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141023171921.GA25061@peff.net \
    --to=peff@peff.net \
    --cc=andrew.crabtree@hp.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.