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
threads / discuss / 22406
Subject: Testing if a certain commit is in the current branch
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
Re: Testing if a certain commit is in the current branch
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.
Re: Testing if a certain commit is in the current branch
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
Re: Testing if a certain commit is in the current branch
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 ...
Re: Testing if a certain commit is in the current branch
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
Re: Testing if a certain commit is in the current branch
> > 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
Re: Testing if a certain commit is in the current branch
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
Re: Testing if a certain commit is in the current branch
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
Re: Testing if a certain commit is in the current branch
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
Re: Testing if a certain commit is in the current branch
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/
Re: Testing if a certain commit is in the current branch
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
Re: Testing if a certain commit is in the current branch
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