From 88bbfd428b2b7fdf9baf20b2ec5254c3e94ed926 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 10 Jul 2018 22:16:13 +0100 Subject: [PATCH] InitGitDBRepo.create: rewrite to use new Result methods --- .../net/kemitix/gitdb/impl/InitGitDBRepo.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/kemitix/gitdb/impl/InitGitDBRepo.java b/src/main/java/net/kemitix/gitdb/impl/InitGitDBRepo.java index b2cc831..1f8c0ad 100644 --- a/src/main/java/net/kemitix/gitdb/impl/InitGitDBRepo.java +++ b/src/main/java/net/kemitix/gitdb/impl/InitGitDBRepo.java @@ -29,7 +29,6 @@ import org.eclipse.jgit.lib.RepositoryCache; import org.eclipse.jgit.util.FS; import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.*; @@ -52,19 +51,14 @@ class InitGitDBRepo { * * @param dbDir the directory to initialise the repo in */ - static Result create(final Path dbDir) { + static Result create(final Path dbDir) { final InitGitDBRepo initRepo = new InitGitDBRepo(); return initRepo.validDbDir(dbDir.toFile()) .peek(File::mkdirs) - .flatMap(dir -> { - try (Repository repository = RepositoryCache.FileKey.exact(dir, FS.DETECTED).open(false)) { - repository.create(true); - initRepo.createInitialBranchOnMaster(repository); - } catch (IOException e) { - return Result.error(e); - } - return Result.ok(null); - }); + .map(dir -> RepositoryCache.FileKey.exact(dir, FS.DETECTED)) + .andThen(fileKey -> () -> fileKey.open(false)) + .thenWith(repository -> () -> repository.create(true)) + .thenWith(repository -> () -> initRepo.createInitialBranchOnMaster(repository)); } private Result validDbDir(final File dbDir) {