{"thread":{"id":"20802","subject":"`Git Status`-like output for two local branches","startedAt":"2009-08-31T20:20:47Z","lastAt":"2009-09-09T12:26:02Z","messageCount":6,"participants":["Tim Visher","Jeff King","Sverre Rabbelier","demerphq"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"122202","messageId":"c115fd3c0908311320q46d585d2v457ccd0f411a6404@mail.gmail.com","threadId":"20802","inReplyTo":null,"subject":"`Git Status`-like output for two local branches","fromName":"Tim Visher","fromEmail":"tim.visher@gmail.com","sentAt":"2009-08-31T20:20:47Z","receivedAt":"2009-08-31T20:20:47Z","isPatch":false,"sender":{"key":"tim.visher@gmail.com","avatar":"https://gravatar.com/avatar/98307ce54bcac1a46b5d845827d5386e2a27895ff08790cdd3877ad527760575?d=mp&s=160"},"body":"Hello Everyone,\n\nI'm interested in being able to get a message such as 'dev and master\nhave diverged, having 1 and 2 commits different respectively' or 'dev\nis behind master by 3 commits and can be fast-forwarded', etc.  I'm\nsure this is simple, but I can't figure out how to do it in the docs.\nSorry for the noobness of the question.\n\nThanks!\n\n-- \n\nIn Christ,\n\nTimmy V.\n\nhttp://burningones.com/\nhttp://five.sentenc.es/ - Spend less time on e-mail\n"},{"id":"122296","messageId":"20090902075713.GA1832@coredump.intra.peff.net","threadId":"20802","inReplyTo":"c115fd3c0908311320q46d585d2v457ccd0f411a6404@mail.gmail.com","subject":"Re: `Git Status`-like output for two local branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-09-02T07:57:13Z","receivedAt":"2009-09-02T07:57:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Aug 31, 2009 at 04:20:47PM -0400, Tim Visher wrote:\n\n> I'm interested in being able to get a message such as 'dev and master\n> have diverged, having 1 and 2 commits different respectively' or 'dev\n> is behind master by 3 commits and can be fast-forwarded', etc.  I'm\n> sure this is simple, but I can't figure out how to do it in the docs.\n> Sorry for the noobness of the question.\n\nNo, there isn't a simple command to say \"show me this status text for\nthese two arbitrary branches\".\n\nHowever, the process is relatively simple to implement in a shell\nscript:\n\n  1. Pick your two branches. I'm not clear on whether you want to\n     compare two arbitrary branches, or what.\n\n     For the regular \"status\", one is the current branch, and the other\n     is the \"upstream\" branch (as configured by your\n     branch.$current.merge variables). Calculating \"upstream\" can\n     actually be a bit tricky because it involves looking at several\n     configuraiton variables. However, recent versions of git allow this\n     shell snippet (the 'upstream' formatter was added in v1.6.3):\n\n       current=`git symbolic-ref HEAD`\n       upstream=`git for-each-ref --format='%(upstream)' $current`\n\n  2. Count the commits on each side that are not in the other. The\n     simplest way to do this is:\n\n       in_a=`git rev-list $b..$a -- | wc -l`\n       in_b=`git rev-list $a..$b -- | wc -l`\n\n     but the internal code actually does both traversals simultaneously,\n     which is slightly more efficient.  You can also do that by parsing\n     the output of:\n\n       git rev-list --left-right $a...$b --\n\n      which will mark commits in \"a\" with a '<' and commits in \"b\" with\n      a '>'. I don't know whether the extra complexity is worth the\n      efficiency gain (in the internal code it is easier, since we\n      aren't actually generating output and parsing it; we just keep a\n      count).\n\n  3. Compare the counts. If:\n\n       a=0, b=0: they are the same commit\n       a=0, b>0: a is behind b by $b commits, and can be fast-forwarded\n       a>0, b=0: a is ahead of b by $a commits (and can be pushed, or b\n                 can be fast-forwarded to a)\n       a>0, b>0: branches have diverged and have $a and $b commits\n                 respectively\n\nSo it's easy to script, but not exactly a one-liner. We might be able to\ndo better if you reduce the problem space. What exactly are you trying\nto accomplish?\n\n-Peff\n"},{"id":"122299","messageId":"fabb9a1e0909020118m2fe2e6e1g79cc83ce941ac000@mail.gmail.com","threadId":"20802","inReplyTo":"20090902075713.GA1832@coredump.intra.peff.net","subject":"Re: `Git Status`-like output for two local branches","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-09-02T08:18:54Z","receivedAt":"2009-09-02T08:18:54Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Sep 2, 2009 at 09:57, Jeff King<peff@peff.net> wrote:\n>  2. Count the commits on each side that are not in the other.\n\n[...]\n\n>      You can also do that by parsing the output of:\n>       git rev-list --left-right $a...$b --\n\nPerhaps it is useful to introduce a --left-right-count or such?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"122494","messageId":"20090905081726.GA7109@coredump.intra.peff.net","threadId":"20802","inReplyTo":"fabb9a1e0909020118m2fe2e6e1g79cc83ce941ac000@mail.gmail.com","subject":"Re: `Git Status`-like output for two local branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-09-05T08:17:26Z","receivedAt":"2009-09-05T08:17:26Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 02, 2009 at 10:18:54AM +0200, Sverre Rabbelier wrote:\n\n> On Wed, Sep 2, 2009 at 09:57, Jeff King<peff@peff.net> wrote:\n> >  2. Count the commits on each side that are not in the other.\n> \n> [...]\n> \n> >      You can also do that by parsing the output of:\n> >       git rev-list --left-right $a...$b --\n> \n> Perhaps it is useful to introduce a --left-right-count or such?\n\nI'm not opposed to that if it is something a lot of people found useful,\nbut I am not sure we have established that as the case (I am curious to\nhear from Tim what his actual use case is).\n\n-Peff\n"},{"id":"122520","messageId":"9b18b3110909050758k597f917fn3baefa5fdb4741a0@mail.gmail.com","threadId":"20802","inReplyTo":"20090905081726.GA7109@coredump.intra.peff.net","subject":"Re: `Git Status`-like output for two local branches","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2009-09-05T14:58:36Z","receivedAt":"2009-09-05T14:58:36Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"2009/9/5 Jeff King <peff@peff.net>:\n> On Wed, Sep 02, 2009 at 10:18:54AM +0200, Sverre Rabbelier wrote:\n>\n>> On Wed, Sep 2, 2009 at 09:57, Jeff King<peff@peff.net> wrote:\n>> >  2. Count the commits on each side that are not in the other.\n>>\n>> [...]\n>>\n>> >      You can also do that by parsing the output of:\n>> >       git rev-list --left-right $a...$b --\n>>\n>> Perhaps it is useful to introduce a --left-right-count or such?\n>\n> I'm not opposed to that if it is something a lot of people found useful,\n> but I am not sure we have established that as the case (I am curious to\n> hear from Tim what his actual use case is).\n\nIt would be useful in for instance prompt status line. At $work we\nhave a number of people using a prompt that includes the result of\nparsing git-status, but something --left-right-count would be much\nnicer, and if i understand it, more efficient (although maybe im\nwrong). In the prompt they use a number of different unicode arrows to\nshow what has happened, with a Y type thing for diverged.\n\ncheers,\nYves\n\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"122759","messageId":"20090909122602.GA31208@coredump.intra.peff.net","threadId":"20802","inReplyTo":"9b18b3110909050758k597f917fn3baefa5fdb4741a0@mail.gmail.com","subject":"Re: `Git Status`-like output for two local branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-09-09T12:26:02Z","receivedAt":"2009-09-09T12:26:02Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Sep 05, 2009 at 04:58:36PM +0200, demerphq wrote:\n\n> It would be useful in for instance prompt status line. At $work we\n> have a number of people using a prompt that includes the result of\n> parsing git-status, but something --left-right-count would be much\n> nicer, and if i understand it, more efficient (although maybe im\n> wrong). In the prompt they use a number of different unicode arrows to\n> show what has happened, with a Y type thing for diverged.\n\nWell, if they are using the other bits of \"git status\" then it may not\nbe that inefficient compared to a \"--left-right-count\".\n\nHowever, it sounds like they are not actually interested in the count,\nbut just the two bits of information: is A ahead of B, and is B ahead of\nA (and then displaying one of four symbols as a result).\n\nAnd getting that information is even more efficient than just a count,\nbecause you don't have to traverse all of the commits. Though you do\nstill have to find the merge base, so I'm not sure how much you would be\nsaving in practice.\n\nA \"--left-right-count\" does feel like an odd option to \"git log\" or \"git\nrev-list\", as you are no longer logging or listing anything. In a way,\nit makes more sense to me as a special output format of \"git\nmerge-base\".\n\nAnyway, I think your example sounds like a reasonable application.\nPersonally, I do not use a git-enhanced prompt, so it is not my itch to\nscratch (and I think a plumbing patch would only make sense if it was a\nstepping stone to an actual application, which means somebody needs to\nwrite the actual application).\n\n-Peff\n"}]}