git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Testing if a certain commit is in the current branch
@ 2010-01-27  7:19 Frans Pop
  2010-01-27  7:24 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Frans Pop @ 2010-01-27  7:19 UTC (permalink / raw)
  To: git

I'm currently using the following command for this:
   git log --pretty=format:%H | grep -q '^<commit id>"

Problem is that with large repos that can be quite slow.

Is there a faster way to do the test?

TIA,
FJP

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27  7:19 Testing if a certain commit is in the current branch Frans Pop
@ 2010-01-27  7:24 ` Junio C Hamano
  2010-01-27  8:36   ` Frans Pop
  2010-01-27  8:26 ` Matthieu Moy
  2010-01-27  8:56 ` Johannes Schindelin
  2 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2010-01-27  7:24 UTC (permalink / raw)
  To: Frans Pop; +Cc: git

Frans Pop <elendil@planet.nl> writes:

> I'm currently using the following command for this:
>    git log --pretty=format:%H | grep -q '^<commit id>"
>
> Problem is that with large repos that can be quite slow.
>
> Is there a faster way to do the test?

test "$(git merge-base HEAD $commit)" = "$(git rev-parse $commit)"

But this is a literal answer that could be a less than optimal solution if
you are having an XY problem.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27  7:19 Testing if a certain commit is in the current branch Frans Pop
  2010-01-27  7:24 ` Junio C Hamano
@ 2010-01-27  8:26 ` Matthieu Moy
  2010-01-27  8:47   ` Frans Pop
  2010-01-27  8:56 ` Johannes Schindelin
  2 siblings, 1 reply; 12+ messages in thread
From: Matthieu Moy @ 2010-01-27  8:26 UTC (permalink / raw)
  To: Frans Pop; +Cc: git

Frans Pop <elendil@planet.nl> writes:

> I'm currently using the following command for this:
>    git log --pretty=format:%H | grep -q '^<commit id>"
>
> Problem is that with large repos that can be quite slow.
>
> Is there a faster way to do the test?

Not answering the question exactly, but "git branch --contains <commitid>"
does almost this and a bit more.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27  7:24 ` Junio C Hamano
@ 2010-01-27  8:36   ` Frans Pop
  2010-01-27 10:19     ` Jonathan Nieder
  2010-01-27 15:08     ` Petr Baudis
  0 siblings, 2 replies; 12+ messages in thread
From: Frans Pop @ 2010-01-27  8:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Wednesday 27 January 2010, Junio C Hamano wrote:
> Frans Pop <elendil@planet.nl> writes:
> > I'm currently using the following command for this:
> >    git log --pretty=format:%H | grep -q "^<commit id>"
> >
> > Problem is that with large repos that can be quite slow.
> >
> > Is there a faster way to do the test?
>
> test "$(git merge-base HEAD $commit)" = "$(git rev-parse $commit)"

Great! If the commit ID is not present that only takes 1 sec versus 11 secs 
for my test. (If the commit _is_ present and fairly recent my test can be 
faster, but 11 secs delay when it's not present hurts more.)

> But this is a literal answer that could be a less than optimal solution
> if you are having an XY problem.

The use case is a wrapper script for kernel builds in which some variation 
are needed (due to changes in the build system) when building older 
kernels, e.g. during bisections or when building older stable updates.
So I test for the presence of commits that introduced relevant changes.

Thanks again,
FJP

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27  8:26 ` Matthieu Moy
@ 2010-01-27  8:47   ` Frans Pop
  0 siblings, 0 replies; 12+ messages in thread
From: Frans Pop @ 2010-01-27  8:47 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git

On Wednesday 27 January 2010, Matthieu Moy wrote:
> Frans Pop <elendil@planet.nl> writes:
> > I'm currently using the following command for this:
> >    git log --pretty=format:%H | grep -q "^<commit id>"
> >
> > Problem is that with large repos that can be quite slow.
> >
> > Is there a faster way to do the test?
>
> Not answering the question exactly, but "git branch --contains
> <commitid>" does almost this and a bit more.

Thanks. That would work as:
   git branch --contains <commitid> | grep -q "^\*"

It's a lot slower than Junio's solution though (and even slower than my 
original solution).

Cheers,
FJP

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27  7:19 Testing if a certain commit is in the current branch Frans Pop
  2010-01-27  7:24 ` Junio C Hamano
  2010-01-27  8:26 ` Matthieu Moy
@ 2010-01-27  8:56 ` Johannes Schindelin
  2 siblings, 0 replies; 12+ messages in thread
From: Johannes Schindelin @ 2010-01-27  8:56 UTC (permalink / raw)
  To: Frans Pop; +Cc: git

Hi,

On Wed, 27 Jan 2010, Frans Pop wrote:

> I'm currently using the following command for this:
>    git log --pretty=format:%H | grep -q '^<commit id>"
> 
> Problem is that with large repos that can be quite slow.
> 
> Is there a faster way to do the test?

You are more likely looking for "git branch --contains".  But this gives 
you _more_ information.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27  8:36   ` Frans Pop
@ 2010-01-27 10:19     ` Jonathan Nieder
  2010-01-27 13:26       ` Frans Pop
  2010-01-27 15:08     ` Petr Baudis
  1 sibling, 1 reply; 12+ messages in thread
From: Jonathan Nieder @ 2010-01-27 10:19 UTC (permalink / raw)
  To: Frans Pop; +Cc: Junio C Hamano, git

Frans Pop wrote:

> The use case is a wrapper script for kernel builds in which some variation 
> are needed (due to changes in the build system) when building older 
> kernels, e.g. during bisections or when building older stable updates.
> So I test for the presence of commits that introduced relevant changes.

Neat idea.  How about this (untested)?

 git rev-list ^HEAD --no-walk commit1 commit2 ...

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27 10:19     ` Jonathan Nieder
@ 2010-01-27 13:26       ` Frans Pop
  2010-01-27 15:15         ` Dale Farnsworth
  0 siblings, 1 reply; 12+ messages in thread
From: Frans Pop @ 2010-01-27 13:26 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Junio C Hamano, git

On Wednesday 27 January 2010, Jonathan Nieder wrote:
> Frans Pop wrote:
> > The use case is a wrapper script for kernel builds in which some
> > variation are needed (due to changes in the build system) when
> > building older kernels, e.g. during bisections or when building older
> > stable updates. So I test for the presence of commits that introduced
> > relevant changes.
>
> Neat idea.  How about this (untested)?
>
>  git rev-list ^HEAD --no-walk commit1 commit2 ...

Does not seem to work. But I'd be interested if you find a variant that 
does as it's very fast.

Thanks,
FJP

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27  8:36   ` Frans Pop
  2010-01-27 10:19     ` Jonathan Nieder
@ 2010-01-27 15:08     ` Petr Baudis
  2010-01-27 15:27       ` Frans Pop
  1 sibling, 1 reply; 12+ messages in thread
From: Petr Baudis @ 2010-01-27 15:08 UTC (permalink / raw)
  To: Frans Pop; +Cc: Junio C Hamano, git

On Wed, Jan 27, 2010 at 09:36:14AM +0100, Frans Pop wrote:
> On Wednesday 27 January 2010, Junio C Hamano wrote:
> > Frans Pop <elendil@planet.nl> writes:
> > > I'm currently using the following command for this:
> > >    git log --pretty=format:%H | grep -q "^<commit id>"
> > >
> > > Problem is that with large repos that can be quite slow.
> > >
> > > Is there a faster way to do the test?
> >
> > test "$(git merge-base HEAD $commit)" = "$(git rev-parse $commit)"
> 
> Great! If the commit ID is not present that only takes 1 sec versus 11 secs 
> for my test. (If the commit _is_ present and fairly recent my test can be 
> faster, but 11 secs delay when it's not present hurts more.)

Isn't something very wrong if grepping the log output is faster than
simple merge-base call? Can you post exact numbers?

				Petr "Pasky" Baudis

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27 13:26       ` Frans Pop
@ 2010-01-27 15:15         ` Dale Farnsworth
  2010-01-27 15:39           ` Frans Pop
  0 siblings, 1 reply; 12+ messages in thread
From: Dale Farnsworth @ 2010-01-27 15:15 UTC (permalink / raw)
  To: elendil, git

> >  git rev-list ^HEAD --no-walk commit1 commit2 ...
> 
> Does not seem to work. But I'd be interested if you find a variant that 
> does as it's very fast.

I've been using the following.  It produces output only if the commit
is NOT in HEAD.

git rev-list -1 ^HEAD commitID

-Dale

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27 15:08     ` Petr Baudis
@ 2010-01-27 15:27       ` Frans Pop
  0 siblings, 0 replies; 12+ messages in thread
From: Frans Pop @ 2010-01-27 15:27 UTC (permalink / raw)
  To: Petr Baudis; +Cc: Junio C Hamano, git

On Wednesday 27 January 2010, Petr Baudis wrote:
> > Great! If the commit ID is not present that only takes 1 sec versus 11
> > secs for my test. (If the commit _is_ present and fairly recent my
> > test can be faster, but 11 secs delay when it's not present hurts
> > more.)
>
> Isn't something very wrong if grepping the log output is faster than
> simple merge-base call? Can you post exact numbers?

It's only faster if the commit is present very early in the log.
The reason is probably that because of the '-q' option it does not actually 
read the full log, but breaks out as soon as it's found a match.

In my test I had an elapsed time of ~0.5 sec (versus 1 sec for Junio's 
test). And here's a grep for the very first commit:

$ time git log --pretty=format:%H | grep -q 48404cb50b0b547

real    0m0.010s
user    0m0.000s
sys     0m0.012s

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Testing if a certain commit is in the current branch
  2010-01-27 15:15         ` Dale Farnsworth
@ 2010-01-27 15:39           ` Frans Pop
  0 siblings, 0 replies; 12+ messages in thread
From: Frans Pop @ 2010-01-27 15:39 UTC (permalink / raw)
  To: Dale Farnsworth; +Cc: git

On Wednesday 27 January 2010, Dale Farnsworth wrote:
> I've been using the following.  It produces output only if the commit
> is NOT in HEAD.
>
> git rev-list -1 ^HEAD commitID

Nice. That does work.

Returns 0 in both cases and you'd need to allow for nonexisting commit IDs, 
so you'd get:
   test -z "$(git rev-list -1 ^HEAD <commit id> 2>/dev/null)"

Time needed looks to be slightly faster than Junio's test.

Thanks,
FJP

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-01-27 16:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-27  7:19 Testing if a certain commit is in the current branch Frans Pop
2010-01-27  7:24 ` Junio C Hamano
2010-01-27  8:36   ` Frans Pop
2010-01-27 10:19     ` Jonathan Nieder
2010-01-27 13:26       ` Frans Pop
2010-01-27 15:15         ` Dale Farnsworth
2010-01-27 15:39           ` Frans Pop
2010-01-27 15:08     ` Petr Baudis
2010-01-27 15:27       ` Frans Pop
2010-01-27  8:26 ` Matthieu Moy
2010-01-27  8:47   ` Frans Pop
2010-01-27  8:56 ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).