diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2015-04-11 00:21:39 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-05-21 02:05:45 +0200 |
commit | 686124bec32fcdee1545e7d9c312dcf0276b44af (patch) | |
tree | cd98b171d3b97de6972bf1f606f34d72eaf5fa12 /org.eclipse.jgit.junit/src | |
parent | 0e73d395061d1bfee365acaa2f79c392175d13bf (diff) | |
download | jgit-686124bec32fcdee1545e7d9c312dcf0276b44af.tar.gz jgit-686124bec32fcdee1545e7d9c312dcf0276b44af.zip |
Replace deprecated release() methods by close()
See the discussion [1] in the Gerrit mailing list.
[1] https://groups.google.com/forum/#!topic/repo-discuss/RRQT_xCqz4o
Change-Id: I2c67384309c5c2e8511a7d0d4e088b4e95f819ff
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.junit/src')
-rw-r--r-- | org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java index bc225cc017..83148d0009 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java @@ -307,26 +307,27 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { */ protected void resetIndex(FileTreeIterator treeItr) throws FileNotFoundException, IOException { - ObjectInserter inserter = db.newObjectInserter(); - DirCacheBuilder builder = db.lockDirCache().builder(); - DirCacheEntry dce; - - while (!treeItr.eof()) { - long len = treeItr.getEntryLength(); - - dce = new DirCacheEntry(treeItr.getEntryPathString()); - dce.setFileMode(treeItr.getEntryFileMode()); - dce.setLastModified(treeItr.getEntryLastModified()); - dce.setLength((int) len); - FileInputStream in = new FileInputStream(treeItr.getEntryFile()); - dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in)); - in.close(); - builder.add(dce); - treeItr.next(1); + try (ObjectInserter inserter = db.newObjectInserter()) { + DirCacheBuilder builder = db.lockDirCache().builder(); + DirCacheEntry dce; + + while (!treeItr.eof()) { + long len = treeItr.getEntryLength(); + + dce = new DirCacheEntry(treeItr.getEntryPathString()); + dce.setFileMode(treeItr.getEntryFileMode()); + dce.setLastModified(treeItr.getEntryLastModified()); + dce.setLength((int) len); + FileInputStream in = new FileInputStream( + treeItr.getEntryFile()); + dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in)); + in.close(); + builder.add(dce); + treeItr.next(1); + } + builder.commit(); + inserter.flush(); } - builder.commit(); - inserter.flush(); - inserter.release(); } /** @@ -410,14 +411,15 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { protected void checkoutBranch(String branchName) throws IllegalStateException, IOException { - RevWalk walk = new RevWalk(db); - RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD)); - RevCommit branch = walk.parseCommit(db.resolve(branchName)); - DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(), - db.lockDirCache(), branch.getTree().getId()); - dco.setFailOnConflict(true); - dco.checkout(); - walk.release(); + try (RevWalk walk = new RevWalk(db)) { + RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD)); + RevCommit branch = walk.parseCommit(db.resolve(branchName)); + DirCacheCheckout dco = new DirCacheCheckout(db, + head.getTree().getId(), db.lockDirCache(), + branch.getTree().getId()); + dco.setFailOnConflict(true); + dco.checkout(); + } // update the HEAD RefUpdate refUpdate = db.updateRef(Constants.HEAD); refUpdate.setRefLogMessage("checkout: moving to " + branchName, false); |