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 <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-06-28 09:35:55 -07:00
parent 5aae041a81
commit b40f02eb1a
2 changed files with 8 additions and 10 deletions

View File

@ -148,7 +148,12 @@ public boolean merge(final AnyObjectId[] tips) throws IOException {
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();
}
}
/**

View File

@ -154,15 +154,8 @@ else if (tw.isSubtree()) {
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;