summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2012-05-08 14:25:46 +0200
committerShawn O. Pearce <spearce@spearce.org>2012-06-04 07:52:36 -0700
commit0f84b86e01da4680633c32bad101d021e0cb98ad (patch)
tree4f443d608f2fd95f43026954c79c0d60536ce0d7 /org.eclipse.jgit.test/tst
parentbc7817c9436756bec3ffe88dc0ef75881d4b9478 (diff)
downloadjgit-0f84b86e01da4680633c32bad101d021e0cb98ad.tar.gz
jgit-0f84b86e01da4680633c32bad101d021e0cb98ad.zip
fix PackWriter excluded objects handling
PackWriter supports excluding objects from being written to the pack. You may specify a PackIndex which lists all those objects which should not go into the new pack. This feature was broken because not all commits have been checked whether they should be excluded or not. For other object types the exclude algorithm worked. This commit adds the missing check. Change-Id: Id0047098393641ccba784c58b8325175c22fcece Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java
index b609b4766b..965a21ce05 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java
@@ -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()