From b40f02eb1a2444e4a15ac4d5faef28ae8398f02d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 28 Jun 2010 09:35:55 -0700 Subject: [PATCH] Release ObjectInserter in merge() not mergeImpl() By doing the release at the higher level class, we can ensure the release occurs if the inserter was allocated, even if the implementation forgets to do this. Since the higher level class is what allocated it, it makes sense to have it also do the release. Change-Id: Id617b2db864c3208ed68cba4eda80e51612359ad Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/merge/Merger.java | 7 ++++++- .../jgit/merge/StrategySimpleTwoWayInCore.java | 11 ++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java index 38a8b8eae..d95b11159 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java @@ -148,7 +148,12 @@ public abstract class Merger { for (int i = 0; i < sourceObjects.length; i++) sourceTrees[i] = walk.parseTree(sourceObjects[i]); - return mergeImpl(); + try { + return mergeImpl(); + } finally { + if (inserter != null) + inserter.release(); + } } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java index aa2321b4a..891abe058 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java @@ -154,15 +154,8 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy { return false; try { ObjectInserter odi = getObjectInserter(); - try { - resultTree = cache.writeTree(odi); - odi.flush(); - } finally { - // We don't know if our caller will release the - // inserter, so make sure we do it ourselves. - // - odi.release(); - } + resultTree = cache.writeTree(odi); + odi.flush(); return true; } catch (UnmergedPathException upe) { resultTree = null;