HeadWriter: avoid the Law of Demeter
This commit is contained in:
parent
23b9caebf5
commit
058572ab91
1 changed files with 14 additions and 5 deletions
|
@ -27,6 +27,7 @@ import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -49,15 +50,23 @@ class HeadWriter {
|
||||||
* @return the Ref of the new branch
|
* @return the Ref of the new branch
|
||||||
*/
|
*/
|
||||||
Result<Ref> write(final String branchName, final ObjectId commitId) {
|
Result<Ref> write(final String branchName, final ObjectId commitId) {
|
||||||
final Path branchRefPath = repository
|
final Path branchRefPath = branchRefPath(branchName).toAbsolutePath();
|
||||||
.getDirectory()
|
|
||||||
.toPath()
|
|
||||||
.resolve(branchName)
|
|
||||||
.toAbsolutePath();
|
|
||||||
final byte[] commitIdBytes = commitId.name().getBytes(StandardCharsets.UTF_8);
|
final byte[] commitIdBytes = commitId.name().getBytes(StandardCharsets.UTF_8);
|
||||||
return Result.of(() -> {
|
return Result.of(() -> {
|
||||||
Files.write(branchRefPath, commitIdBytes);
|
Files.write(branchRefPath, commitIdBytes);
|
||||||
return repository.findRef(branchName);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue