From 058572ab919205f3bea5595819726b7208ce23e0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 20 Jul 2018 07:36:58 +0100 Subject: [PATCH] HeadWriter: avoid the Law of Demeter --- .../net/kemitix/gitdb/impl/HeadWriter.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java b/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java index c9d6351..f7f668d 100644 --- a/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java +++ b/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java @@ -27,6 +27,7 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; +import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -49,15 +50,23 @@ class HeadWriter { * @return the Ref of the new branch */ Result write(final String branchName, final ObjectId commitId) { - final Path branchRefPath = repository - .getDirectory() - .toPath() - .resolve(branchName) - .toAbsolutePath(); + final Path branchRefPath = branchRefPath(branchName).toAbsolutePath(); final byte[] commitIdBytes = commitId.name().getBytes(StandardCharsets.UTF_8); return Result.of(() -> { Files.write(branchRefPath, commitIdBytes); return repository.findRef(branchName); }); } + + private Path branchRefPath(String branchName) { + return gitDirPath().resolve(branchName); + } + + private Path gitDirPath() { + return gitDir().toPath(); + } + + private File gitDir() { + return repository.getDirectory(); + } }