Browse Source

PackWriterTest: Open TestRepository in try-with-resource

Change-Id: Ia4202c860b851bef5db72ea6781b3e6a32484e08
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.4
David Pursehouse 6 years ago
parent
commit
5d9c78e471
  1. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java

23
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java

@ -469,10 +469,12 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
public void testDeltaStatistics() throws Exception {
config.setDeltaCompress(true);
FileRepository repo = createBareRepository();
TestRepository<FileRepository> testRepo = new TestRepository<>(repo);
ArrayList<RevObject> blobs = new ArrayList<>();
try (TestRepository<FileRepository> testRepo = new TestRepository<>(
repo)) {
blobs.add(testRepo.blob(genDeltableData(1000)));
blobs.add(testRepo.blob(genDeltableData(1005)));
}
try (PackWriter pw = new PackWriter(repo)) {
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
@ -535,26 +537,24 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
public void testExclude() throws Exception {
FileRepository repo = createBareRepository();
TestRepository<FileRepository> testRepo = new TestRepository<>(
repo);
try (TestRepository<FileRepository> testRepo = new TestRepository<>(
repo)) {
BranchBuilder bb = testRepo.branch("refs/heads/master");
contentA = testRepo.blob("A");
c1 = bb.commit().add("f", contentA).create();
testRepo.getRevWalk().parseHeaders(c1);
PackIndex pf1 = writePack(repo, wants(c1), EMPTY_ID_SET);
assertContent(
pf1,
Arrays.asList(c1.getId(), c1.getTree().getId(),
assertContent(pf1, Arrays.asList(c1.getId(), c1.getTree().getId(),
contentA.getId()));
contentB = testRepo.blob("B");
c2 = bb.commit().add("f", contentB).create();
testRepo.getRevWalk().parseHeaders(c2);
PackIndex pf2 = writePack(repo, wants(c2), Sets.of((ObjectIdSet) pf1));
assertContent(
pf2,
Arrays.asList(c2.getId(), c2.getTree().getId(),
PackIndex pf2 = writePack(repo, wants(c2),
Sets.of((ObjectIdSet) pf1));
assertContent(pf2, Arrays.asList(c2.getId(), c2.getTree().getId(),
contentB.getId()));
}
}
private static void assertContent(PackIndex pi, List<ObjectId> expected) {
assertEquals("Pack index has wrong size.", expected.size(),
@ -660,7 +660,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
private FileRepository setupRepoForShallowFetch() throws Exception {
FileRepository repo = createBareRepository();
TestRepository<Repository> r = new TestRepository<>(repo);
try (TestRepository<Repository> r = new TestRepository<>(repo)) {
BranchBuilder bb = r.branch("refs/heads/master");
contentA = r.blob("A");
contentB = r.blob("B");
@ -675,6 +675,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
r.getRevWalk().parseHeaders(c5); // fully initialize the tip RevCommit
return repo;
}
}
private static PackIndex writePack(FileRepository repo,
Set<? extends ObjectId> want, Set<ObjectIdSet> excludeObjects)

Loading…
Cancel
Save