Subject: Re: simple cvs-like git wrapper

From: "Shawn O. Pearce" <[email-masked]>
Date: Thu, 31 Jan 2008 01:01:37 -0500

"Ed S. Peschko" <[email-masked]> wrote:
> > This is going to be slow as you are running git-merge for each
> > and every branch available to you.  You can do a lot better by
> > loading the branch DAG into memory in Perl/C/Python and doing a
> > graph coloring algorithm to see if a merge is necessary or not,
> > as if you are merging everything all of the time almost everything
> > is going to be always merged to everything else.  Which as I said
> > earlier is nuts.
> 
> hmm. Is there a simple method to get this graph? I'm assuming that you
> would have to get all the local commits and compare them to the remote
> commits, and only merge the branches that have commits not yet 
> merged..

Something along these lines:

	%remotes = \
		git for-each-ref \
		--format='%(objname) %(refname)' \
		refs/remotes/origin;

	@lines = \
		git rev-list \
		keys %remotes \
		--not HEAD

	foreach $line in @lines {
		if $remotes contains $line
			git merge $remotes{$line}
	}

That gets you the graph.  The %(objname) string coming back from
for-each-ref is in $line in the loop.  If you see $line inside that
map you built from for-each-ref then that commit isn't yet in the
current branch.  So you'd then want to merge that commit.

-- 
Shawn.