@ -63,10 +63,14 @@ import java.util.Set;
import org.eclipse.jgit.errors.MissingObjectException ;
import org.eclipse.jgit.junit.JGitTestUtil ;
import org.eclipse.jgit.junit.TestRepository ;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder ;
import org.eclipse.jgit.lib.NullProgressMonitor ;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.ObjectInserter ;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase ;
import org.eclipse.jgit.revwalk.RevBlob ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevObject ;
import org.eclipse.jgit.revwalk.RevWalk ;
import org.eclipse.jgit.storage.file.PackIndex.MutableEntry ;
@ -447,6 +451,68 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
}
}
@Test
public void testExclude ( ) throws Exception {
FileRepository repo = createBareRepository ( ) ;
TestRepository < FileRepository > testRepo = new TestRepository < FileRepository > (
repo ) ;
BranchBuilder bb = testRepo . branch ( "refs/heads/master" ) ;
RevBlob contentA = testRepo . blob ( "A" ) ;
RevCommit c1 = bb . commit ( ) . add ( "f" , contentA ) . create ( ) ;
testRepo . getRevWalk ( ) . parseHeaders ( c1 ) ;
PackIndex pf1 = writePack ( repo , Collections . singleton ( c1 ) ,
Collections . < PackIndex > emptySet ( ) ) ;
assertContent (
pf1 ,
Arrays . asList ( c1 . getId ( ) , c1 . getTree ( ) . getId ( ) ,
contentA . getId ( ) ) ) ;
RevBlob contentB = testRepo . blob ( "B" ) ;
RevCommit c2 = bb . commit ( ) . add ( "f" , contentB ) . create ( ) ;
testRepo . getRevWalk ( ) . parseHeaders ( c2 ) ;
PackIndex pf2 = writePack ( repo , Collections . singleton ( c2 ) ,
Collections . singleton ( pf1 ) ) ;
assertContent (
pf2 ,
Arrays . asList ( c2 . getId ( ) , c2 . getTree ( ) . getId ( ) ,
contentB . getId ( ) ) ) ;
}
private void assertContent ( PackIndex pi , List < ObjectId > expected ) {
assertEquals ( "Pack index has wrong size." , expected . size ( ) ,
pi . getObjectCount ( ) ) ;
for ( int i = 0 ; i < pi . getObjectCount ( ) ; i + + )
assertTrue (
"Pack index didn't contain the expected id "
+ pi . getObjectId ( i ) ,
expected . contains ( pi . getObjectId ( i ) ) ) ;
}
private PackIndex writePack ( FileRepository repo ,
Set < ? extends ObjectId > want , Set < PackIndex > excludeObjects )
throws IOException {
PackWriter pw = new PackWriter ( repo ) ;
pw . setDeltaBaseAsOffset ( true ) ;
pw . setReuseDeltaCommits ( false ) ;
for ( PackIndex idx : excludeObjects )
pw . excludeObjects ( idx ) ;
pw . preparePack ( NullProgressMonitor . INSTANCE , want ,
Collections . < ObjectId > emptySet ( ) ) ;
String id = pw . computeName ( ) . getName ( ) ;
File packdir = new File ( repo . getObjectsDirectory ( ) , "pack" ) ;
File packFile = new File ( packdir , "pack-" + id + ".pack" ) ;
FileOutputStream packOS = new FileOutputStream ( packFile ) ;
pw . writePack ( NullProgressMonitor . INSTANCE ,
NullProgressMonitor . INSTANCE , packOS ) ;
packOS . close ( ) ;
File idxFile = new File ( packdir , "pack-" + id + ".idx" ) ;
FileOutputStream idxOS = new FileOutputStream ( idxFile ) ;
pw . writeIndex ( idxOS ) ;
idxOS . close ( ) ;
pw . release ( ) ;
return PackIndex . open ( idxFile ) ;
}
// TODO: testWritePackDeltasCycle()
// TODO: testWritePackDeltasDepth()