git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* finding unmerged branches
@ 2009-08-27 22:02 Joey Hess
  2009-08-27 22:22 ` Avery Pennarun
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Joey Hess @ 2009-08-27 22:02 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1143 bytes --]

My situation is this: My project has a lot of remotes with
lots of branches; about 250 branches in total. I want to
figure out which of these branches to look at to consider
merging.

So, I reach for git branch -a --no-merged master; that's what
its man page says its for. But this still finds 120 branches,
and a lot of them are not things I want to look at. Many of
them are copies of some of my own branches.

What I really want is a way to find remote branches that
are not merged with any of my local branches (or any origin
branches). A slow and stupid implementation of that is in the
attached git-unmerged script, and it weeds the branch list
down to 68 branches, which are mostly really ones I might
want to look at.

So, three questions:

* Is this situation somewhat common, or an I doing something wrong?
  (Assuming that I have a good reason to want to look at remote 
  branches rather than waiting to get merge requests.)
* Is there a better way to accomplish this than a slow perl script that
  runs git branch -r --merged foreach of my branches?
* Should git have something builtin to handle this case better?

-- 
see shy jo

[-- Attachment #2: git-unmerged --]
[-- Type: text/plain, Size: 582 bytes --]

#!/usr/bin/perl

my @remote_branches = split ' ', `git branch -r | awk '{print $1}'`;

# have to filter out the "* "
my @local_branches = split ' ', `git branch | sed 's/^..//'`;

my @origin_branches = grep /^origin\//, @remote_branches;

my %unmerged = (map { $_ => 1 } @remote_branches),
	(map { $_ => 0 } @local_branches, @origin_branches);

foreach my $branch (@local_branches, @origin_branches) {
	map { $unmerged{$_}=0 } split ' ', `git branch -r --merged "$branch" | awk '{print $1}'`
}

foreach my $branch (sort keys %unmerged) {
	print "$branch\n" if $unmerged{$branch};
}

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

* Re: finding unmerged branches
  2009-08-27 22:02 finding unmerged branches Joey Hess
@ 2009-08-27 22:22 ` Avery Pennarun
  2009-08-28  0:54   ` Joey Hess
  2009-08-27 22:35 ` Björn Steinbrink
  2009-08-28  2:08 ` Joey Hess
  2 siblings, 1 reply; 7+ messages in thread
From: Avery Pennarun @ 2009-08-27 22:22 UTC (permalink / raw)
  To: Joey Hess; +Cc: git

On Thu, Aug 27, 2009 at 10:02 PM, Joey Hess<joey@kitenet.net> wrote:
> What I really want is a way to find remote branches that
> are not merged with any of my local branches (or any origin
> branches). A slow and stupid implementation of that is in the
> attached git-unmerged script, and it weeds the branch list
> down to 68 branches, which are mostly really ones I might
> want to look at.

How about:

gitk $(git for-each-ref --format='%(refname)' 'refs/remotes/'; git
for-each-ref --format='^%(refname)' 'refs/heads/')

You could also replace 'gitk' with 'git log', and mess with the
--pretty=format:whatever parameter.

Have fun,

Avery

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

* Re: finding unmerged branches
  2009-08-27 22:02 finding unmerged branches Joey Hess
  2009-08-27 22:22 ` Avery Pennarun
@ 2009-08-27 22:35 ` Björn Steinbrink
  2009-08-27 23:25   ` Junio C Hamano
  2009-08-28  0:44   ` Joey Hess
  2009-08-28  2:08 ` Joey Hess
  2 siblings, 2 replies; 7+ messages in thread
From: Björn Steinbrink @ 2009-08-27 22:35 UTC (permalink / raw)
  To: Joey Hess; +Cc: git

On 2009.08.27 18:02:41 -0400, Joey Hess wrote:
> My situation is this: My project has a lot of remotes with
> lots of branches; about 250 branches in total. I want to
> figure out which of these branches to look at to consider
> merging.
> 
> So, I reach for git branch -a --no-merged master; that's what
> its man page says its for. But this still finds 120 branches,
> and a lot of them are not things I want to look at. Many of
> them are copies of some of my own branches.
> 
> What I really want is a way to find remote branches that
> are not merged with any of my local branches (or any origin
> branches). A slow and stupid implementation of that is in the
> attached git-unmerged script, and it weeds the branch list
> down to 68 branches, which are mostly really ones I might
> want to look at.
> 
> So, three questions:
> 
> * Is this situation somewhat common, or an I doing something wrong?
>   (Assuming that I have a good reason to want to look at remote 
>   branches rather than waiting to get merge requests.)
> * Is there a better way to accomplish this than a slow perl script that
>   runs git branch -r --merged foreach of my branches?

Hm, not sure if I'd call it "better", but probably at least a bit
faster. You could create a "fake" merge to combine all the branches.

git branch -r --no-merged $(
  : | git commit-tree HEAD^{tree} $(
    git for-each-ref --format='-p %(refname)' \
      refs/heads/ \
      refs/remotes/origin
    )
  )

Björn

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

* Re: finding unmerged branches
  2009-08-27 22:35 ` Björn Steinbrink
@ 2009-08-27 23:25   ` Junio C Hamano
  2009-08-28  0:44   ` Joey Hess
  1 sibling, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2009-08-27 23:25 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: Joey Hess, git

Björn Steinbrink <B.Steinbrink@gmx.de> writes:

> Hm, not sure if I'd call it "better", but probably at least a bit
> faster. You could create a "fake" merge to combine all the branches.
>
> git branch -r --no-merged $(
>   : | git commit-tree HEAD^{tree} $(
>     git for-each-ref --format='-p %(refname)' \
>       refs/heads/ \
>       refs/remotes/origin
>     )
>   )

Heh, that is certainly a cute hack ;-)

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

* Re: finding unmerged branches
  2009-08-27 22:35 ` Björn Steinbrink
  2009-08-27 23:25   ` Junio C Hamano
@ 2009-08-28  0:44   ` Joey Hess
  1 sibling, 0 replies; 7+ messages in thread
From: Joey Hess @ 2009-08-28  0:44 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

Björn Steinbrink wrote:
> Hm, not sure if I'd call it "better", but probably at least a bit
> faster. You could create a "fake" merge to combine all the branches.
> 
> git branch -r --no-merged $(
>   : | git commit-tree HEAD^{tree} $(
>     git for-each-ref --format='-p %(refname)' \
>       refs/heads/ \
>       refs/remotes/origin
>     )
>   )

That does run fast. Has some warnings about duplicate parents. The gitk
method seems more useful.

-- 
see shy jo

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: finding unmerged branches
  2009-08-27 22:22 ` Avery Pennarun
@ 2009-08-28  0:54   ` Joey Hess
  0 siblings, 0 replies; 7+ messages in thread
From: Joey Hess @ 2009-08-28  0:54 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

Avery Pennarun wrote:
> How about:
> 
> gitk $(git for-each-ref --format='%(refname)' 'refs/remotes/'; git
> for-each-ref --format='^%(refname)' 'refs/heads/')
> 
> You could also replace 'gitk' with 'git log', and mess with the
> --pretty=format:whatever parameter.

I added 'refs/remotes/origin/' 'refs/tags/' to the list, and that's
almost perfect, thanks.

Though there was one remote branch where gitk showed a lot of commits
from origin/master before the unmerged changes in the branch. Could not
figure out why, git log doesn't show them.

-- 
see shy jo

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: finding unmerged branches
  2009-08-27 22:02 finding unmerged branches Joey Hess
  2009-08-27 22:22 ` Avery Pennarun
  2009-08-27 22:35 ` Björn Steinbrink
@ 2009-08-28  2:08 ` Joey Hess
  2 siblings, 0 replies; 7+ messages in thread
From: Joey Hess @ 2009-08-28  2:08 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 343 bytes --]

Joey Hess wrote:
> * Is this situation somewhat common, or an I doing something wrong?
>   (Assuming that I have a good reason to want to look at remote 
>   branches rather than waiting to get merge requests.)

Come to think, the github fork queue serves basically the same purpose,
but only for branches in github.

-- 
see shy jo

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2009-08-28  2:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-27 22:02 finding unmerged branches Joey Hess
2009-08-27 22:22 ` Avery Pennarun
2009-08-28  0:54   ` Joey Hess
2009-08-27 22:35 ` Björn Steinbrink
2009-08-27 23:25   ` Junio C Hamano
2009-08-28  0:44   ` Joey Hess
2009-08-28  2:08 ` Joey Hess

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