@ -44,7 +44,9 @@
package org.eclipse.jgit.merge ;
import java.io.ByteArrayInputStream ;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB ;
import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT ;
import java.io.IOException ;
import org.eclipse.jgit.dircache.DirCache ;
@ -54,7 +56,7 @@ import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.FileMode ;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.ObjectWri ter ;
import org.eclipse.jgit.lib.ObjectInser ter ;
import org.eclipse.jgit.lib.PersonIdent ;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase ;
import org.eclipse.jgit.treewalk.TreeWalk ;
@ -126,7 +128,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t . finish ( ) ;
}
final ObjectWriter ow = new ObjectWriter ( db ) ;
final ObjectInserter ow = db . newObjectInserter ( ) ;
final ObjectId b = commit ( ow , treeB , new ObjectId [ ] { } ) ;
final ObjectId o = commit ( ow , treeO , new ObjectId [ ] { b } ) ;
final ObjectId t = commit ( ow , treeT , new ObjectId [ ] { b } ) ;
@ -177,7 +179,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t . finish ( ) ;
}
final ObjectWriter ow = new ObjectWriter ( db ) ;
final ObjectInserter ow = db . newObjectInserter ( ) ;
final ObjectId b = commit ( ow , treeB , new ObjectId [ ] { } ) ;
final ObjectId o = commit ( ow , treeO , new ObjectId [ ] { b } ) ;
final ObjectId t = commit ( ow , treeT , new ObjectId [ ] { b } ) ;
@ -224,7 +226,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t . finish ( ) ;
}
final ObjectWriter ow = new ObjectWriter ( db ) ;
final ObjectInserter ow = db . newObjectInserter ( ) ;
final ObjectId b = commit ( ow , treeB , new ObjectId [ ] { } ) ;
final ObjectId o = commit ( ow , treeO , new ObjectId [ ] { b } ) ;
final ObjectId t = commit ( ow , treeT , new ObjectId [ ] { b } ) ;
@ -256,7 +258,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t . finish ( ) ;
}
final ObjectWriter ow = new ObjectWriter ( db ) ;
final ObjectInserter ow = db . newObjectInserter ( ) ;
final ObjectId b = commit ( ow , treeB , new ObjectId [ ] { } ) ;
final ObjectId o = commit ( ow , treeO , new ObjectId [ ] { b } ) ;
final ObjectId t = commit ( ow , treeT , new ObjectId [ ] { b } ) ;
@ -288,7 +290,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t . finish ( ) ;
}
final ObjectWriter ow = new ObjectWriter ( db ) ;
final ObjectInserter ow = db . newObjectInserter ( ) ;
final ObjectId b = commit ( ow , treeB , new ObjectId [ ] { } ) ;
final ObjectId o = commit ( ow , treeO , new ObjectId [ ] { b } ) ;
final ObjectId t = commit ( ow , treeT , new ObjectId [ ] { b } ) ;
@ -318,7 +320,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t . finish ( ) ;
}
final ObjectWriter ow = new ObjectWriter ( db ) ;
final ObjectInserter ow = db . newObjectInserter ( ) ;
final ObjectId b = commit ( ow , treeB , new ObjectId [ ] { } ) ;
final ObjectId o = commit ( ow , treeO , new ObjectId [ ] { b } ) ;
final ObjectId t = commit ( ow , treeT , new ObjectId [ ] { b } ) ;
@ -348,7 +350,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t . finish ( ) ;
}
final ObjectWriter ow = new ObjectWriter ( db ) ;
final ObjectInserter ow = db . newObjectInserter ( ) ;
final ObjectId b = commit ( ow , treeB , new ObjectId [ ] { } ) ;
final ObjectId o = commit ( ow , treeO , new ObjectId [ ] { b } ) ;
final ObjectId t = commit ( ow , treeT , new ObjectId [ ] { b } ) ;
@ -363,15 +365,17 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
. getObjectId ( 0 ) ) ;
}
private ObjectId commit ( final ObjectWriter ow , final DirCache treeB ,
private ObjectId commit ( final ObjectInserter odi , final DirCache treeB ,
final ObjectId [ ] parentIds ) throws Exception {
final Commit c = new Commit ( db ) ;
c . setTreeId ( treeB . writeTree ( ow ) ) ;
c . setTreeId ( treeB . writeTree ( odi ) ) ;
c . setAuthor ( new PersonIdent ( "A U Thor" , "a.u.thor" , 1L , 0 ) ) ;
c . setCommitter ( c . getAuthor ( ) ) ;
c . setParentIds ( parentIds ) ;
c . setMessage ( "Tree " + c . getTreeId ( ) . name ( ) ) ;
return ow . writeCommit ( c ) ;
ObjectId id = odi . insert ( OBJ_COMMIT , odi . format ( c ) ) ;
odi . flush ( ) ;
return id ;
}
private DirCacheEntry makeEntry ( final String path , final FileMode mode )
@ -383,9 +387,8 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
final String content ) throws Exception {
final DirCacheEntry ent = new DirCacheEntry ( path ) ;
ent . setFileMode ( mode ) ;
final byte [ ] contentBytes = Constants . encode ( content ) ;
ent . setObjectId ( new ObjectWriter ( db ) . computeBlobSha1 (
contentBytes . length , new ByteArrayInputStream ( contentBytes ) ) ) ;
ent . setObjectId ( new ObjectInserter . Formatter ( ) . idFor ( OBJ_BLOB ,
Constants . encode ( content ) ) ) ;
return ent ;
}
}