]> source.dussan.org Git - jgit.git/commitdiff
Replace deprecated release() methods by close() 26/48326/4
authorMatthias Sohn <matthias.sohn@sap.com>
Fri, 10 Apr 2015 22:21:39 +0000 (00:21 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 21 May 2015 00:05:45 +0000 (02:05 +0200)
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>
56 files changed:
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DiffCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/blame/BlameGeneratorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/DefaultNoteMergerTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapMergerTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkBasicDiffTest.java
org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java

index cd066b0c74c9dd1d2592d97ae7adfddf4f7ac77c..030287b5cf508e3daf4d183b649a00c696530765 100644 (file)
@@ -117,7 +117,7 @@ class ReceivePackServlet extends HttpServlet {
                        try {
                                rp.sendAdvertisedRefs(pck);
                        } finally {
-                               rp.getRevWalk().release();
+                               rp.getRevWalk().close();
                        }
                }
        }
index 443eebb4d443a8e3c68598d8fd23c46e1eea71b0..44d4b1bcfa3ea1d56200cf879710d1eec4ba4a47 100644 (file)
@@ -117,7 +117,7 @@ class UploadPackServlet extends HttpServlet {
                                up.setBiDirectionalPipe(false);
                                up.sendAdvertisedRefs(pck);
                        } finally {
-                               up.getRevWalk().release();
+                               up.getRevWalk().close();
                        }
                }
        }
index bc225cc017354f69bc3420209083dcc6b535c47e..83148d0009e10c78fceb2036e6c3b22c5b111a92 100644 (file)
@@ -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);
index d226df21bb481b49e5cd833fe8f93ac90b08e78f..fde0a78bf6ca9ab2fa7bfd9454c34dc723533b64 100644 (file)
@@ -67,8 +67,7 @@ abstract class AbstractFetchCommand extends TextBuiltin {
        private boolean verbose;
 
        protected void showFetchResult(final FetchResult r) throws IOException {
-               ObjectReader reader = db.newObjectReader();
-               try {
+               try (ObjectReader reader = db.newObjectReader()) {
                        boolean shownURI = false;
                        for (final TrackingRefUpdate u : r.getTrackingRefUpdates()) {
                                if (!verbose && u.getResult() == RefUpdate.Result.NO_CHANGE)
@@ -89,8 +88,6 @@ abstract class AbstractFetchCommand extends TextBuiltin {
                                                src, dst);
                                outw.println();
                        }
-               } finally {
-                       reader.release();
                }
                showRemoteMessages(errw, r.getMessages());
        }
index 271e934b45e5cec061ae61170a03c3c44fdbe983..0f541715ab0debb71bb9906dca552ab40fd57071 100644 (file)
@@ -156,10 +156,9 @@ class Blame extends TextBuiltin {
                else
                        dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$
 
-               BlameGenerator generator = new BlameGenerator(db, file);
-               RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
                reader = db.newObjectReader();
-               try {
+               try (BlameGenerator generator = new BlameGenerator(db, file)) {
+                       RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
                        generator.setTextComparator(comparator);
 
                        if (!reverseRange.isEmpty()) {
@@ -247,8 +246,7 @@ class Blame extends TextBuiltin {
                                } while (++line < end && blame.getSourceCommit(line) == c);
                        }
                } finally {
-                       generator.release();
-                       reader.release();
+                       reader.close();
                }
        }
 
index 7147544d1b31c57d71896aade96682fc851d7c82..72e37158cd22aae6b964009e25221a9e6af446d8 100644 (file)
@@ -204,15 +204,12 @@ class Branch extends TextBuiltin {
                        addRefs(refs, Constants.R_HEADS);
                        addRefs(refs, Constants.R_REMOTES);
 
-                       ObjectReader reader = db.newObjectReader();
-                       try {
+                       try (ObjectReader reader = db.newObjectReader()) {
                                for (final Entry<String, Ref> e : printRefs.entrySet()) {
                                        final Ref ref = e.getValue();
                                        printHead(reader, e.getKey(),
                                                        current.equals(ref.getName()), ref);
                                }
-                       } finally {
-                               reader.release();
                        }
                }
        }
index fe2df65541c0405fab52c33509fa4a8a0140964a..61a385df839091c82825bba4d16d3982195fe84a 100644 (file)
@@ -184,11 +184,8 @@ class Diff extends TextBuiltin {
                                        if (head == null)
                                                die(MessageFormat.format(CLIText.get().notATree, HEAD));
                                        CanonicalTreeParser p = new CanonicalTreeParser();
-                                       ObjectReader reader = db.newObjectReader();
-                                       try {
+                                       try (ObjectReader reader = db.newObjectReader()) {
                                                p.reset(reader, head);
-                                       } finally {
-                                               reader.release();
                                        }
                                        oldTree = p;
                                }
@@ -219,7 +216,7 @@ class Diff extends TextBuiltin {
                                diffFmt.flush();
                        }
                } finally {
-                       diffFmt.release();
+                       diffFmt.close();
                }
        }
 
index 4afb6d5f88f2730ddb56df6e500ec6e7c459e708..22f3be9afd1543b4ca6b4a4e3ad4f8d5747e2206 100644 (file)
@@ -63,8 +63,7 @@ class IndexPack extends TextBuiltin {
        @Override
        protected void run() throws Exception {
                BufferedInputStream in = new BufferedInputStream(ins);
-               ObjectInserter inserter = db.newObjectInserter();
-               try {
+               try (ObjectInserter inserter = db.newObjectInserter()) {
                        PackParser p = inserter.newPackParser(in);
                        p.setAllowThin(fixThin);
                        if (indexVersion != -1 && p instanceof ObjectDirectoryPackParser) {
@@ -73,8 +72,6 @@ class IndexPack extends TextBuiltin {
                        }
                        p.parse(new TextProgressMonitor(errw));
                        inserter.flush();
-               } finally {
-                       inserter.release();
                }
        }
 }
index 688de2c499ddd9b83653379cceac191adf355065..d43424c7ce2a050a10e9c4de13b42f739cb7da34 100644 (file)
@@ -223,7 +223,7 @@ class Log extends RevWalkTextBuiltin {
 
                        super.run();
                } finally {
-                       diffFmt.release();
+                       diffFmt.close();
                }
        }
 
index 111933790ea0feecea96a89001de2aa40d6fac0d..4268f214fd8d59cf51707c47b39b27da79772343 100644 (file)
@@ -125,11 +125,8 @@ class Push extends TextBuiltin {
                push.setTimeout(timeout);
                Iterable<PushResult> results = push.call();
                for (PushResult result : results) {
-                       ObjectReader reader = db.newObjectReader();
-                       try {
+                       try (ObjectReader reader = db.newObjectReader()) {
                                printPushResult(reader, result.getURI(), result);
-                       } finally {
-                               reader.release();
                        }
                }
        }
index a33a2d4dff046b3a19e36b3d1026fbcc5b806889..b668139b5e0108804e219acb9aa30d6f646bef62 100644 (file)
@@ -184,8 +184,7 @@ class Show extends TextBuiltin {
                        else
                                objectId = db.resolve(objectName);
 
-                       RevWalk rw = new RevWalk(db);
-                       try {
+                       try (RevWalk rw = new RevWalk(db)) {
                                RevObject obj = rw.parseAny(objectId);
                                while (obj instanceof RevTag) {
                                        show((RevTag) obj);
@@ -216,11 +215,9 @@ class Show extends TextBuiltin {
                                                        CLIText.get().cannotReadBecause, obj.name(),
                                                        obj.getType()));
                                }
-                       } finally {
-                               rw.release();
                        }
                } finally {
-                       diffFmt.release();
+                       diffFmt.close();
                }
        }
 
index 91b5917155bfabd907babf6a7d77e859007d2fb3..24d717dfd81b3b33320e4128c0094a045db88345 100644 (file)
@@ -173,8 +173,7 @@ class DiffAlgorithms extends TextBuiltin {
                int maxN = 0;
 
                AbbreviatedObjectId startId;
-               ObjectReader or = db.newObjectReader();
-               try {
+               try (ObjectReader or = db.newObjectReader()) {
                        final MutableObjectId id = new MutableObjectId();
                        RevWalk rw = new RevWalk(or);
                        TreeWalk tw = new TreeWalk(or);
@@ -232,8 +231,6 @@ class DiffAlgorithms extends TextBuiltin {
                                if (count > 0 && files > count)
                                        break;
                        }
-               } finally {
-                       or.release();
                }
 
                Collections.sort(all, new Comparator<Test>() {
index afa469636cf4f97f02a8d82b05f4c42237947050..494055a265968fc54609a2a55f171c45b06e7545 100644 (file)
@@ -134,12 +134,12 @@ class RebuildCommitGraph extends TextBuiltin {
        }
 
        private void recreateCommitGraph() throws IOException {
-               final RevWalk rw = new RevWalk(db);
                final Map<ObjectId, ToRewrite> toRewrite = new HashMap<ObjectId, ToRewrite>();
                List<ToRewrite> queue = new ArrayList<ToRewrite>();
-               final BufferedReader br = new BufferedReader(new InputStreamReader(
-                               new FileInputStream(graph), Constants.CHARSET));
-               try {
+               try (RevWalk rw = new RevWalk(db);
+                               final BufferedReader br = new BufferedReader(
+                                               new InputStreamReader(new FileInputStream(graph),
+                                                               Constants.CHARSET))) {
                        String line;
                        while ((line = br.readLine()) != null) {
                                final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$
@@ -162,52 +162,52 @@ class RebuildCommitGraph extends TextBuiltin {
                                toRewrite.put(oldId, t);
                                queue.add(t);
                        }
-               } finally {
-                       br.close();
                }
 
                pm.beginTask("Rewriting commits", queue.size());
-               final ObjectInserter oi = db.newObjectInserter();
-               final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE, new byte[] {});
-               final PersonIdent me = new PersonIdent("jgit rebuild-commitgraph", //$NON-NLS-1$
-                               "rebuild-commitgraph@localhost"); //$NON-NLS-1$
-               while (!queue.isEmpty()) {
-                       final ListIterator<ToRewrite> itr = queue
-                                       .listIterator(queue.size());
-                       queue = new ArrayList<ToRewrite>();
-                       REWRITE: while (itr.hasPrevious()) {
-                               final ToRewrite t = itr.previous();
-                               final ObjectId[] newParents = new ObjectId[t.oldParents.length];
-                               for (int k = 0; k < t.oldParents.length; k++) {
-                                       final ToRewrite p = toRewrite.get(t.oldParents[k]);
-                                       if (p != null) {
-                                               if (p.newId == null) {
-                                                       // Must defer until after the parent is rewritten.
-                                                       queue.add(t);
-                                                       continue REWRITE;
+               try (ObjectInserter oi = db.newObjectInserter()) {
+                       final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE,
+                                       new byte[] {});
+                       final PersonIdent me = new PersonIdent("jgit rebuild-commitgraph", //$NON-NLS-1$
+                                       "rebuild-commitgraph@localhost"); //$NON-NLS-1$
+                       while (!queue.isEmpty()) {
+                               final ListIterator<ToRewrite> itr = queue
+                                               .listIterator(queue.size());
+                               queue = new ArrayList<ToRewrite>();
+                               REWRITE: while (itr.hasPrevious()) {
+                                       final ToRewrite t = itr.previous();
+                                       final ObjectId[] newParents = new ObjectId[t.oldParents.length];
+                                       for (int k = 0; k < t.oldParents.length; k++) {
+                                               final ToRewrite p = toRewrite.get(t.oldParents[k]);
+                                               if (p != null) {
+                                                       if (p.newId == null) {
+                                                               // Must defer until after the parent is
+                                                               // rewritten.
+                                                               queue.add(t);
+                                                               continue REWRITE;
+                                                       } else {
+                                                               newParents[k] = p.newId;
+                                                       }
                                                } else {
-                                                       newParents[k] = p.newId;
+                                                       // We have the old parent object. Use it.
+                                                       //
+                                                       newParents[k] = t.oldParents[k];
                                                }
-                                       } else {
-                                               // We have the old parent object. Use it.
-                                               //
-                                               newParents[k] = t.oldParents[k];
                                        }
-                               }
 
-                               final CommitBuilder newc = new CommitBuilder();
-                               newc.setTreeId(emptyTree);
-                               newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
-                               newc.setCommitter(newc.getAuthor());
-                               newc.setParentIds(newParents);
-                               newc.setMessage("ORIGINAL " + t.oldId.name() + "\n"); //$NON-NLS-2$
-                               t.newId = oi.insert(newc);
-                               rewrites.put(t.oldId, t.newId);
-                               pm.update(1);
+                                       final CommitBuilder newc = new CommitBuilder();
+                                       newc.setTreeId(emptyTree);
+                                       newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
+                                       newc.setCommitter(newc.getAuthor());
+                                       newc.setParentIds(newParents);
+                                       newc.setMessage("ORIGINAL " + t.oldId.name() + "\n"); //$NON-NLS-2$
+                                       t.newId = oi.insert(newc);
+                                       rewrites.put(t.oldId, t.newId);
+                                       pm.update(1);
+                               }
                        }
+                       oi.flush();
                }
-               oi.flush();
-               oi.release();
                pm.endTask();
        }
 
@@ -275,11 +275,11 @@ class RebuildCommitGraph extends TextBuiltin {
        }
 
        private Map<String, Ref> computeNewRefs() throws IOException {
-               final RevWalk rw = new RevWalk(db);
                final Map<String, Ref> refs = new HashMap<String, Ref>();
-               final BufferedReader br = new BufferedReader(new InputStreamReader(
-                               new FileInputStream(refList), Constants.CHARSET));
-               try {
+               try (RevWalk rw = new RevWalk(db);
+                               BufferedReader br = new BufferedReader(
+                                               new InputStreamReader(new FileInputStream(refList),
+                                                               Constants.CHARSET))) {
                        String line;
                        while ((line = br.readLine()) != null) {
                                final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$
@@ -302,9 +302,6 @@ class RebuildCommitGraph extends TextBuiltin {
                                refs.put(name, new ObjectIdRef.Unpeeled(Ref.Storage.PACKED,
                                                name, id));
                        }
-               } finally {
-                       rw.release();
-                       br.close();
                }
                return refs;
        }
index 4205140bb93bc15c6604b1e521adc9c6279f7917..dcfa8cf00afe93d2acfa4637072b28787f3da3ff 100644 (file)
@@ -300,8 +300,7 @@ class TextHashFunctions extends TextBuiltin {
 
                long fileCnt = 0;
                long lineCnt = 0;
-               ObjectReader or = db.newObjectReader();
-               try {
+               try (ObjectReader or = db.newObjectReader()) {
                        final MutableObjectId id = new MutableObjectId();
                        RevWalk rw = new RevWalk(or);
                        TreeWalk tw = new TreeWalk(or);
@@ -340,8 +339,6 @@ class TextHashFunctions extends TextBuiltin {
                                for (Function fun : all)
                                        testOne(fun, txt, lines, cnt);
                        }
-               } finally {
-                       or.release();
                }
 
                if (db.getDirectory() != null) {
index 087dbb0679aaa560be09adc2e36c4c2012134a62..229fb67b0cf41781a16908b1b7e7dbfc68445114 100644 (file)
@@ -125,8 +125,7 @@ public class AbstractTreeIteratorHandler extends
                        throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
 
                final CanonicalTreeParser p = new CanonicalTreeParser();
-               final ObjectReader curs = clp.getRepository().newObjectReader();
-               try {
+               try (ObjectReader curs = clp.getRepository().newObjectReader()) {
                        p.reset(curs, clp.getRevWalk().parseTree(id));
                } catch (MissingObjectException e) {
                        throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
@@ -134,8 +133,6 @@ public class AbstractTreeIteratorHandler extends
                        throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
                } catch (IOException e) {
                        throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
-               } finally {
-                       curs.release();
                }
 
                setter.addValue(p);
index ea07beed70caefe2ca5dbba2962261a5f810d06d..3b2fa6c37dfe29b1b28e77be7758d47925683120 100644 (file)
@@ -414,17 +414,19 @@ public class CloneCommandTest extends RepositoryTestCase {
                assertEquals(commit, pathStatus.getHeadId());
                assertEquals(commit, pathStatus.getIndexId());
 
-               SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository());
-               assertTrue(walk.next());
-               Repository clonedSub1 = walk.getRepository();
-               addRepoToClose(clonedSub1);
-               assertNotNull(clonedSub1);
-               assertEquals(
-                               new File(git2.getRepository().getWorkTree(), walk.getPath()),
-                               clonedSub1.getWorkTree());
-               assertEquals(new File(new File(git2.getRepository().getDirectory(),
-                               "modules"), walk.getPath()), clonedSub1.getDirectory());
-               walk.release();
+               try (SubmoduleWalk walk = SubmoduleWalk
+                               .forIndex(git2.getRepository())) {
+                       assertTrue(walk.next());
+                       Repository clonedSub1 = walk.getRepository();
+                       addRepoToClose(clonedSub1);
+                       assertNotNull(clonedSub1);
+                       assertEquals(new File(git2.getRepository().getWorkTree(),
+                                       walk.getPath()), clonedSub1.getWorkTree());
+                       assertEquals(
+                                       new File(new File(git2.getRepository().getDirectory(),
+                                                       "modules"), walk.getPath()),
+                                       clonedSub1.getDirectory());
+               }
        }
 
        @Test
index 1f71402879c18dd2c7e0bfd90d8bc881e4f29518..2c70a166e3564938bb8d9b8ad3dfcd9e8c1daf97 100644 (file)
@@ -509,9 +509,9 @@ public class CommitCommandTest extends RepositoryTestCase {
                                + "[unmerged2, mode:100644, stage:3]",
                                indexState(0));
 
-               TreeWalk walk = TreeWalk.forPath(db, "unmerged1", commit.getTree());
-               assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
-               walk.release();
+               try (TreeWalk walk = TreeWalk.forPath(db, "unmerged1", commit.getTree())) {
+                       assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
+               }
        }
 
        private static void addUnmergedEntry(String file, DirCacheBuilder builder) {
index c5608b3f1ee84f7c0191313fa204e6f181b47796..4ad01cf6f0b899c06c4ce249ecb206da563bcece 100644 (file)
@@ -247,12 +247,9 @@ public class DiffCommandTest extends RepositoryTestCase {
                if (id == null)
                        throw new IllegalArgumentException(name);
                final CanonicalTreeParser p = new CanonicalTreeParser();
-               final ObjectReader or = db.newObjectReader();
-               try {
+               try (ObjectReader or = db.newObjectReader()) {
                        p.reset(or, new RevWalk(db).parseTree(id));
                        return p;
-               } finally {
-                       or.release();
                }
        }
 }
index eb092ad6c85b4e4f26c0eb2c316590730f20e80c..db811cdf59757dc64f1a7134ea287887bb89db3e 100644 (file)
@@ -193,8 +193,8 @@ public class PathCheckoutCommandTest extends RepositoryTestCase {
        public static void validateIndex(Git git) throws NoWorkTreeException,
                        IOException {
                DirCache dc = git.getRepository().lockDirCache();
-               ObjectReader r = git.getRepository().getObjectDatabase().newReader();
-               try {
+               try (ObjectReader r = git.getRepository().getObjectDatabase()
+                               .newReader()) {
                        for (int i = 0; i < dc.getEntryCount(); ++i) {
                                DirCacheEntry entry = dc.getEntry(i);
                                if (entry.getLength() > 0)
@@ -203,7 +203,6 @@ public class PathCheckoutCommandTest extends RepositoryTestCase {
                        }
                } finally {
                        dc.unlock();
-                       r.release();
                }
        }
 
index d4805d0aa1bad97dbbaf68a4a367d7a546d9ac57..57888e70a830ea717e16b1142758b95b0826b90d 100644 (file)
@@ -474,34 +474,35 @@ public class PullCommandTest extends RepositoryTestCase {
                }
                assertFileContentsEqual(sourceFile, "content");
 
-               RevWalk rw = new RevWalk(dbTarget);
-               rw.sort(RevSort.TOPO);
-               rw.markStart(rw.parseCommit(dbTarget.resolve("refs/heads/master")));
+               try (RevWalk rw = new RevWalk(dbTarget)) {
+                       rw.sort(RevSort.TOPO);
+                       rw.markStart(rw.parseCommit(dbTarget.resolve("refs/heads/master")));
 
-               RevCommit next;
-               if (expectedPullMode == TestPullMode.MERGE) {
-                       next = rw.next();
-                       assertEquals(2, next.getParentCount());
-                       assertEquals(merge, next.getParent(0));
-                       assertEquals(sourceCommit, next.getParent(1));
-                       // since both parents are known do no further checks here
-               } else {
-                       if (expectedPullMode == TestPullMode.REBASE_PREASERVE) {
+                       RevCommit next;
+                       if (expectedPullMode == TestPullMode.MERGE) {
                                next = rw.next();
                                assertEquals(2, next.getParentCount());
+                               assertEquals(merge, next.getParent(0));
+                               assertEquals(sourceCommit, next.getParent(1));
+                               // since both parents are known do no further checks here
+                       } else {
+                               if (expectedPullMode == TestPullMode.REBASE_PREASERVE) {
+                                       next = rw.next();
+                                       assertEquals(2, next.getParentCount());
+                               }
+                               next = rw.next();
+                               assertEquals(t2.getShortMessage(), next.getShortMessage());
+                               next = rw.next();
+                               assertEquals(t1.getShortMessage(), next.getShortMessage());
+                               next = rw.next();
+                               assertEquals(sourceCommit, next);
+                               next = rw.next();
+                               assertEquals("Initial commit for source",
+                                               next.getShortMessage());
+                               next = rw.next();
+                               assertNull(next);
                        }
-                       next = rw.next();
-                       assertEquals(t2.getShortMessage(), next.getShortMessage());
-                       next = rw.next();
-                       assertEquals(t1.getShortMessage(), next.getShortMessage());
-                       next = rw.next();
-                       assertEquals(sourceCommit, next);
-                       next = rw.next();
-                       assertEquals("Initial commit for source", next.getShortMessage());
-                       next = rw.next();
-                       assertNull(next);
                }
-               rw.release();
        }
 
        @Override
index 6b641c495f7aeaa486c2166125ca585a83b4ee4b..8b0ed5f39d1465d70421ae4e3b5d0cc97ee55fd3 100644 (file)
@@ -114,13 +114,14 @@ public class RebaseCommandTest extends RepositoryTestCase {
 
        private void checkoutCommit(RevCommit commit) throws IllegalStateException,
                        IOException {
-               RevWalk walk = new RevWalk(db);
-               RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
-               DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(), db
-                               .lockDirCache(), commit.getTree());
-               dco.setFailOnConflict(true);
-               dco.checkout();
-               walk.release();
+               RevCommit head;
+               try (RevWalk walk = new RevWalk(db)) {
+                       head = walk.parseCommit(db.resolve(Constants.HEAD));
+                       DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(),
+                                       db.lockDirCache(), commit.getTree());
+                       dco.setFailOnConflict(true);
+                       dco.checkout();
+               }
                // update the HEAD
                RefUpdate refUpdate = db.updateRef(Constants.HEAD, true);
                refUpdate.setNewObjectId(commit);
@@ -472,11 +473,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
        }
 
        private String readFile(String path, RevCommit commit) throws IOException {
-               TreeWalk walk = TreeWalk.forPath(db, path, commit.getTree());
-               ObjectLoader loader = db.open(walk.getObjectId(0), Constants.OBJ_BLOB);
-               String result = RawParseUtils.decode(loader.getCachedBytes());
-               walk.release();
-               return result;
+               try (TreeWalk walk = TreeWalk.forPath(db, path, commit.getTree())) {
+                       ObjectLoader loader = db.open(walk.getObjectId(0),
+                                       Constants.OBJ_BLOB);
+                       String result = RawParseUtils.decode(loader.getCachedBytes());
+                       return result;
+               }
        }
 
        @Test
@@ -2073,14 +2075,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
        private List<DiffEntry> diffWorkingAgainstHead(final RevCommit commit,
                        RevWalk revWalk)
                        throws IOException {
-               TreeWalk walk = createTreeWalk();
                RevCommit parentCommit = revWalk.parseCommit(commit.getParent(0));
-               try {
+               try (TreeWalk walk = createTreeWalk()) {
                        walk.addTree(parentCommit.getTree());
                        walk.addTree(commit.getTree());
                        return DiffEntry.scan(walk);
-               } finally {
-                       walk.release();
                }
        }
 
index c48b412401c18711d76a735cf130c626b71224cb..9997c8c426c0cc119a6ea9152daad36ac80cc63c 100644 (file)
@@ -537,16 +537,10 @@ public class ResetCommandTest extends RepositoryTestCase {
         */
        private boolean inHead(String path) throws IOException {
                ObjectId headId = db.resolve(Constants.HEAD);
-               RevWalk rw = new RevWalk(db);
-               TreeWalk tw = null;
-               try {
-                       tw = TreeWalk.forPath(db, path, rw.parseTree(headId));
+               try (RevWalk rw = new RevWalk(db);
+                               TreeWalk tw = TreeWalk.forPath(db, path,
+                                               rw.parseTree(headId))) {
                        return tw != null;
-               } finally {
-                       rw.release();
-                       rw.dispose();
-                       if (tw != null)
-                               tw.release();
                }
        }
 
index 387120342f2a75ed458c916657942b93aa3538b1..c317e3beef40dbab0e115f41ae8e83452c059d04 100644 (file)
@@ -118,12 +118,9 @@ public class StashCreateCommandTest extends RepositoryTestCase {
                assertEquals(parentCount, commit.getParentCount());
 
                // Load parents
-               RevWalk walk = new RevWalk(db);
-               try {
+               try (RevWalk walk = new RevWalk(db)) {
                        for (RevCommit parent : commit.getParents())
                                walk.parseBody(parent);
-               } finally {
-                       walk.release();
                }
 
                assertEquals(1, commit.getParent(1).getParentCount());
@@ -144,37 +141,28 @@ public class StashCreateCommandTest extends RepositoryTestCase {
 
        private List<DiffEntry> diffWorkingAgainstHead(final RevCommit commit)
                        throws IOException {
-               TreeWalk walk = createTreeWalk();
-               try {
+               try (TreeWalk walk = createTreeWalk()) {
                        walk.addTree(commit.getParent(0).getTree());
                        walk.addTree(commit.getTree());
                        return DiffEntry.scan(walk);
-               } finally {
-                       walk.release();
                }
        }
 
        private List<DiffEntry> diffIndexAgainstHead(final RevCommit commit)
                        throws IOException {
-               TreeWalk walk = createTreeWalk();
-               try {
+               try (TreeWalk walk = createTreeWalk()) {
                        walk.addTree(commit.getParent(0).getTree());
                        walk.addTree(commit.getParent(1).getTree());
                        return DiffEntry.scan(walk);
-               } finally {
-                       walk.release();
                }
        }
 
        private List<DiffEntry> diffIndexAgainstWorking(final RevCommit commit)
                        throws IOException {
-               TreeWalk walk = createTreeWalk();
-               try {
+               try (TreeWalk walk = createTreeWalk()) {
                        walk.addTree(commit.getParent(1).getTree());
                        walk.addTree(commit.getTree());
                        return DiffEntry.scan(walk);
-               } finally {
-                       walk.release();
                }
        }
 
@@ -224,11 +212,12 @@ public class StashCreateCommandTest extends RepositoryTestCase {
                writeTrashFile("file", "content2");
                RevCommit stashedWorkTree = Git.wrap(db).stashCreate().call();
                validateStashedCommit(stashedWorkTree);
-               RevWalk walk = new RevWalk(db);
-               RevCommit stashedIndex = stashedWorkTree.getParent(1);
-               walk.parseBody(stashedIndex);
-               walk.parseBody(stashedIndex.getTree());
-               walk.parseBody(stashedIndex.getParent(0));
+               try (RevWalk walk = new RevWalk(db)) {
+                       RevCommit stashedIndex = stashedWorkTree.getParent(1);
+                       walk.parseBody(stashedIndex);
+                       walk.parseBody(stashedIndex.getTree());
+                       walk.parseBody(stashedIndex.getParent(0));
+               }
                List<DiffEntry> workTreeStashAgainstWorkTree = diffWorkingAgainstHead(stashedWorkTree);
                assertEquals(1, workTreeStashAgainstWorkTree.size());
                List<DiffEntry> workIndexAgainstWorkTree = diffIndexAgainstHead(stashedWorkTree);
index a7bce1e11ed3332251cefc51a5588a28dc384911..42909f0d762cd0298f8fcf2b64307171517d7ffb 100644 (file)
@@ -70,8 +70,7 @@ public class BlameGeneratorTest extends RepositoryTestCase {
                git.add().addFilepattern("file.txt").call();
                RevCommit c2 = git.commit().setMessage("create file").call();
 
-               BlameGenerator generator = new BlameGenerator(db, "file.txt");
-               try {
+               try (BlameGenerator generator = new BlameGenerator(db, "file.txt")) {
                        generator.push(null, db.resolve(Constants.HEAD));
                        assertEquals(3, generator.getResultContents().size());
 
@@ -94,8 +93,6 @@ public class BlameGeneratorTest extends RepositoryTestCase {
                        assertEquals("file.txt", generator.getSourcePath());
 
                        assertFalse(generator.next());
-               } finally {
-                       generator.release();
                }
        }
 
@@ -123,8 +120,7 @@ public class BlameGeneratorTest extends RepositoryTestCase {
                git.add().addFilepattern(FILENAME_2).call();
                RevCommit c2 = git.commit().setMessage("change file2").call();
 
-               BlameGenerator generator = new BlameGenerator(db, FILENAME_2);
-               try {
+               try (BlameGenerator generator = new BlameGenerator(db, FILENAME_2)) {
                        generator.push(null, db.resolve(Constants.HEAD));
                        assertEquals(3, generator.getResultContents().size());
 
@@ -147,13 +143,10 @@ public class BlameGeneratorTest extends RepositoryTestCase {
                        assertEquals(FILENAME_1, generator.getSourcePath());
 
                        assertFalse(generator.next());
-               } finally {
-                       generator.release();
                }
 
                // and test again with other BlameGenerator API:
-               generator = new BlameGenerator(db, FILENAME_2);
-               try {
+               try (BlameGenerator generator = new BlameGenerator(db, FILENAME_2)) {
                        generator.push(null, db.resolve(Constants.HEAD));
                        BlameResult result = generator.computeBlameResult();
 
@@ -167,9 +160,6 @@ public class BlameGeneratorTest extends RepositoryTestCase {
 
                        assertEquals(c1, result.getSourceCommit(2));
                        assertEquals(FILENAME_1, result.getSourcePath(2));
-
-               } finally {
-                       generator.release();
                }
        }
 
@@ -193,8 +183,7 @@ public class BlameGeneratorTest extends RepositoryTestCase {
                git.add().addFilepattern("file.txt").call();
                RevCommit c3 = git.commit().setMessage("create file").call();
 
-               BlameGenerator generator = new BlameGenerator(db, "file.txt");
-               try {
+               try (BlameGenerator generator = new BlameGenerator(db, "file.txt")) {
                        generator.push(null, db.resolve(Constants.HEAD));
                        assertEquals(3, generator.getResultContents().size());
 
@@ -204,8 +193,6 @@ public class BlameGeneratorTest extends RepositoryTestCase {
                        assertEquals(3, generator.getResultEnd());
 
                        assertFalse(generator.next());
-               } finally {
-                       generator.release();
                }
        }
 
index 91498e7dfc2acf477aa5b8abff2eb1b93b282311..02e485d41ecd3cf99cf397deba94dbe976e137d2 100644 (file)
@@ -98,8 +98,9 @@ public class DiffFormatterTest extends RepositoryTestCase {
        @Override
        @After
        public void tearDown() throws Exception {
-               if (df != null)
-                       df.release();
+               if (df != null) {
+                       df.close();
+               }
                super.tearDown();
        }
 
index 693388c0bfa8fff138fa27f9d337be7933233fd4..fc8cbaa4372b25e03efe4e90995bad4b66618951 100644 (file)
@@ -78,12 +78,11 @@ public class DfsInserterTest {
 
        @Test
        public void testInserterDiscardsPack() throws IOException {
-               ObjectInserter ins = db.newObjectInserter();
-               ins.insert(Constants.OBJ_BLOB, Constants.encode("foo"));
-               ins.insert(Constants.OBJ_BLOB, Constants.encode("bar"));
-               assertEquals(0, db.getObjectDatabase().listPacks().size());
-
-               ins.release();
+               try (ObjectInserter ins = db.newObjectInserter()) {
+                       ins.insert(Constants.OBJ_BLOB, Constants.encode("foo"));
+                       ins.insert(Constants.OBJ_BLOB, Constants.encode("bar"));
+                       assertEquals(0, db.getObjectDatabase().listPacks().size());
+               }
                assertEquals(0, db.getObjectDatabase().listPacks().size());
        }
 
index 3a0b827b3f81bae42e5200e847f9f204bf2a321e..987540399bac3fc83e960fc899687c9a1a4aadba 100644 (file)
@@ -94,8 +94,9 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase {
 
        @After
        public void tearDown() throws Exception {
-               if (reader != null)
-                       reader.release();
+               if (reader != null) {
+                       reader.close();
+               }
        }
 
        @Test
index 562cde72ca4e13fde5cf5b09bd081cd9b208f70b..514e00f356a06d66cbe4e0c28f90547f7c6d5f91 100644 (file)
@@ -150,11 +150,11 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
                // within the pack has been modified.
                //
                final RevObject o2 = writeBlob(eden, "o2");
-               final PackWriter pw = new PackWriter(eden);
-               pw.addObject(o2);
-               pw.addObject(o1);
-               write(out1, pw);
-               pw.release();
+               try (PackWriter pw = new PackWriter(eden)) {
+                       pw.addObject(o2);
+                       pw.addObject(o1);
+                       write(out1, pw);
+               }
 
                // Try the old name, then the new name. The old name should cause the
                // pack to reload when it opens and the index and pack mismatch.
@@ -216,18 +216,18 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
 
        private File[] pack(final Repository src, final RevObject... list)
                        throws IOException {
-               final PackWriter pw = new PackWriter(src);
-               for (final RevObject o : list) {
-                       pw.addObject(o);
-               }
+               try (PackWriter pw = new PackWriter(src)) {
+                       for (final RevObject o : list) {
+                               pw.addObject(o);
+                       }
 
-               final ObjectId name = pw.computeName();
-               final File packFile = fullPackFileName(name, ".pack");
-               final File idxFile = fullPackFileName(name, ".idx");
-               final File[] files = new File[] { packFile, idxFile };
-               write(files, pw);
-               pw.release();
-               return files;
+                       final ObjectId name = pw.computeName();
+                       final File packFile = fullPackFileName(name, ".pack");
+                       final File idxFile = fullPackFileName(name, ".idx");
+                       final File[] files = new File[] { packFile, idxFile };
+                       write(files, pw);
+                       return files;
+               }
        }
 
        private static void write(final File[] files, final PackWriter pw)
@@ -282,13 +282,10 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
                        throws IOException {
                final RevWalk revWalk = new RevWalk(repo);
                final byte[] bytes = Constants.encode(data);
-               final ObjectInserter inserter = repo.newObjectInserter();
                final ObjectId id;
-               try {
+               try (ObjectInserter inserter = repo.newObjectInserter()) {
                        id = inserter.insert(Constants.OBJ_BLOB, bytes);
                        inserter.flush();
-               } finally {
-                       inserter.release();
                }
                try {
                        parse(id);
index 3324627e7f1e14643f0e07ade179d73789dda166..05055644ece047401e10143abc5b19fad58aa74a 100644 (file)
@@ -373,8 +373,9 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
 
        @After
        public void release() {
-               if (inserter != null)
-                       inserter.release();
+               if (inserter != null) {
+                       inserter.close();
+               }
        }
 
        private PackParser index(byte[] raw) throws IOException {
index 873b2cda45980699265848871e53c133f769f3a7..bc880a13efc96b2b2da97ea0fbc39cb0d88cb236 100644 (file)
@@ -120,11 +120,11 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
        @After
        public void tearDown() throws Exception {
                if (writer != null) {
-                       writer.release();
+                       writer.close();
                        writer = null;
                }
                if (inserter != null) {
-                       inserter.release();
+                       inserter.close();
                        inserter = null;
                }
                super.tearDown();
@@ -514,26 +514,26 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
        private static PackIndex writePack(FileRepository repo,
                        Set<? extends ObjectId> want, Set<ObjectIdSet> excludeObjects)
                        throws IOException {
-               PackWriter pw = new PackWriter(repo);
-               pw.setDeltaBaseAsOffset(true);
-               pw.setReuseDeltaCommits(false);
-               for (ObjectIdSet 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);
+               try (PackWriter pw = new PackWriter(repo)) {
+                       pw.setDeltaBaseAsOffset(true);
+                       pw.setReuseDeltaCommits(false);
+                       for (ObjectIdSet 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();
+                       return PackIndex.open(idxFile);
+               }
        }
 
        // TODO: testWritePackDeltasCycle()
@@ -639,7 +639,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
                writer.setIgnoreMissingUninteresting(ignoreMissingUninteresting);
                writer.preparePack(m, interestings, uninterestings);
                writer.writePack(m, m, os);
-               writer.release();
+               writer.close();
                verifyOpenPack(thin);
        }
 
@@ -650,7 +650,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
                writer.preparePack(objectSource.iterator());
                assertEquals(objectSource.size(), writer.getObjectCount());
                writer.writePack(m, m, os);
-               writer.release();
+               writer.close();
                verifyOpenPack(false);
        }
 
index 0ab013baffb18f4d708e46e08f38df9db3696866..5670a9634d7c8d53584326636b51bf3b68e4a0b3 100644 (file)
@@ -304,11 +304,12 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                // object (as it already exists in the pack).
                //
                final Repository newdb = createBareRepository();
-               final ObjectInserter oi = newdb.newObjectInserter();
-               final ObjectId treeId = oi.insert(new TreeFormatter());
-               oi.release();
+               try (final ObjectInserter oi = newdb.newObjectInserter()) {
+                       final ObjectId treeId = oi.insert(new TreeFormatter());
+                       assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904",
+                                       treeId.name());
+               }
 
-               assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
                final File o = new File(new File(new File(newdb.getDirectory(),
                                "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904");
                assertTrue("Exists " + o, o.isFile());
@@ -569,8 +570,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
        @Test
        public void test026_CreateCommitMultipleparents() throws IOException {
                final ObjectId treeId;
-               final ObjectInserter oi = db.newObjectInserter();
-               try {
+               try (final ObjectInserter oi = db.newObjectInserter()) {
                        final ObjectId blobId = oi.insert(Constants.OBJ_BLOB,
                                        "and this is the data in me\n".getBytes(Constants.CHARSET
                                                        .name()));
@@ -578,8 +578,6 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                        fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId);
                        treeId = oi.insert(fmt);
                        oi.flush();
-               } finally {
-                       oi.release();
                }
                assertEquals(ObjectId
                                .fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), treeId);
@@ -741,80 +739,59 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
 
        private ObjectId insertEmptyBlob() throws IOException {
                final ObjectId emptyId;
-               ObjectInserter oi = db.newObjectInserter();
-               try {
+               try (ObjectInserter oi = db.newObjectInserter()) {
                        emptyId = oi.insert(Constants.OBJ_BLOB, new byte[] {});
                        oi.flush();
-               } finally {
-                       oi.release();
                }
                return emptyId;
        }
 
        private ObjectId insertTree(Tree tree) throws IOException {
-               ObjectInserter oi = db.newObjectInserter();
-               try {
+               try (ObjectInserter oi = db.newObjectInserter()) {
                        ObjectId id = oi.insert(Constants.OBJ_TREE, tree.format());
                        oi.flush();
                        return id;
-               } finally {
-                       oi.release();
                }
        }
 
        private ObjectId insertTree(TreeFormatter tree) throws IOException {
-               ObjectInserter oi = db.newObjectInserter();
-               try {
+               try (ObjectInserter oi = db.newObjectInserter()) {
                        ObjectId id = oi.insert(tree);
                        oi.flush();
                        return id;
-               } finally {
-                       oi.release();
                }
        }
 
        private ObjectId insertCommit(final CommitBuilder builder)
                        throws IOException, UnsupportedEncodingException {
-               ObjectInserter oi = db.newObjectInserter();
-               try {
+               try (ObjectInserter oi = db.newObjectInserter()) {
                        ObjectId id = oi.insert(builder);
                        oi.flush();
                        return id;
-               } finally {
-                       oi.release();
                }
        }
 
        private RevCommit parseCommit(AnyObjectId id)
                        throws MissingObjectException, IncorrectObjectTypeException,
                        IOException {
-               RevWalk rw = new RevWalk(db);
-               try {
+               try (RevWalk rw = new RevWalk(db)) {
                        return rw.parseCommit(id);
-               } finally {
-                       rw.release();
                }
        }
 
        private ObjectId insertTag(final TagBuilder tag) throws IOException,
                        UnsupportedEncodingException {
-               ObjectInserter oi = db.newObjectInserter();
-               try {
+               try (ObjectInserter oi = db.newObjectInserter()) {
                        ObjectId id = oi.insert(tag);
                        oi.flush();
                        return id;
-               } finally {
-                       oi.release();
                }
        }
 
        private RevTag parseTag(AnyObjectId id) throws MissingObjectException,
                        IncorrectObjectTypeException, IOException {
-               RevWalk rw = new RevWalk(db);
-               try {
+               try (RevWalk rw = new RevWalk(db)) {
                        return rw.parseTag(id);
-               } finally {
-                       rw.release();
                }
        }
 
index 48debae93223de297b33badf82f203baada3af11..7a115e10760608b59fd3c0ea9bf9a8a50b1c04a0 100644 (file)
@@ -356,15 +356,12 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
        }
 
        ObjectId genSha1(String data) {
-               ObjectInserter w = db.newObjectInserter();
-               try {
+               try (ObjectInserter w = db.newObjectInserter()) {
                        ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes());
                        w.flush();
                        return id;
                } catch (IOException e) {
                        fail(e.toString());
-               } finally {
-                       w.release();
                }
                return null;
        }
index a85198f0192fa8621b63db2b25b57cac238b0659..a5cd7b5c0b8760121ca7cf8da393f1480f84f083 100644 (file)
@@ -384,13 +384,10 @@ public class IndexDiffTest extends RepositoryTestCase {
        }
 
        private ObjectId insertTree(Tree tree) throws IOException {
-               ObjectInserter oi = db.newObjectInserter();
-               try {
+               try (ObjectInserter oi = db.newObjectInserter()) {
                        ObjectId id = oi.insert(Constants.OBJ_TREE, tree.format());
                        oi.flush();
                        return id;
-               } finally {
-                       oi.release();
                }
        }
 
index cf8d42f724bcf338aaf4a83bb40e038a9b8fee59..7b6d7d4b0da477b5d4a6fce4a8dd49a06472a011 100644 (file)
@@ -109,14 +109,11 @@ public class ReflogConfigTest extends RepositoryTestCase {
                commit.setAuthor(author);
                commit.setCommitter(committer);
                commit.setMessage(commitMsg);
-               ObjectInserter inserter = db.newObjectInserter();
                ObjectId id;
-               try {
+               try (ObjectInserter inserter = db.newObjectInserter()) {
                        commit.setTreeId(inserter.insert(new TreeFormatter()));
                        id = inserter.insert(commit);
                        inserter.flush();
-               } finally {
-                       inserter.release();
                }
 
                int nl = commitMsg.indexOf('\n');
index 91608ead13b8a07ec83d70e97049bdbc95eac13f..d3a6f18389c6db3ab722c76059290b3f66311d5d 100644 (file)
@@ -86,8 +86,8 @@ public class DefaultNoteMergerTest extends RepositoryTestCase {
        @Override
        @After
        public void tearDown() throws Exception {
-               reader.release();
-               inserter.release();
+               reader.close();
+               inserter.close();
                super.tearDown();
        }
 
index 8010fb1aacbe8f7c154da834011a8d022b601f09..be7bead6bd8d960708089f1d3b3c70f90ca9a2f6 100644 (file)
@@ -127,8 +127,8 @@ public class NoteMapMergerTest extends RepositoryTestCase {
        @Override
        @After
        public void tearDown() throws Exception {
-               reader.release();
-               inserter.release();
+               reader.close();
+               inserter.close();
                super.tearDown();
        }
 
index c2f63d617fc4165d841158678def7a2123fd5d4c..4539a013f30426b6664f903cef3732551eb62b70 100644 (file)
@@ -91,8 +91,8 @@ public class NoteMapTest extends RepositoryTestCase {
        @Override
        @After
        public void tearDown() throws Exception {
-               reader.release();
-               inserter.release();
+               reader.close();
+               inserter.close();
                super.tearDown();
        }
 
index dfde7fcf2c222cfd4d12312b273736f8d0ab0ec4..2a59f58c66f659a9de793fdaa6637e2c46e19491 100644 (file)
@@ -229,15 +229,12 @@ public class ObjectWalkTest extends RevWalkTestCase {
                        Tree A_A = A.addTree("A");
                        Tree A_B = A.addTree("B");
 
-                       final ObjectInserter inserter = db.newObjectInserter();
-                       try {
+                       try (final ObjectInserter inserter = db.newObjectInserter()) {
                                A_A.setId(inserter.insert(Constants.OBJ_TREE, A_A.format()));
                                A_B.setId(inserter.insert(Constants.OBJ_TREE, A_B.format()));
                                A.setId(inserter.insert(Constants.OBJ_TREE, A.format()));
                                root.setId(inserter.insert(Constants.OBJ_TREE, root.format()));
                                inserter.flush();
-                       } finally {
-                               inserter.release();
                        }
 
                        tree_root = rw.parseTree(root.getId());
index 855bb805699b9b0bdd163c7d876f601c8af5ce7c..10bea0a8b5a29bdb307e0865c0e9f395fd64fec9 100644 (file)
@@ -103,12 +103,9 @@ public class RevWalkUtilsReachableTest extends RevWalkTestCase {
                RevCommit a = commit();
                Ref branchA = branch("a", a);
 
-               RevWalk walk = new RevWalk(db);
-               try {
+               try (RevWalk walk = new RevWalk(db)) {
                        RevCommit parsedCommit = walk.parseCommit(a.getId());
                        assertContains(parsedCommit, asList(branchA));
-               } finally {
-                       walk.release();
                }
        }
 
index 6859dd53a66c13d57fe9b2a05ebbf18fc7acd95e..c829be900e7c430cc9d5e1dff2b8f796301cd27d 100644 (file)
@@ -486,8 +486,9 @@ public class PackParserTest extends RepositoryTestCase {
 
        @After
        public void release() {
-               if (inserter != null)
-                       inserter.release();
+               if (inserter != null) {
+                       inserter.close();
+               }
        }
 
        private PackParser index(InputStream in) throws IOException {
index 2bd907767702892cab831fecc0f77e3c7d71d711..aa5914fe032836ad1b6d5d8e8075ebf651ceeab6 100644 (file)
@@ -543,8 +543,9 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
 
        @After
        public void release() {
-               if (inserter != null)
-                       inserter.release();
+               if (inserter != null) {
+                       inserter.close();
+               }
        }
 
        private void openPack(TemporaryBuffer.Heap buf) throws IOException {
index 741396c5191c77fd2ba75de2da13af09f4de135a..88754109f73da697ea21023301b1b06bbbf858fe 100644 (file)
@@ -89,20 +89,19 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase {
                DirCacheEditor dce = dc.editor();
                final String UNNORMALIZED = "target/";
                final byte[] UNNORMALIZED_BYTES = Constants.encode(UNNORMALIZED);
-               ObjectInserter oi = db.newObjectInserter();
-               final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
-                               UNNORMALIZED_BYTES, 0,
-                               UNNORMALIZED_BYTES.length);
-               oi.release();
-               dce.add(new DirCacheEditor.PathEdit("link") {
-                       @Override
-                       public void apply(DirCacheEntry ent) {
-                               ent.setFileMode(FileMode.SYMLINK);
-                               ent.setObjectId(linkid);
-                               ent.setLength(UNNORMALIZED_BYTES.length);
-                       }
-               });
-               assertTrue(dce.commit());
+               try (ObjectInserter oi = db.newObjectInserter()) {
+                       final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
+                                       UNNORMALIZED_BYTES, 0, UNNORMALIZED_BYTES.length);
+                       dce.add(new DirCacheEditor.PathEdit("link") {
+                               @Override
+                               public void apply(DirCacheEntry ent) {
+                                       ent.setFileMode(FileMode.SYMLINK);
+                                       ent.setObjectId(linkid);
+                                       ent.setLength(UNNORMALIZED_BYTES.length);
+                               }
+                       });
+                       assertTrue(dce.commit());
+               }
                new Git(db).commit().setMessage("Adding link").call();
                new Git(db).reset().setMode(ResetType.HARD).call();
                DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
@@ -129,19 +128,19 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase {
                DirCacheEditor dce = dc.editor();
                final String NORMALIZED = "target";
                final byte[] NORMALIZED_BYTES = Constants.encode(NORMALIZED);
-               ObjectInserter oi = db.newObjectInserter();
-               final ObjectId linkid = oi.insert(Constants.OBJ_BLOB, NORMALIZED_BYTES,
-                               0, NORMALIZED_BYTES.length);
-               oi.release();
-               dce.add(new DirCacheEditor.PathEdit("link") {
-                       @Override
-                       public void apply(DirCacheEntry ent) {
-                               ent.setFileMode(FileMode.SYMLINK);
-                               ent.setObjectId(linkid);
-                               ent.setLength(NORMALIZED_BYTES.length);
-                       }
-               });
-               assertTrue(dce.commit());
+               try (ObjectInserter oi = db.newObjectInserter()) {
+                       final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
+                                       NORMALIZED_BYTES, 0, NORMALIZED_BYTES.length);
+                       dce.add(new DirCacheEditor.PathEdit("link") {
+                               @Override
+                               public void apply(DirCacheEntry ent) {
+                                       ent.setFileMode(FileMode.SYMLINK);
+                                       ent.setObjectId(linkid);
+                                       ent.setLength(NORMALIZED_BYTES.length);
+                               }
+                       });
+                       assertTrue(dce.commit());
+               }
                new Git(db).commit().setMessage("Adding link").call();
                new Git(db).reset().setMode(ResetType.HARD).call();
                DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
@@ -166,21 +165,21 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase {
        public void testSymlinkActuallyModified() throws Exception {
                final String NORMALIZED = "target";
                final byte[] NORMALIZED_BYTES = Constants.encode(NORMALIZED);
-               ObjectInserter oi = db.newObjectInserter();
-               final ObjectId linkid = oi.insert(Constants.OBJ_BLOB, NORMALIZED_BYTES,
-                               0, NORMALIZED_BYTES.length);
-               oi.release();
-               DirCache dc = db.lockDirCache();
-               DirCacheEditor dce = dc.editor();
-               dce.add(new DirCacheEditor.PathEdit("link") {
-                       @Override
-                       public void apply(DirCacheEntry ent) {
-                               ent.setFileMode(FileMode.SYMLINK);
-                               ent.setObjectId(linkid);
-                               ent.setLength(NORMALIZED_BYTES.length);
-                       }
-               });
-               assertTrue(dce.commit());
+               try (ObjectInserter oi = db.newObjectInserter()) {
+                       final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
+                                       NORMALIZED_BYTES, 0, NORMALIZED_BYTES.length);
+                       DirCache dc = db.lockDirCache();
+                       DirCacheEditor dce = dc.editor();
+                       dce.add(new DirCacheEditor.PathEdit("link") {
+                               @Override
+                               public void apply(DirCacheEntry ent) {
+                                       ent.setFileMode(FileMode.SYMLINK);
+                                       ent.setObjectId(linkid);
+                                       ent.setLength(NORMALIZED_BYTES.length);
+                               }
+                       });
+                       assertTrue(dce.commit());
+               }
                new Git(db).commit().setMessage("Adding link").call();
                new Git(db).reset().setMode(ResetType.HARD).call();
 
index 7964578c364567aac129bddb303283d37d63be76..767e13d114b6442b8d0d332b48395a575bd756b2 100644 (file)
@@ -274,9 +274,9 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
                ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
                assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
                                fromRaw.getName());
-               ObjectReader objectReader = db.newObjectReader();
-               assertFalse(fti.isModified(dce, false, objectReader));
-               objectReader.release();
+               try (ObjectReader objectReader = db.newObjectReader()) {
+                       assertFalse(fti.isModified(dce, false, objectReader));
+               }
        }
 
        @Test
@@ -291,15 +291,15 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
                // Modify previously committed DirCacheEntry and write it back to disk
                DirCacheEntry dce = db.readDirCache().getEntry("symlink");
                dce.setFileMode(FileMode.SYMLINK);
-               ObjectReader objectReader = db.newObjectReader();
-               DirCacheCheckout.checkoutEntry(db, dce, objectReader);
-
-               FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
-                               .getConfig().get(WorkingTreeOptions.KEY));
-               while (!fti.getEntryPathString().equals("symlink"))
-                       fti.next(1);
-               assertFalse(fti.isModified(dce, false, objectReader));
-               objectReader.release();
+               try (ObjectReader objectReader = db.newObjectReader()) {
+                       DirCacheCheckout.checkoutEntry(db, dce, objectReader);
+
+                       FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(),
+                                       db.getConfig().get(WorkingTreeOptions.KEY));
+                       while (!fti.getEntryPathString().equals("symlink"))
+                               fti.next(1);
+                       assertFalse(fti.isModified(dce, false, objectReader));
+               }
        }
 
        @Test
@@ -327,9 +327,9 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
                // If the rounding trick does not work we could skip the compareMetaData
                // test and hope that we are usually testing the intended code path.
                assertEquals(MetadataDiff.SMUDGED, fti.compareMetadata(dce));
-               ObjectReader objectReader = db.newObjectReader();
-               assertTrue(fti.isModified(dce, false, objectReader));
-               objectReader.release();
+               try (ObjectReader objectReader = db.newObjectReader()) {
+                       assertTrue(fti.isModified(dce, false, objectReader));
+               }
        }
 
        @Test
index 59c4a8d1bbc956f0316d9cdf03f0dbe156a2c0f9..eaee8bb4b94d83b59a604cc3968a8601eefe07da 100644 (file)
@@ -68,70 +68,69 @@ public class ForPathTest extends RepositoryTestCase {
        public void testFindObjects() throws Exception {
                final DirCache tree0 = DirCache.newInCore();
                final DirCacheBuilder b0 = tree0.builder();
-               ObjectReader or = db.newObjectReader();
-               ObjectInserter oi = db.newObjectInserter();
-
-               DirCacheEntry aDotB = createEntry("a.b", EXECUTABLE_FILE);
-               b0.add(aDotB);
-               DirCacheEntry aSlashB = createEntry("a/b", REGULAR_FILE);
-               b0.add(aSlashB);
-               DirCacheEntry aSlashCSlashD = createEntry("a/c/d", REGULAR_FILE);
-               b0.add(aSlashCSlashD);
-               DirCacheEntry aZeroB = createEntry("a0b", SYMLINK);
-               b0.add(aZeroB);
-               b0.finish();
-               assertEquals(4, tree0.getEntryCount());
-               ObjectId tree = tree0.writeTree(oi);
-
-               // Find the directories that were implicitly created above.
-               TreeWalk tw = new TreeWalk(or);
-               tw.addTree(tree);
-               ObjectId a = null;
-               ObjectId aSlashC = null;
-               while (tw.next()) {
-                       if (tw.getPathString().equals("a")) {
-                               a = tw.getObjectId(0);
-                               tw.enterSubtree();
-                               while (tw.next()) {
-                                       if (tw.getPathString().equals("a/c")) {
-                                               aSlashC = tw.getObjectId(0);
-                                               break;
+               try (ObjectReader or = db.newObjectReader();
+                               ObjectInserter oi = db.newObjectInserter()) {
+
+                       DirCacheEntry aDotB = createEntry("a.b", EXECUTABLE_FILE);
+                       b0.add(aDotB);
+                       DirCacheEntry aSlashB = createEntry("a/b", REGULAR_FILE);
+                       b0.add(aSlashB);
+                       DirCacheEntry aSlashCSlashD = createEntry("a/c/d", REGULAR_FILE);
+                       b0.add(aSlashCSlashD);
+                       DirCacheEntry aZeroB = createEntry("a0b", SYMLINK);
+                       b0.add(aZeroB);
+                       b0.finish();
+                       assertEquals(4, tree0.getEntryCount());
+                       ObjectId tree = tree0.writeTree(oi);
+
+                       // Find the directories that were implicitly created above.
+                       TreeWalk tw = new TreeWalk(or);
+                       tw.addTree(tree);
+                       ObjectId a = null;
+                       ObjectId aSlashC = null;
+                       while (tw.next()) {
+                               if (tw.getPathString().equals("a")) {
+                                       a = tw.getObjectId(0);
+                                       tw.enterSubtree();
+                                       while (tw.next()) {
+                                               if (tw.getPathString().equals("a/c")) {
+                                                       aSlashC = tw.getObjectId(0);
+                                                       break;
+                                               }
                                        }
+                                       break;
                                }
-                               break;
                        }
-               }
-
-               assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
-               assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));
-               assertEquals(null, TreeWalk.forPath(or, "/a", tree));
-               assertEquals(null, TreeWalk.forPath(or, "/a/", tree));
-
-               assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b", tree)
-                               .getObjectId(0));
-               assertEquals(null, TreeWalk.forPath(or, "/a.b", tree));
-               assertEquals(null, TreeWalk.forPath(or, "/a.b/", tree));
-               assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b/", tree)
-                               .getObjectId(0));
-
-               assertEquals(aZeroB.getObjectId(), TreeWalk.forPath(or, "a0b", tree)
-                               .getObjectId(0));
 
-               assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "a/b", tree)
-                               .getObjectId(0));
-               assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "b", a)
-                               .getObjectId(0));
-
-               assertEquals(aSlashC, TreeWalk.forPath(or, "a/c", tree).getObjectId(0));
-               assertEquals(aSlashC, TreeWalk.forPath(or, "c", a).getObjectId(0));
-
-               assertEquals(aSlashCSlashD.getObjectId(),
-                               TreeWalk.forPath(or, "a/c/d", tree).getObjectId(0));
-               assertEquals(aSlashCSlashD.getObjectId(), TreeWalk
-                               .forPath(or, "c/d", a).getObjectId(0));
-
-               or.release();
-               oi.release();
+                       assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
+                       assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));
+                       assertEquals(null, TreeWalk.forPath(or, "/a", tree));
+                       assertEquals(null, TreeWalk.forPath(or, "/a/", tree));
+
+                       assertEquals(aDotB.getObjectId(),
+                                       TreeWalk.forPath(or, "a.b", tree).getObjectId(0));
+                       assertEquals(null, TreeWalk.forPath(or, "/a.b", tree));
+                       assertEquals(null, TreeWalk.forPath(or, "/a.b/", tree));
+                       assertEquals(aDotB.getObjectId(),
+                                       TreeWalk.forPath(or, "a.b/", tree).getObjectId(0));
+
+                       assertEquals(aZeroB.getObjectId(),
+                                       TreeWalk.forPath(or, "a0b", tree).getObjectId(0));
+
+                       assertEquals(aSlashB.getObjectId(),
+                                       TreeWalk.forPath(or, "a/b", tree).getObjectId(0));
+                       assertEquals(aSlashB.getObjectId(),
+                                       TreeWalk.forPath(or, "b", a).getObjectId(0));
+
+                       assertEquals(aSlashC,
+                                       TreeWalk.forPath(or, "a/c", tree).getObjectId(0));
+                       assertEquals(aSlashC, TreeWalk.forPath(or, "c", a).getObjectId(0));
+
+                       assertEquals(aSlashCSlashD.getObjectId(),
+                                       TreeWalk.forPath(or, "a/c/d", tree).getObjectId(0));
+                       assertEquals(aSlashCSlashD.getObjectId(),
+                                       TreeWalk.forPath(or, "c/d", a).getObjectId(0));
+               }
        }
 
 }
index b52a727d8d6b27c801a1973cc10eb620b57b80b8..aca7c80fd7ec15bcf93582f96f1345491551af87 100644 (file)
@@ -63,52 +63,51 @@ public class TreeWalkBasicDiffTest extends RepositoryTestCase {
        @Test
        public void testMissingSubtree_DetectFileAdded_FileModified()
                        throws Exception {
-               final ObjectInserter inserter = db.newObjectInserter();
-               final ObjectId aFileId = inserter.insert(OBJ_BLOB, encode("a"));
-               final ObjectId bFileId = inserter.insert(OBJ_BLOB, encode("b"));
-               final ObjectId cFileId1 = inserter.insert(OBJ_BLOB, encode("c-1"));
-               final ObjectId cFileId2 = inserter.insert(OBJ_BLOB, encode("c-2"));
+               final ObjectId oldTree, newTree, bFileId, cFileId1, cFileId2;
+               try (ObjectInserter inserter = db.newObjectInserter()) {
+                       final ObjectId aFileId = inserter.insert(OBJ_BLOB, encode("a"));
+                       bFileId = inserter.insert(OBJ_BLOB, encode("b"));
+                       cFileId1 = inserter.insert(OBJ_BLOB, encode("c-1"));
+                       cFileId2 = inserter.insert(OBJ_BLOB, encode("c-2"));
 
-               // Create sub-a/empty, sub-c/empty = hello.
-               final ObjectId oldTree;
-               {
-                       final Tree root = new Tree(db);
+                       // Create sub-a/empty, sub-c/empty = hello.
                        {
-                               final Tree subA = root.addTree("sub-a");
-                               subA.addFile("empty").setId(aFileId);
-                               subA.setId(inserter.insert(OBJ_TREE, subA.format()));
+                               final Tree root = new Tree(db);
+                               {
+                                       final Tree subA = root.addTree("sub-a");
+                                       subA.addFile("empty").setId(aFileId);
+                                       subA.setId(inserter.insert(OBJ_TREE, subA.format()));
+                               }
+                               {
+                                       final Tree subC = root.addTree("sub-c");
+                                       subC.addFile("empty").setId(cFileId1);
+                                       subC.setId(inserter.insert(OBJ_TREE, subC.format()));
+                               }
+                               oldTree = inserter.insert(OBJ_TREE, root.format());
                        }
-                       {
-                               final Tree subC = root.addTree("sub-c");
-                               subC.addFile("empty").setId(cFileId1);
-                               subC.setId(inserter.insert(OBJ_TREE, subC.format()));
-                       }
-                       oldTree = inserter.insert(OBJ_TREE, root.format());
-               }
 
-               // Create sub-a/empty, sub-b/empty, sub-c/empty.
-               final ObjectId newTree;
-               {
-                       final Tree root = new Tree(db);
-                       {
-                               final Tree subA = root.addTree("sub-a");
-                               subA.addFile("empty").setId(aFileId);
-                               subA.setId(inserter.insert(OBJ_TREE, subA.format()));
-                       }
-                       {
-                               final Tree subB = root.addTree("sub-b");
-                               subB.addFile("empty").setId(bFileId);
-                               subB.setId(inserter.insert(OBJ_TREE, subB.format()));
-                       }
+                       // Create sub-a/empty, sub-b/empty, sub-c/empty.
                        {
-                               final Tree subC = root.addTree("sub-c");
-                               subC.addFile("empty").setId(cFileId2);
-                               subC.setId(inserter.insert(OBJ_TREE, subC.format()));
+                               final Tree root = new Tree(db);
+                               {
+                                       final Tree subA = root.addTree("sub-a");
+                                       subA.addFile("empty").setId(aFileId);
+                                       subA.setId(inserter.insert(OBJ_TREE, subA.format()));
+                               }
+                               {
+                                       final Tree subB = root.addTree("sub-b");
+                                       subB.addFile("empty").setId(bFileId);
+                                       subB.setId(inserter.insert(OBJ_TREE, subB.format()));
+                               }
+                               {
+                                       final Tree subC = root.addTree("sub-c");
+                                       subC.addFile("empty").setId(cFileId2);
+                                       subC.setId(inserter.insert(OBJ_TREE, subC.format()));
+                               }
+                               newTree = inserter.insert(OBJ_TREE, root.format());
                        }
-                       newTree = inserter.insert(OBJ_TREE, root.format());
+                       inserter.flush();
                }
-               inserter.flush();
-               inserter.release();
 
                final TreeWalk tw = new TreeWalk(db);
                tw.reset(oldTree, newTree);
index a6d672e7f3738579999419a992d59999f43c7993..fa6fe75e644d3daf30bb6efaf550e60c58efb63f 100644 (file)
@@ -936,14 +936,6 @@ public class BlameGenerator implements AutoCloseable {
                return queue != null ? queue.sourceText : null;
        }
 
-       /**
-        * Release the current blame session. Use {@link #close()} instead.
-        */
-       @Deprecated
-       public void release() {
-               close();
-       }
-
        /**
         * Release the current blame session.
         *
index b71e9902cc12798a70ea2211ebd775a71557fc67..bcc30c35b41cdf7010d12e4d6b6959250dbeace0 100644 (file)
@@ -380,14 +380,6 @@ public class DiffFormatter implements AutoCloseable {
                out.flush();
        }
 
-       /**
-        * Release the internal ObjectReader state. Use {@link #close()} instead.
-        */
-       @Deprecated
-       public void release() {
-               close();
-       }
-
        /**
         * Release the internal ObjectReader state.
         *
index 578a3d6cd1eb80edb1b13e82fdd982f20a521e55..488eee97942041ebce002ab0951b6e6f66181a05 100644 (file)
@@ -216,7 +216,7 @@ public class DfsInserter extends ObjectInserter {
        }
 
        @Override
-       public void release() {
+       public void close() {
                if (packOut != null) {
                        try {
                                packOut.close();
@@ -600,7 +600,7 @@ public class DfsInserter extends ObjectInserter {
                }
 
                @Override
-               public void release() {
+               public void close() {
                        ctx.close();
                }
        }
index f5f3375fa13d8ad20356ac449c1396127a2b28d0..a7ab0bb4a372c59dc5750c707f42ef0eee3c6ac4 100644 (file)
@@ -618,7 +618,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
 
        /** Release the current window cursor. */
        @Override
-       public void release() {
+       public void close() {
                last = null;
                block = null;
                baseCache = null;
index eb87460d891a79e2420ccf041f7b0aa92b7afe0b..fb411722be49df196b38501294f0f6c7484e0e70 100644 (file)
@@ -145,7 +145,7 @@ class ObjectDirectoryInserter extends ObjectInserter {
        }
 
        @Override
-       public void release() {
+       public void close() {
                if (deflate != null) {
                        try {
                                deflate.end();
index baaed846c14463810df412c367f7e392408cd491..8fac907270ca3fed7ca5b652868b66b3a4ba2bef 100644 (file)
@@ -1005,14 +1005,6 @@ public class PackWriter implements AutoCloseable {
                return state.snapshot();
        }
 
-       /**
-        * Release all resources used by this writer. Use {@link #close()} instead.
-        */
-       @Deprecated
-       public void release() {
-               close();
-       }
-
        /**
         * Release all resources used by this writer.
         *
index f05326900c1d08c4d0ef664238b730fec33389f3..5d892019ab2c48050bd708402c1735e28fd759bb 100644 (file)
@@ -63,7 +63,7 @@ import org.eclipse.jgit.transport.PackParser;
  * <p>
  * Objects written by an inserter may not be immediately visible for reading
  * after the insert method completes. Callers must invoke either
- * {@link #release()} or {@link #flush()} prior to updating references or
+ * {@link #close()} or {@link #flush()} prior to updating references or
  * otherwise making the returned ObjectIds visible to other code.
  */
 public abstract class ObjectInserter implements AutoCloseable {
@@ -91,7 +91,7 @@ public abstract class ObjectInserter implements AutoCloseable {
                }
 
                @Override
-               public void release() {
+               public void close() {
                        // Do nothing.
                }
        }
@@ -149,8 +149,8 @@ public abstract class ObjectInserter implements AutoCloseable {
                        delegate().flush();
                }
 
-               public void release() {
-                       delegate().release();
+               public void close() {
+                       delegate().close();
                }
        }
 
@@ -416,15 +416,6 @@ public abstract class ObjectInserter implements AutoCloseable {
         */
        public abstract void flush() throws IOException;
 
-       /**
-        * Release any resources used by this inserter.
-        * <p>
-        * An inserter that has been released can be used again, but may need to be
-        * released after the subsequent usage. Use {@link #close()} instead
-        */
-       @Deprecated
-       public abstract void release();
-
        /**
         * Release any resources used by this inserter.
         * <p>
@@ -434,7 +425,5 @@ public abstract class ObjectInserter implements AutoCloseable {
         * @since 4.0
         */
        @Override
-       public void close() {
-               release();
-       }
+       public abstract void close();
 }
index f686c419a45be3e4255c01c45029e2cf522d2c78..4c9af85fa8b0a8b82c524ddf8ae5f1ebc0e324ae 100644 (file)
@@ -421,17 +421,6 @@ public abstract class ObjectReader implements AutoCloseable {
                return null;
        }
 
-       /**
-        * Release any resources used by this reader.
-        * <p>
-        * A reader that has been released can be used again, but may need to be
-        * released after the subsequent usage. Use {@link #close()} instead.
-        */
-       @Deprecated
-       public void release() {
-               // Do nothing.
-       }
-
        /**
         * Release any resources used by this reader.
         * <p>
@@ -442,6 +431,6 @@ public abstract class ObjectReader implements AutoCloseable {
         */
        @Override
        public void close() {
-               release();
+               // Do nothing.
        }
 }
index d1009abae946406115034077ad3e54251168ca54..afb208ecf978579d423dcb4937013f4ee0c20354 100644 (file)
@@ -241,17 +241,6 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
                return reader;
        }
 
-       /**
-        * Release any resources used by this walker's reader.
-        * <p>
-        * A walker that has been released can be used again, but may need to be
-        * released after the subsequent usage. Use {@link #close()} instead.
-        */
-       @Deprecated
-       public void release() {
-               close();
-       }
-
        /**
         * Release any resources used by this walker's reader.
         * <p>
index 40f1d22ed220cf08287161e2348b196cce72cfd6..7d9bca0d1bedc113cf6d732c4f4fea8a9b5d4e9f 100644 (file)
@@ -726,15 +726,6 @@ public class SubmoduleWalk implements AutoCloseable {
                return url != null ? getSubmoduleRemoteUrl(repository, url) : null;
        }
 
-       /**
-        * Release any resources used by this walker's reader. Use {@link #close()}
-        * instead.
-        */
-       @Deprecated
-       public void release() {
-               close();
-       }
-
        /**
         * Release any resources used by this walker's reader.
         *
index a4d2d7e7968dce09dc0105f26d5d5bbb7eef35e9..06e828419d765f28553e0578c665d1574d57b586 100644 (file)
@@ -250,17 +250,6 @@ public class TreeWalk implements AutoCloseable {
                return reader;
        }
 
-       /**
-        * Release any resources used by this walker's reader.
-        * <p>
-        * A walker that has been released can be used again, but may need to be
-        * released after the subsequent usage. Use {@link #close()} instead.
-        */
-       @Deprecated
-       public void release() {
-               close();
-       }
-
        /**
         * Release any resources used by this walker's reader.
         * <p>