KeyRemover.insertTree: rewrite without try/catch block

This commit is contained in:
Paul Campbell 2018-07-10 22:19:51 +01:00
parent 88bbfd428b
commit 20e6ba3f84

View file

@ -26,7 +26,6 @@ import net.kemitix.mon.maybe.Maybe;
import net.kemitix.mon.result.Result; import net.kemitix.mon.result.Result;
import org.eclipse.jgit.lib.*; import org.eclipse.jgit.lib.*;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -101,10 +100,8 @@ class KeyRemover {
* @return the name of the tree object. * @return the name of the tree object.
*/ */
private Result<ObjectId> insertTree(final TreeFormatter treeFormatter) { private Result<ObjectId> insertTree(final TreeFormatter treeFormatter) {
try (ObjectInserter inserter = repository.getObjectDatabase().newInserter()) { return Result.ok(repository.getObjectDatabase())
return Result.ok(inserter.insert(treeFormatter)); .map(ObjectDatabase::newInserter)
} catch (IOException e) { .andThen(inserter -> () -> inserter.insert(treeFormatter));
return Result.error(e);
}
} }
} }