From c1edc1a07ebbc4cf7b39a59c9e183db5b37284c2 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 2 Apr 2015 01:11:22 +0200 Subject: [PATCH 1/2] Use try-with-resources to close resources in BaseReceivePack Change-Id: Iacaad1a7e0719541e5616d231422ea6fd4c95161 Signed-off-by: Matthias Sohn --- .../jgit/transport/BaseReceivePack.java | 117 +++++++++--------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java index dfb8ca93a..9bdfbf52e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java @@ -1070,8 +1070,7 @@ public abstract class BaseReceivePack { if (sideBand) resolving = new SideBandProgressMonitor(msgOut); - ObjectInserter ins = db.newObjectInserter(); - try { + try (ObjectInserter ins = db.newObjectInserter()) { String lockMsg = "jgit receive-pack"; //$NON-NLS-1$ if (getRefLogIdent() != null) lockMsg += " from " + getRefLogIdent().toExternalString(); //$NON-NLS-1$ @@ -1089,8 +1088,6 @@ public abstract class BaseReceivePack { packLock = parser.parse(receiving, resolving); packSize = Long.valueOf(parser.getPackSize()); ins.flush(); - } finally { - ins.release(); } if (timeoutIn != null) @@ -1119,67 +1116,69 @@ public abstract class BaseReceivePack { } parser = null; - final ObjectWalk ow = new ObjectWalk(db); - ow.setRetainBody(false); - if (baseObjects != null) { - ow.sort(RevSort.TOPO); - if (!baseObjects.isEmpty()) - ow.sort(RevSort.BOUNDARY, true); - } - - for (final ReceiveCommand cmd : commands) { - if (cmd.getResult() != Result.NOT_ATTEMPTED) - continue; - if (cmd.getType() == ReceiveCommand.Type.DELETE) - continue; - ow.markStart(ow.parseAny(cmd.getNewId())); - } - for (final ObjectId have : advertisedHaves) { - RevObject o = ow.parseAny(have); - ow.markUninteresting(o); - - if (baseObjects != null && !baseObjects.isEmpty()) { - o = ow.peel(o); - if (o instanceof RevCommit) - o = ((RevCommit) o).getTree(); - if (o instanceof RevTree) - ow.markUninteresting(o); + try (final ObjectWalk ow = new ObjectWalk(db)) { + ow.setRetainBody(false); + if (baseObjects != null) { + ow.sort(RevSort.TOPO); + if (!baseObjects.isEmpty()) + ow.sort(RevSort.BOUNDARY, true); } - } - checking.beginTask(JGitText.get().countingObjects, ProgressMonitor.UNKNOWN); - RevCommit c; - while ((c = ow.next()) != null) { - checking.update(1); - if (providedObjects != null // - && !c.has(RevFlag.UNINTERESTING) // - && !providedObjects.contains(c)) - throw new MissingObjectException(c, Constants.TYPE_COMMIT); - } + for (final ReceiveCommand cmd : commands) { + if (cmd.getResult() != Result.NOT_ATTEMPTED) + continue; + if (cmd.getType() == ReceiveCommand.Type.DELETE) + continue; + ow.markStart(ow.parseAny(cmd.getNewId())); + } + for (final ObjectId have : advertisedHaves) { + RevObject o = ow.parseAny(have); + ow.markUninteresting(o); + + if (baseObjects != null && !baseObjects.isEmpty()) { + o = ow.peel(o); + if (o instanceof RevCommit) + o = ((RevCommit) o).getTree(); + if (o instanceof RevTree) + ow.markUninteresting(o); + } + } - RevObject o; - while ((o = ow.nextObject()) != null) { - checking.update(1); - if (o.has(RevFlag.UNINTERESTING)) - continue; + checking.beginTask(JGitText.get().countingObjects, + ProgressMonitor.UNKNOWN); + RevCommit c; + while ((c = ow.next()) != null) { + checking.update(1); + if (providedObjects != null // + && !c.has(RevFlag.UNINTERESTING) // + && !providedObjects.contains(c)) + throw new MissingObjectException(c, Constants.TYPE_COMMIT); + } - if (providedObjects != null) { - if (providedObjects.contains(o)) + RevObject o; + while ((o = ow.nextObject()) != null) { + checking.update(1); + if (o.has(RevFlag.UNINTERESTING)) continue; - else - throw new MissingObjectException(o, o.getType()); - } - if (o instanceof RevBlob && !db.hasObject(o)) - throw new MissingObjectException(o, Constants.TYPE_BLOB); - } - checking.endTask(); + if (providedObjects != null) { + if (providedObjects.contains(o)) + continue; + else + throw new MissingObjectException(o, o.getType()); + } - if (baseObjects != null) { - for (ObjectId id : baseObjects) { - o = ow.parseAny(id); - if (!o.has(RevFlag.UNINTERESTING)) - throw new MissingObjectException(o, o.getType()); + if (o instanceof RevBlob && !db.hasObject(o)) + throw new MissingObjectException(o, Constants.TYPE_BLOB); + } + checking.endTask(); + + if (baseObjects != null) { + for (ObjectId id : baseObjects) { + o = ow.parseAny(id); + if (!o.has(RevFlag.UNINTERESTING)) + throw new MissingObjectException(o, o.getType()); + } } } } @@ -1502,7 +1501,7 @@ public abstract class BaseReceivePack { * the pack could not be unlocked. */ protected void release() throws IOException { - walk.release(); + walk.close(); unlockPack(); timeoutIn = null; rawIn = null; From 21eee62f7d55cf4da69df3f2210e66900652d3ed Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 2 Apr 2015 01:12:22 +0200 Subject: [PATCH 2/2] Remove unnecessary $NON-NLS comment in BaseReceivePack Change-Id: I184945ee29fb9a6b1f30aec88958375e7b5239b3 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/transport/BaseReceivePack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java index 9bdfbf52e..b7a599bad 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java @@ -317,7 +317,7 @@ public abstract class BaseReceivePack { "denynonfastforwards", false); //$NON-NLS-1$ allowOfsDelta = config.getBoolean("repack", "usedeltabaseoffset", //$NON-NLS-1$ //$NON-NLS-2$ true); - certNonceSeed = config.getString("receive", null, "certnonceseed"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + certNonceSeed = config.getString("receive", null, "certnonceseed"); //$NON-NLS-1$ //$NON-NLS-2$ certNonceSlopLimit = config.getInt("receive", "certnonceslop", 0); //$NON-NLS-1$ //$NON-NLS-2$ }