threads / discuss / 17166

jgit merge question

Subject: jgit merge question

## tl;dr

7 messages between Jan 14, 2009 and Jan 15, 2009.

replies: 6people: 3as markdown or json

David Birchfield· Jan 14, 2009, 07:55 UTC · lore
Hi all,

My apologies in advance for the newbie question, and I hope this is the correct forum - please let me know if there is a better place.

I have been working with the JGit library and with the pgm files and other documentation I have been able to implement most of the basic functions that I need for my testing application - including fetch. This is great! However, I have not been able to successfully implement the merge function with JGit. There is some reference to this in the mail archive, but I cannot find any of the merge code that is referenced in the distribution. I have tried to pull from pgm.MergeBase.java, but that hasn't been successful.

My question: Is there any sort of tutorial or reference code snippet that implements merge? Or is there a trick to getting the MergeBase code to achieve a basic merge?

Thanks in advance!

Best, David

Johannes Schindelin· Jan 14, 2009, 10:26 UTC · re: David Birchfield · lore

Re: jgit merge question

Hi,
On Wed, 14 Jan 2009, David Birchfield wrote:
Show 7 quoted lines
> I have been working with the JGit library and with the pgm files and 
> other documentation I have been able to implement most of the basic 
> functions that I need for my testing application - including fetch.  
> This is great!  However, I have not been able to successfully implement 
> the merge function with JGit. There is some reference to this in the 
> mail archive, but I cannot find any of the merge code that is referenced 
> in the distribution.
You mean
http://thread.gmane.org/gmane.comp.version-control.git/100524/focus=100589
?

Yes, it has not been implemented, basically because it needs a diff implementation, and I constantly run out of time working on it. I have something that works, but needs lots of improvements to be usable (basically, it has to avoid deep recursion depths).

Ciao, Dscho

Shawn O. Pearce· Jan 14, 2009, 15:30 UTC · re: Johannes Schindelin · lore

Re: jgit merge question

Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 6 quoted lines
> On Wed, 14 Jan 2009, David Birchfield wrote:
> 
> > I have been working with the JGit library and with the pgm files and 
> > other documentation I have been able to implement most of the basic 
> > functions that I need for my testing application - including fetch.  
> > This is great!
I'm glad JGit has been useful for you.
> > However, I have not been able to successfully implement 
> > the merge function with JGit. There is some reference to this in the 
> > mail archive, but I cannot find any of the merge code that is referenced 
> > in the distribution.

David is probably talking about the 8 patch series I proposed to add a crude merge API to JGit. The patches are available here, based on the current JGit master:

  http://android.git.kernel.org/?p=tools/egit.git;a=shortlog;h=refs/heads/for-gerrit2
  git://android.git.kernel.org/tools/egit.git for-gerrit2

as I'm still highly dependent upon this in Gerrit2, but I haven't been able to fix enough bugs and add enough unit tests to make Robin happy with accepting them into the library. I plan to get back to that as soon as Gerrit2 is live for Android.

That API is a very, very crude merge API. I don't like coding with it from the application level. It doesn't give Gerrit2 enough error information when it fails, and that means any other application will also be unhappy with it.

It also has at least one bug, but at least its a conservative bug (it won't merge subtrees sometimes and aborts even though they should have merged clean). Its also missing a huge block of code about head simplification; that block is in Gerrit2 application code rather than down in the library (that was a mistake in design).

So basically, yea, I've proposed something, but there are some very good reasons why there isn't merge support yet in JGit.

> http://thread.gmane.org/gmane.comp.version-control.git/100524/focus=100589
Yea, we also need the diff implementation so we can do file-level
merges.  That merge API above only does path-level merges.  If a
file is modified on both sides, the merge API I use in Gerrit2
just aborts.  That typically isn't what a human who is trying to
use Git for development wants.
 
> Yes, it has not been implemented, basically because it needs a diff 
> implementation, and I constantly run out of time working on it.  I have 
> something that works, but needs lots of improvements to be usable 
> (basically, it has to avoid deep recursion depths).
What's a little stack space between friends?  ;-)
-- 
Shawn.
David Birchfield· Jan 14, 2009, 22:03 UTC · re: Shawn O. Pearce · lore

RE: jgit merge question

Great - thanks so much for this feedback and link.  My merge needs are straightforward, so hopefully this will suit the need!
I have pulled the latest jgit updates and downloaded the four .java files that are referenced in your link.  I have added these to the directory structure for jgit in the following new folder: org.spearce.jgit/src/org/spearce/jgit/merge/
However, when I try to now make_jgit.sh I am getting a series of errors (pasted below) that appear to stem from not having the same underlying files.  Is it possible that I am not getting the most recent jgit release files?  Or am I misunderstanding how you expect these Merge files to be used?

Thanks again, David

<errors>
Entering org.spearce.jgit ...
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:45: cannot find symbol
symbol  : class UnmergedPathException
location: package org.spearce.jgit.errors
import org.spearce.jgit.errors.UnmergedPathException;
                               ^
./org/spearce/jgit/merge/Merger.java:184: cannot find symbol
symbol  : constructor CanonicalTreeParser(<nulltype>,org.spearce.jgit.lib.Repository,org.spearce.jgit.revwalk.RevTree,org.spearce.jgit.lib.WindowCursor)
location: class org.spearce.jgit.treewalk.CanonicalTreeParser
			return new CanonicalTreeParser(null, db, base.getTree(), curs);
                               ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:98: cannot find symbol
symbol  : method newInCore()
location: class org.spearce.jgit.dircache.DirCache
			cache = DirCache.newInCore();
                                        ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:123: cannot find symbol
symbol  : variable STAGE_0
location: class org.spearce.jgit.dircache.DirCacheEntry
					add(T_THEIRS, DirCacheEntry.STAGE_0);
                                                                   ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:125: cannot find symbol
symbol  : variable STAGE_0
location: class org.spearce.jgit.dircache.DirCacheEntry
					add(T_OURS, DirCacheEntry.STAGE_0);
                                                                 ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:137: cannot find symbol
symbol  : method writeTree(org.spearce.jgit.lib.ObjectWriter)
location: class org.spearce.jgit.dircache.DirCache
				resultTree = cache.writeTree(getObjectWriter());
                                                  ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:139: cannot find symbol
symbol  : class UnmergedPathException
location: class org.spearce.jgit.merge.StrategySimpleTwoWayInCore.InCoreMerger
			} catch (UnmergedPathException upe) {
                                 ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:147: cannot find symbol
symbol  : method getRawPath()
location: class org.spearce.jgit.treewalk.NameConflictTreeWalk
				builder.addTree(tw.getRawPath(), db, tw.getObjectId(1));
                                                  ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:149: cannot find symbol
symbol  : variable STAGE_0
location: class org.spearce.jgit.dircache.DirCacheEntry
				add(T_OURS, DirCacheEntry.STAGE_0);
                                                         ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:153: cannot find symbol
symbol  : variable STAGE_1
location: class org.spearce.jgit.dircache.DirCacheEntry
			add(T_BASE, DirCacheEntry.STAGE_1);
                                                 ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:154: cannot find symbol
symbol  : variable STAGE_2
location: class org.spearce.jgit.dircache.DirCacheEntry
			add(T_OURS, DirCacheEntry.STAGE_2);
                                                 ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:155: cannot find symbol
symbol  : variable STAGE_3
location: class org.spearce.jgit.dircache.DirCacheEntry
			add(T_THEIRS, DirCacheEntry.STAGE_3);
                                                   ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:163: cannot find symbol
symbol  : method getRawPath()
location: class org.spearce.jgit.treewalk.NameConflictTreeWalk
				e = new DirCacheEntry(tw.getRawPath(), stage);
                                                        ^
./org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java:163: internal error; cannot instantiate org.spearce.jgit.dircache.DirCacheEntry.<init> at org.spearce.jgit.dircache.DirCacheEntry to ()
				e = new DirCacheEntry(tw.getRawPath(), stage);
                                    ^
</errors
-----Original Message-----

David is probably talking about the 8 patch series I proposed to add a crude merge API to JGit. The patches are available here, based on the current JGit master:

  http://android.git.kernel.org/?p=tools/egit.git;a=shortlog;h=refs/heads/for-gerrit2
  git://android.git.kernel.org/tools/egit.git for-gerrit2
Shawn O. Pearce· Jan 14, 2009, 23:12 UTC · re: David Birchfield · lore

Re: jgit merge question

David Birchfield <dbirchfield@asu.edu> wrote:
Show 7 quoted lines
> Great - thanks so much for this feedback and link.  My merge
> needs are straightforward, so hopefully this will suit the need!
> 
> I have pulled the latest jgit updates and downloaded the four
> .java files that are referenced in your link.  I have added these
> to the directory structure for jgit in the following new folder:
> org.spearce.jgit/src/org/spearce/jgit/merge/

Instead of copying 4 files, why don't you actually fetch the 8 commits and merge them into your local repository? You are getting build errors because you didn't get an exception type in the errors directory, and at least two existing classes had new methods added to them in order to support the merge API.

-- 
Shawn.
David Birchfield· Jan 15, 2009, 03:47 UTC · re: Shawn O. Pearce · lore

Re: jgit merge question

thanks again for your help, and really sorry for the newbie questions.
how do I grab those 8 commits?

I did originally use git clone on this uri: git:// android.git.kernel.org/tools/egit.git - but I don't see the modifications there.

thanks again, david

On Jan 14, 2009, at 4:12 PM, Shawn O. Pearce wrote:
Show 10 quoted lines
>>
>
> Instead of copying 4 files, why don't you actually fetch the 8
> commits and merge them into your local repository?  You are getting
> build errors because you didn't get an exception type in the errors
> directory, and at least two existing classes had new methods added
> to them in order to support the merge API.
>
> -- 
> Shawn.
Shawn O. Pearce· Jan 15, 2009, 04:01 UTC · re: David Birchfield · lore

Re: jgit merge question

David Birchfield <dbirchfield@asu.edu> wrote:
Show 7 quoted lines
> thanks again for your help, and really sorry for the newbie questions.
>
> how do I grab those 8 commits?
>
> I did originally use git clone on this uri: git:// 
> android.git.kernel.org/tools/egit.git - but I don't see the  
> modifications there.
They are in a side branch:
  git pull git://android.git.kernel.org/tools/egit.git for-gerrit2
-- 
Shawn.

← back to recent threads