{"thread":{"id":"22406","subject":"Testing if a certain commit is in the current branch","startedAt":"2010-01-27T07:19:39Z","lastAt":"2010-01-27T15:39:43Z","messageCount":12,"participants":["Frans Pop","Junio C Hamano","Matthieu Moy","Johannes Schindelin","Jonathan Nieder","Petr Baudis","Dale Farnsworth"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"132748","messageId":"201001270819.39819.elendil@planet.nl","threadId":"22406","inReplyTo":null,"subject":"Testing if a certain commit is in the current branch","fromName":"Frans Pop","fromEmail":"elendil@planet.nl","sentAt":"2010-01-27T07:19:39Z","receivedAt":"2010-01-27T07:19:39Z","isPatch":false,"sender":{"key":"elendil@planet.nl","avatar":null},"body":"I'm currently using the following command for this:\n   git log --pretty=format:%H | grep -q '^<commit id>\"\n\nProblem is that with large repos that can be quite slow.\n\nIs there a faster way to do the test?\n\nTIA,\nFJP\n"},{"id":"132750","messageId":"7viqaorowo.fsf@alter.siamese.dyndns.org","threadId":"22406","inReplyTo":"201001270819.39819.elendil@planet.nl","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-27T07:24:23Z","receivedAt":"2010-01-27T07:24:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Frans Pop <elendil@planet.nl> writes:\n\n> I'm currently using the following command for this:\n>    git log --pretty=format:%H | grep -q '^<commit id>\"\n>\n> Problem is that with large repos that can be quite slow.\n>\n> Is there a faster way to do the test?\n\ntest \"$(git merge-base HEAD $commit)\" = \"$(git rev-parse $commit)\"\n\nBut this is a literal answer that could be a less than optimal solution if\nyou are having an XY problem.\n"},{"id":"132752","messageId":"vpqiqaonec1.fsf@bauges.imag.fr","threadId":"22406","inReplyTo":"201001270819.39819.elendil@planet.nl","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-01-27T08:26:22Z","receivedAt":"2010-01-27T08:26:22Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Frans Pop <elendil@planet.nl> writes:\n\n> I'm currently using the following command for this:\n>    git log --pretty=format:%H | grep -q '^<commit id>\"\n>\n> Problem is that with large repos that can be quite slow.\n>\n> Is there a faster way to do the test?\n\nNot answering the question exactly, but \"git branch --contains <commitid>\"\ndoes almost this and a bit more.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"132754","messageId":"201001270936.14935.elendil@planet.nl","threadId":"22406","inReplyTo":"7viqaorowo.fsf@alter.siamese.dyndns.org","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Frans Pop","fromEmail":"elendil@planet.nl","sentAt":"2010-01-27T08:36:14Z","receivedAt":"2010-01-27T08:36:14Z","isPatch":false,"sender":{"key":"elendil@planet.nl","avatar":null},"body":"On Wednesday 27 January 2010, Junio C Hamano wrote:\n> Frans Pop <elendil@planet.nl> writes:\n> > I'm currently using the following command for this:\n> >    git log --pretty=format:%H | grep -q \"^<commit id>\"\n> >\n> > Problem is that with large repos that can be quite slow.\n> >\n> > Is there a faster way to do the test?\n>\n> test \"$(git merge-base HEAD $commit)\" = \"$(git rev-parse $commit)\"\n\nGreat! If the commit ID is not present that only takes 1 sec versus 11 secs \nfor my test. (If the commit _is_ present and fairly recent my test can be \nfaster, but 11 secs delay when it's not present hurts more.)\n\n> But this is a literal answer that could be a less than optimal solution\n> if you are having an XY problem.\n\nThe use case is a wrapper script for kernel builds in which some variation \nare needed (due to changes in the build system) when building older \nkernels, e.g. during bisections or when building older stable updates.\nSo I test for the presence of commits that introduced relevant changes.\n\nThanks again,\nFJP\n"},{"id":"132756","messageId":"201001270947.41480.elendil@planet.nl","threadId":"22406","inReplyTo":"vpqiqaonec1.fsf@bauges.imag.fr","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Frans Pop","fromEmail":"elendil@planet.nl","sentAt":"2010-01-27T08:47:40Z","receivedAt":"2010-01-27T08:47:40Z","isPatch":false,"sender":{"key":"elendil@planet.nl","avatar":null},"body":"On Wednesday 27 January 2010, Matthieu Moy wrote:\n> Frans Pop <elendil@planet.nl> writes:\n> > I'm currently using the following command for this:\n> >    git log --pretty=format:%H | grep -q \"^<commit id>\"\n> >\n> > Problem is that with large repos that can be quite slow.\n> >\n> > Is there a faster way to do the test?\n>\n> Not answering the question exactly, but \"git branch --contains\n> <commitid>\" does almost this and a bit more.\n\nThanks. That would work as:\n   git branch --contains <commitid> | grep -q \"^\\*\"\n\nIt's a lot slower than Junio's solution though (and even slower than my \noriginal solution).\n\nCheers,\nFJP\n"},{"id":"132757","messageId":"alpine.DEB.1.00.1001270955350.4985@pacific.mpi-cbg.de","threadId":"22406","inReplyTo":"201001270819.39819.elendil@planet.nl","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-01-27T08:56:01Z","receivedAt":"2010-01-27T08:56:01Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 27 Jan 2010, Frans Pop wrote:\n\n> I'm currently using the following command for this:\n>    git log --pretty=format:%H | grep -q '^<commit id>\"\n> \n> Problem is that with large repos that can be quite slow.\n> \n> Is there a faster way to do the test?\n\nYou are more likely looking for \"git branch --contains\".  But this gives \nyou _more_ information.\n\nCiao,\nDscho\n"},{"id":"132763","messageId":"20100127101943.GA4470@progeny.tock","threadId":"22406","inReplyTo":"201001270936.14935.elendil@planet.nl","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-01-27T10:19:43Z","receivedAt":"2010-01-27T10:19:43Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Frans Pop wrote:\n\n> The use case is a wrapper script for kernel builds in which some variation \n> are needed (due to changes in the build system) when building older \n> kernels, e.g. during bisections or when building older stable updates.\n> So I test for the presence of commits that introduced relevant changes.\n\nNeat idea.  How about this (untested)?\n\n git rev-list ^HEAD --no-walk commit1 commit2 ...\n"},{"id":"132796","messageId":"201001271426.06844.elendil@planet.nl","threadId":"22406","inReplyTo":"20100127101943.GA4470@progeny.tock","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Frans Pop","fromEmail":"elendil@planet.nl","sentAt":"2010-01-27T13:26:05Z","receivedAt":"2010-01-27T13:26:05Z","isPatch":false,"sender":{"key":"elendil@planet.nl","avatar":null},"body":"On Wednesday 27 January 2010, Jonathan Nieder wrote:\n> Frans Pop wrote:\n> > The use case is a wrapper script for kernel builds in which some\n> > variation are needed (due to changes in the build system) when\n> > building older kernels, e.g. during bisections or when building older\n> > stable updates. So I test for the presence of commits that introduced\n> > relevant changes.\n>\n> Neat idea.  How about this (untested)?\n>\n>  git rev-list ^HEAD --no-walk commit1 commit2 ...\n\nDoes not seem to work. But I'd be interested if you find a variant that \ndoes as it's very fast.\n\nThanks,\nFJP\n"},{"id":"132797","messageId":"20100127150834.GG9553@machine.or.cz","threadId":"22406","inReplyTo":"201001270936.14935.elendil@planet.nl","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2010-01-27T15:08:34Z","receivedAt":"2010-01-27T15:08:34Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Wed, Jan 27, 2010 at 09:36:14AM +0100, Frans Pop wrote:\n> On Wednesday 27 January 2010, Junio C Hamano wrote:\n> > Frans Pop <elendil@planet.nl> writes:\n> > > I'm currently using the following command for this:\n> > >    git log --pretty=format:%H | grep -q \"^<commit id>\"\n> > >\n> > > Problem is that with large repos that can be quite slow.\n> > >\n> > > Is there a faster way to do the test?\n> >\n> > test \"$(git merge-base HEAD $commit)\" = \"$(git rev-parse $commit)\"\n> \n> Great! If the commit ID is not present that only takes 1 sec versus 11 secs \n> for my test. (If the commit _is_ present and fairly recent my test can be \n> faster, but 11 secs delay when it's not present hurts more.)\n\nIsn't something very wrong if grepping the log output is faster than\nsimple merge-base call? Can you post exact numbers?\n\n\t\t\t\tPetr \"Pasky\" Baudis\n"},{"id":"132802","messageId":"E1Na9ca-0004x2-Gf@xyzzy.farnsworth.org","threadId":"22406","inReplyTo":"201001271426.06844.elendil@planet.nl","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Dale Farnsworth","fromEmail":"dale@farnsworth.org","sentAt":"2010-01-27T15:15:56Z","receivedAt":"2010-01-27T15:15:56Z","isPatch":false,"sender":{"key":"dale@farnsworth.org","avatar":null},"body":"> >  git rev-list ^HEAD --no-walk commit1 commit2 ...\n> \n> Does not seem to work. But I'd be interested if you find a variant that \n> does as it's very fast.\n\nI've been using the following.  It produces output only if the commit\nis NOT in HEAD.\n\ngit rev-list -1 ^HEAD commitID\n\n-Dale\n"},{"id":"132799","messageId":"201001271627.45715.elendil@planet.nl","threadId":"22406","inReplyTo":"20100127150834.GG9553@machine.or.cz","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Frans Pop","fromEmail":"elendil@planet.nl","sentAt":"2010-01-27T15:27:44Z","receivedAt":"2010-01-27T15:27:44Z","isPatch":false,"sender":{"key":"elendil@planet.nl","avatar":null},"body":"On Wednesday 27 January 2010, Petr Baudis wrote:\n> > Great! If the commit ID is not present that only takes 1 sec versus 11\n> > secs for my test. (If the commit _is_ present and fairly recent my\n> > test can be faster, but 11 secs delay when it's not present hurts\n> > more.)\n>\n> Isn't something very wrong if grepping the log output is faster than\n> simple merge-base call? Can you post exact numbers?\n\nIt's only faster if the commit is present very early in the log.\nThe reason is probably that because of the '-q' option it does not actually \nread the full log, but breaks out as soon as it's found a match.\n\nIn my test I had an elapsed time of ~0.5 sec (versus 1 sec for Junio's \ntest). And here's a grep for the very first commit:\n\n$ time git log --pretty=format:%H | grep -q 48404cb50b0b547\n\nreal    0m0.010s\nuser    0m0.000s\nsys     0m0.012s\n"},{"id":"132798","messageId":"201001271639.44167.elendil@planet.nl","threadId":"22406","inReplyTo":"E1Na9ca-0004x2-Gf@xyzzy.farnsworth.org","subject":"Re: Testing if a certain commit is in the current branch","fromName":"Frans Pop","fromEmail":"elendil@planet.nl","sentAt":"2010-01-27T15:39:43Z","receivedAt":"2010-01-27T15:39:43Z","isPatch":false,"sender":{"key":"elendil@planet.nl","avatar":null},"body":"On Wednesday 27 January 2010, Dale Farnsworth wrote:\n> I've been using the following.  It produces output only if the commit\n> is NOT in HEAD.\n>\n> git rev-list -1 ^HEAD commitID\n\nNice. That does work.\n\nReturns 0 in both cases and you'd need to allow for nonexisting commit IDs, \nso you'd get:\n   test -z \"$(git rev-list -1 ^HEAD <commit id> 2>/dev/null)\"\n\nTime needed looks to be slightly faster than Junio's test.\n\nThanks,\nFJP\n"}]}