diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2015-04-11 00:21:39 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-05-21 02:05:45 +0200 |
commit | 686124bec32fcdee1545e7d9c312dcf0276b44af (patch) | |
tree | cd98b171d3b97de6972bf1f606f34d72eaf5fa12 /org.eclipse.jgit.pgm | |
parent | 0e73d395061d1bfee365acaa2f79c392175d13bf (diff) | |
download | jgit-686124bec32fcdee1545e7d9c312dcf0276b44af.tar.gz jgit-686124bec32fcdee1545e7d9c312dcf0276b44af.zip |
Replace deprecated release() methods by close()
See the discussion [1] in the Gerrit mailing list.
[1] https://groups.google.com/forum/#!topic/repo-discuss/RRQT_xCqz4o
Change-Id: I2c67384309c5c2e8511a7d0d4e088b4e95f819ff
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
12 files changed, 60 insertions, 92 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java index d226df21bb..fde0a78bf6 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java @@ -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()); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java index 271e934b45..0f541715ab 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java @@ -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(); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java index 7147544d1b..72e37158cd 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java @@ -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(); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java index fe2df65541..61a385df83 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java @@ -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(); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java index 4afb6d5f88..22f3be9afd 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java @@ -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(); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java index 688de2c499..d43424c7ce 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java @@ -223,7 +223,7 @@ class Log extends RevWalkTextBuiltin { super.run(); } finally { - diffFmt.release(); + diffFmt.close(); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java index 111933790e..4268f214fd 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java @@ -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(); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java index a33a2d4dff..b668139b5e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java @@ -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(); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java index 91b5917155..24d717dfd8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java @@ -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>() { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index afa469636c..494055a265 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -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; } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java index 4205140bb9..dcfa8cf00a 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java @@ -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) { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java index 087dbb0679..229fb67b0c 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java @@ -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); |