diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2019-01-20 17:27:03 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2019-01-20 17:28:10 +0900 |
commit | 5d9c78e47158a321d32f9bbf5f0c204a05e13ebd (patch) | |
tree | 1c07234288ff29a128d84b9985bf5e65c1594eb3 /org.eclipse.jgit.test | |
parent | 6efe3612a7aa72cf6e860522cdc2b8e5a673d61f (diff) | |
download | jgit-5d9c78e47158a321d32f9bbf5f0c204a05e13ebd.tar.gz jgit-5d9c78e47158a321d32f9bbf5f0c204a05e13ebd.zip |
PackWriterTest: Open TestRepository in try-with-resource
Change-Id: Ia4202c860b851bef5db72ea6781b3e6a32484e08
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java index 04bed09af3..ca4486256b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java +++ b/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<>(); - blobs.add(testRepo.blob(genDeltableData(1000))); - blobs.add(testRepo.blob(genDeltableData(1005))); + 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,25 +537,23 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { public void testExclude() throws Exception { FileRepository repo = createBareRepository(); - 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(), - 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(), - contentB.getId())); + 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(), + 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(), + contentB.getId())); + } } private static void assertContent(PackIndex pi, List<ObjectId> expected) { @@ -660,20 +660,21 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { private FileRepository setupRepoForShallowFetch() throws Exception { FileRepository repo = createBareRepository(); - TestRepository<Repository> r = new TestRepository<>(repo); - BranchBuilder bb = r.branch("refs/heads/master"); - contentA = r.blob("A"); - contentB = r.blob("B"); - contentC = r.blob("C"); - contentD = r.blob("D"); - contentE = r.blob("E"); - c1 = bb.commit().add("a", contentA).create(); - c2 = bb.commit().add("b", contentB).create(); - c3 = bb.commit().add("c", contentC).create(); - c4 = bb.commit().add("d", contentD).create(); - c5 = bb.commit().add("e", contentE).create(); - r.getRevWalk().parseHeaders(c5); // fully initialize the tip RevCommit - return repo; + try (TestRepository<Repository> r = new TestRepository<>(repo)) { + BranchBuilder bb = r.branch("refs/heads/master"); + contentA = r.blob("A"); + contentB = r.blob("B"); + contentC = r.blob("C"); + contentD = r.blob("D"); + contentE = r.blob("E"); + c1 = bb.commit().add("a", contentA).create(); + c2 = bb.commit().add("b", contentB).create(); + c3 = bb.commit().add("c", contentC).create(); + c4 = bb.commit().add("d", contentD).create(); + c5 = bb.commit().add("e", contentE).create(); + r.getRevWalk().parseHeaders(c5); // fully initialize the tip RevCommit + return repo; + } } private static PackIndex writePack(FileRepository repo, |