CommitWriter and GitDBRepo return Result<T> values
This commit is contained in:
parent
9eff624a05
commit
ae852be86f
3 changed files with 14 additions and 25 deletions
|
@ -21,10 +21,9 @@
|
||||||
|
|
||||||
package net.kemitix.gitdb.impl;
|
package net.kemitix.gitdb.impl;
|
||||||
|
|
||||||
|
import net.kemitix.mon.result.Result;
|
||||||
import org.eclipse.jgit.lib.*;
|
import org.eclipse.jgit.lib.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits Key/Value updates into the Git Repository.
|
* Commits Key/Value updates into the Git Repository.
|
||||||
*
|
*
|
||||||
|
@ -52,15 +51,14 @@ class CommitWriter {
|
||||||
* @param userName the user name
|
* @param userName the user name
|
||||||
* @param userEmailAddress the user email address
|
* @param userEmailAddress the user email address
|
||||||
* @return the id of the commit
|
* @return the id of the commit
|
||||||
* @throws IOException if there is an error writing the value
|
|
||||||
*/
|
*/
|
||||||
ObjectId write(
|
Result<ObjectId> write(
|
||||||
final ObjectId treeId,
|
final ObjectId treeId,
|
||||||
final ObjectId parentId,
|
final ObjectId parentId,
|
||||||
final String message,
|
final String message,
|
||||||
final String userName,
|
final String userName,
|
||||||
final String userEmailAddress
|
final String userEmailAddress
|
||||||
) throws IOException {
|
) {
|
||||||
final CommitBuilder commitBuilder = new CommitBuilder();
|
final CommitBuilder commitBuilder = new CommitBuilder();
|
||||||
commitBuilder.setTreeId(treeId);
|
commitBuilder.setTreeId(treeId);
|
||||||
commitBuilder.setMessage(message);
|
commitBuilder.setMessage(message);
|
||||||
|
@ -68,7 +66,7 @@ class CommitWriter {
|
||||||
commitBuilder.setAuthor(ident);
|
commitBuilder.setAuthor(ident);
|
||||||
commitBuilder.setCommitter(ident);
|
commitBuilder.setCommitter(ident);
|
||||||
commitBuilder.setParentId(parentId);
|
commitBuilder.setParentId(parentId);
|
||||||
return objectInserter.insert(commitBuilder);
|
return Result.of(() -> objectInserter.insert(commitBuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,15 +80,14 @@ class CommitWriter {
|
||||||
* @param userName the user name
|
* @param userName the user name
|
||||||
* @param userEmailAddress the user email address
|
* @param userEmailAddress the user email address
|
||||||
* @return the id of the commit
|
* @return the id of the commit
|
||||||
* @throws IOException if there is an error writing the value
|
|
||||||
*/
|
*/
|
||||||
ObjectId write(
|
Result<ObjectId> write(
|
||||||
final ObjectId treeId,
|
final ObjectId treeId,
|
||||||
final Ref branchRef,
|
final Ref branchRef,
|
||||||
final String message,
|
final String message,
|
||||||
final String userName,
|
final String userName,
|
||||||
final String userEmailAddress
|
final String userEmailAddress
|
||||||
) throws IOException {
|
) {
|
||||||
return write(treeId, branchRef.getObjectId(), message, userName, userEmailAddress);
|
return write(treeId, branchRef.getObjectId(), message, userName, userEmailAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ 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.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -120,7 +119,6 @@ class GitDBRepo {
|
||||||
* @param userName the user name
|
* @param userName the user name
|
||||||
* @param userEmailAddress the user email address
|
* @param userEmailAddress the user email address
|
||||||
* @return the Ref of the updated branch
|
* @return the Ref of the updated branch
|
||||||
* @throws IOException if there was an error writing the branch
|
|
||||||
*/
|
*/
|
||||||
Result<Ref> writeCommit(
|
Result<Ref> writeCommit(
|
||||||
final Ref branchRef,
|
final Ref branchRef,
|
||||||
|
@ -129,12 +127,9 @@ class GitDBRepo {
|
||||||
final String userName,
|
final String userName,
|
||||||
final String userEmailAddress
|
final String userEmailAddress
|
||||||
) {
|
) {
|
||||||
try {
|
return insertCommit(tree, message, userName, userEmailAddress, branchRef)
|
||||||
final ObjectId commitId = insertCommit(tree, message, userName, userEmailAddress, branchRef);
|
.flatMap(cid -> Result.of(() ->
|
||||||
return Result.ok(headWriter.write(branchRef.getName(), commitId));
|
headWriter.write(branchRef.getName(), cid)));
|
||||||
} catch (IOException e) {
|
|
||||||
return Result.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,15 +141,14 @@ class GitDBRepo {
|
||||||
* @param userName the user name
|
* @param userName the user name
|
||||||
* @param userEmailAddress the user email address
|
* @param userEmailAddress the user email address
|
||||||
* @return the id of the commit
|
* @return the id of the commit
|
||||||
* @throws IOException the commit could not be stored
|
|
||||||
*/
|
*/
|
||||||
ObjectId insertCommit(
|
Result<ObjectId> insertCommit(
|
||||||
final ObjectId treeId,
|
final ObjectId treeId,
|
||||||
final String message,
|
final String message,
|
||||||
final String userName,
|
final String userName,
|
||||||
final String userEmailAddress,
|
final String userEmailAddress,
|
||||||
final Ref branchRef
|
final Ref branchRef
|
||||||
) throws IOException {
|
) {
|
||||||
return commitWriter.write(treeId, branchRef, message, userName, userEmailAddress);
|
return commitWriter.write(treeId, branchRef, message, userName, userEmailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,14 +160,13 @@ class GitDBRepo {
|
||||||
* @param initUser the user name
|
* @param initUser the user name
|
||||||
* @param initEmail the user email address
|
* @param initEmail the user email address
|
||||||
* @return the id of the commit
|
* @return the id of the commit
|
||||||
* @throws IOException if there was an error writing the commit
|
|
||||||
*/
|
*/
|
||||||
ObjectId initialCommit(
|
Result<ObjectId> initialCommit(
|
||||||
final ObjectId treeId,
|
final ObjectId treeId,
|
||||||
final String initMessage,
|
final String initMessage,
|
||||||
final String initUser,
|
final String initUser,
|
||||||
final String initEmail
|
final String initEmail
|
||||||
) throws IOException {
|
) {
|
||||||
return commitWriter.write(treeId, ObjectId.zeroId(), initMessage, initUser, initEmail);
|
return commitWriter.write(treeId, ObjectId.zeroId(), initMessage, initUser, initEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +179,6 @@ class GitDBRepo {
|
||||||
* @param key the key to place the value under
|
* @param key the key to place the value under
|
||||||
* @return an Optional containing the id of the updated tree containing the update, if the key was found, or an
|
* @return an Optional containing the id of the updated tree containing the update, if the key was found, or an
|
||||||
* empty Optional if there key was not found, the there was no changes made
|
* empty Optional if there key was not found, the there was no changes made
|
||||||
* @throws IOException if there was an error writing the value
|
|
||||||
*/
|
*/
|
||||||
Result<Maybe<ObjectId>> removeKey(final Ref branchRef, final String key) {
|
Result<Maybe<ObjectId>> removeKey(final Ref branchRef, final String key) {
|
||||||
return keyRemover.remove(branchRef, key);
|
return keyRemover.remove(branchRef, key);
|
||||||
|
|
|
@ -84,7 +84,7 @@ class InitGitDBRepo {
|
||||||
return new ValueWriter(repository)
|
return new ValueWriter(repository)
|
||||||
.write(new FormatVersion().toBytes())
|
.write(new FormatVersion().toBytes())
|
||||||
.flatMap(oid -> repo.insertNewTree(GIT_DB_VERSION, oid))
|
.flatMap(oid -> repo.insertNewTree(GIT_DB_VERSION, oid))
|
||||||
.flatMap(tid -> Result.of(() -> repo.initialCommit(tid, INIT_MESSAGE, INIT_USER, INIT_EMAIL)))
|
.flatMap(tid -> repo.initialCommit(tid, INIT_MESSAGE, INIT_USER, INIT_EMAIL))
|
||||||
.flatMap(cid -> Result.of(() -> {
|
.flatMap(cid -> Result.of(() -> {
|
||||||
createBranch(repository, cid, MASTER);
|
createBranch(repository, cid, MASTER);
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue