{"thread":{"id":"37784","subject":"Plumbing version of 'git branch --contains' ?","startedAt":"2014-10-22T20:19:07Z","lastAt":"2014-10-23T18:07:13Z","messageCount":3,"participants":["Crabtree, Andrew","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"250976","messageId":"B82B660D4887C042850326C2BC65FE035D58B11E@G9W0757.americas.hpqcorp.net","threadId":"37784","inReplyTo":null,"subject":"Plumbing version of 'git branch --contains' ?","fromName":"Crabtree, Andrew","fromEmail":"andrew.crabtree@hp.com","sentAt":"2014-10-22T20:19:07Z","receivedAt":"2014-10-22T20:19:07Z","isPatch":false,"sender":{"key":"andrew.crabtree@hp.com","avatar":null},"body":"I need to get a list of refs that can reach a certain SHA in in a script.\n\ngit branch --contains SHA \n\nwould be great (runs in ~2 seconds), but not my preferred option for scripting.\n\nI tried\n \nfor br in $(git for-each-ref --format='%(refname:short)' refs/heads/)\ndo\n    git merge-base --is-ancestor $1 ${br}\n    if [ $? -eq 0 ]\n    then\n            echo \"${br}\"\n    fi\ndone\n\nWhich gives me perfect output, but takes 82 seconds to run in my environment.  \n\nIs there an alternative I'm missing to give me the run time performance of 'git branch --contains' but with stable output suitable for parsing?\n\nThanks in advance,\n-Andrew  \n"},{"id":"250984","messageId":"20141023171921.GA25061@peff.net","threadId":"37784","inReplyTo":"B82B660D4887C042850326C2BC65FE035D58B11E@G9W0757.americas.hpqcorp.net","subject":"Re: Plumbing version of 'git branch --contains' ?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-10-23T17:19:22Z","receivedAt":"2014-10-23T17:19:22Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Oct 22, 2014 at 08:19:07PM +0000, Crabtree, Andrew wrote:\n\n> I need to get a list of refs that can reach a certain SHA in in a script.\n> \n> git branch --contains SHA \n> \n> would be great (runs in ~2 seconds), but not my preferred option for scripting.\n> \n> I tried\n>  \n> for br in $(git for-each-ref --format='%(refname:short)' refs/heads/)\n> do\n>     git merge-base --is-ancestor $1 ${br}\n>     if [ $? -eq 0 ]\n>     then\n>             echo \"${br}\"\n>     fi\n> done\n> \n> Which gives me perfect output, but takes 82 seconds to run in my environment.\n\nRight. There's some setup work that happens in `git branch --contains`\nthat we end up repeating.\n\n> Is there an alternative I'm missing to give me the run time\n> performance of 'git branch --contains' but with stable output suitable\n> for parsing?\n\nSadly, no, there isn't currently. The right tool would be `git\nfor-each-ref --contains`, but it doesn't exist yet. I was working\ntowards it, but got stopped on factoring out a `--contains` traversal\nsuitable for both `git tag` and `git branch` (they currently are\ndifferent and make performance tradeoffs based on the expected depth of\nthe merge bases, which is usually different between tags and\nbranches)[1].  That's work I'd love to resume, but I haven't gotten\naround to it yet.\n\n-Peff\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/252472\n"},{"id":"250992","messageId":"xmqqd29islri.fsf@gitster.dls.corp.google.com","threadId":"37784","inReplyTo":"20141023171921.GA25061@peff.net","subject":"Re: Plumbing version of 'git branch --contains' ?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-10-23T18:07:13Z","receivedAt":"2014-10-23T18:07:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Oct 22, 2014 at 08:19:07PM +0000, Crabtree, Andrew wrote:\n>\n>> I need to get a list of refs that can reach a certain SHA in in a script.\n>> \n>> git branch --contains SHA \n>> \n>> would be great (runs in ~2 seconds), but not my preferred option for scripting.\n>> \n>> I tried\n>>  \n>> for br in $(git for-each-ref --format='%(refname:short)' refs/heads/)\n>> do\n>>     git merge-base --is-ancestor $1 ${br}\n>>     if [ $? -eq 0 ]\n>>     then\n>>             echo \"${br}\"\n>>     fi\n>> done\n>> \n>> Which gives me perfect output, but takes 82 seconds to run in my environment.\n>\n> Right. There's some setup work that happens in `git branch --contains`\n> that we end up repeating.\n>\n>> Is there an alternative I'm missing to give me the run time\n>> performance of 'git branch --contains' but with stable output suitable\n>> for parsing?\n>\n> Sadly, no, there isn't currently. The right tool would be `git\n> for-each-ref --contains`, but it doesn't exist yet. I was working\n> towards it, but got stopped on factoring out a `--contains` traversal\n> suitable for both `git tag` and `git branch` (they currently are\n> different and make performance tradeoffs based on the expected depth of\n> the merge bases, which is usually different between tags and\n> branches)[1].  That's work I'd love to resume, but I haven't gotten\n> around to it yet.\n>\n> -Peff\n>\n> [1] http://thread.gmane.org/gmane.comp.version-control.git/252472\n\nThanks for status update.  I was wondering if I should start looking\ninto it myself.\n"}]}