git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* `Git Status`-like output for two local branches
@ 2009-08-31 20:20 Tim Visher
  2009-09-02  7:57 ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Tim Visher @ 2009-08-31 20:20 UTC (permalink / raw)
  To: Git Mailing List

Hello Everyone,

I'm interested in being able to get a message such as 'dev and master
have diverged, having 1 and 2 commits different respectively' or 'dev
is behind master by 3 commits and can be fast-forwarded', etc.  I'm
sure this is simple, but I can't figure out how to do it in the docs.
Sorry for the noobness of the question.

Thanks!

-- 

In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail

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

* Re: `Git Status`-like output for two local branches
  2009-08-31 20:20 `Git Status`-like output for two local branches Tim Visher
@ 2009-09-02  7:57 ` Jeff King
  2009-09-02  8:18   ` Sverre Rabbelier
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2009-09-02  7:57 UTC (permalink / raw)
  To: Tim Visher; +Cc: Git Mailing List

On Mon, Aug 31, 2009 at 04:20:47PM -0400, Tim Visher wrote:

> I'm interested in being able to get a message such as 'dev and master
> have diverged, having 1 and 2 commits different respectively' or 'dev
> is behind master by 3 commits and can be fast-forwarded', etc.  I'm
> sure this is simple, but I can't figure out how to do it in the docs.
> Sorry for the noobness of the question.

No, there isn't a simple command to say "show me this status text for
these two arbitrary branches".

However, the process is relatively simple to implement in a shell
script:

  1. Pick your two branches. I'm not clear on whether you want to
     compare two arbitrary branches, or what.

     For the regular "status", one is the current branch, and the other
     is the "upstream" branch (as configured by your
     branch.$current.merge variables). Calculating "upstream" can
     actually be a bit tricky because it involves looking at several
     configuraiton variables. However, recent versions of git allow this
     shell snippet (the 'upstream' formatter was added in v1.6.3):

       current=`git symbolic-ref HEAD`
       upstream=`git for-each-ref --format='%(upstream)' $current`

  2. Count the commits on each side that are not in the other. The
     simplest way to do this is:

       in_a=`git rev-list $b..$a -- | wc -l`
       in_b=`git rev-list $a..$b -- | wc -l`

     but the internal code actually does both traversals simultaneously,
     which is slightly more efficient.  You can also do that by parsing
     the output of:

       git rev-list --left-right $a...$b --

      which will mark commits in "a" with a '<' and commits in "b" with
      a '>'. I don't know whether the extra complexity is worth the
      efficiency gain (in the internal code it is easier, since we
      aren't actually generating output and parsing it; we just keep a
      count).

  3. Compare the counts. If:

       a=0, b=0: they are the same commit
       a=0, b>0: a is behind b by $b commits, and can be fast-forwarded
       a>0, b=0: a is ahead of b by $a commits (and can be pushed, or b
                 can be fast-forwarded to a)
       a>0, b>0: branches have diverged and have $a and $b commits
                 respectively

So it's easy to script, but not exactly a one-liner. We might be able to
do better if you reduce the problem space. What exactly are you trying
to accomplish?

-Peff

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

* Re: `Git Status`-like output for two local branches
  2009-09-02  7:57 ` Jeff King
@ 2009-09-02  8:18   ` Sverre Rabbelier
  2009-09-05  8:17     ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Sverre Rabbelier @ 2009-09-02  8:18 UTC (permalink / raw)
  To: Jeff King; +Cc: Tim Visher, Git Mailing List

Heya,

On Wed, Sep 2, 2009 at 09:57, Jeff King<peff@peff.net> wrote:
>  2. Count the commits on each side that are not in the other.

[...]

>      You can also do that by parsing the output of:
>       git rev-list --left-right $a...$b --

Perhaps it is useful to introduce a --left-right-count or such?

-- 
Cheers,

Sverre Rabbelier

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

* Re: `Git Status`-like output for two local branches
  2009-09-02  8:18   ` Sverre Rabbelier
@ 2009-09-05  8:17     ` Jeff King
  2009-09-05 14:58       ` demerphq
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2009-09-05  8:17 UTC (permalink / raw)
  To: Sverre Rabbelier; +Cc: Tim Visher, Git Mailing List

On Wed, Sep 02, 2009 at 10:18:54AM +0200, Sverre Rabbelier wrote:

> On Wed, Sep 2, 2009 at 09:57, Jeff King<peff@peff.net> wrote:
> >  2. Count the commits on each side that are not in the other.
> 
> [...]
> 
> >      You can also do that by parsing the output of:
> >       git rev-list --left-right $a...$b --
> 
> Perhaps it is useful to introduce a --left-right-count or such?

I'm not opposed to that if it is something a lot of people found useful,
but I am not sure we have established that as the case (I am curious to
hear from Tim what his actual use case is).

-Peff

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

* Re: `Git Status`-like output for two local branches
  2009-09-05  8:17     ` Jeff King
@ 2009-09-05 14:58       ` demerphq
  2009-09-09 12:26         ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: demerphq @ 2009-09-05 14:58 UTC (permalink / raw)
  To: Jeff King; +Cc: Sverre Rabbelier, Tim Visher, Git Mailing List

2009/9/5 Jeff King <peff@peff.net>:
> On Wed, Sep 02, 2009 at 10:18:54AM +0200, Sverre Rabbelier wrote:
>
>> On Wed, Sep 2, 2009 at 09:57, Jeff King<peff@peff.net> wrote:
>> >  2. Count the commits on each side that are not in the other.
>>
>> [...]
>>
>> >      You can also do that by parsing the output of:
>> >       git rev-list --left-right $a...$b --
>>
>> Perhaps it is useful to introduce a --left-right-count or such?
>
> I'm not opposed to that if it is something a lot of people found useful,
> but I am not sure we have established that as the case (I am curious to
> hear from Tim what his actual use case is).

It would be useful in for instance prompt status line. At $work we
have a number of people using a prompt that includes the result of
parsing git-status, but something --left-right-count would be much
nicer, and if i understand it, more efficient (although maybe im
wrong). In the prompt they use a number of different unicode arrows to
show what has happened, with a Y type thing for diverged.

cheers,
Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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

* Re: `Git Status`-like output for two local branches
  2009-09-05 14:58       ` demerphq
@ 2009-09-09 12:26         ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2009-09-09 12:26 UTC (permalink / raw)
  To: demerphq; +Cc: Sverre Rabbelier, Tim Visher, Git Mailing List

On Sat, Sep 05, 2009 at 04:58:36PM +0200, demerphq wrote:

> It would be useful in for instance prompt status line. At $work we
> have a number of people using a prompt that includes the result of
> parsing git-status, but something --left-right-count would be much
> nicer, and if i understand it, more efficient (although maybe im
> wrong). In the prompt they use a number of different unicode arrows to
> show what has happened, with a Y type thing for diverged.

Well, if they are using the other bits of "git status" then it may not
be that inefficient compared to a "--left-right-count".

However, it sounds like they are not actually interested in the count,
but just the two bits of information: is A ahead of B, and is B ahead of
A (and then displaying one of four symbols as a result).

And getting that information is even more efficient than just a count,
because you don't have to traverse all of the commits. Though you do
still have to find the merge base, so I'm not sure how much you would be
saving in practice.

A "--left-right-count" does feel like an odd option to "git log" or "git
rev-list", as you are no longer logging or listing anything. In a way,
it makes more sense to me as a special output format of "git
merge-base".

Anyway, I think your example sounds like a reasonable application.
Personally, I do not use a git-enhanced prompt, so it is not my itch to
scratch (and I think a plumbing patch would only make sense if it was a
stepping stone to an actual application, which means somebody needs to
write the actual application).

-Peff

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

end of thread, other threads:[~2009-09-09 12:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-31 20:20 `Git Status`-like output for two local branches Tim Visher
2009-09-02  7:57 ` Jeff King
2009-09-02  8:18   ` Sverre Rabbelier
2009-09-05  8:17     ` Jeff King
2009-09-05 14:58       ` demerphq
2009-09-09 12:26         ` Jeff King

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).