Reduce method count for GitDBBranch
This commit is contained in:
parent
58daa2a6a6
commit
9b8c4765ae
5 changed files with 12 additions and 23 deletions
|
@ -93,7 +93,7 @@ public interface GitDBBranch {
|
|||
*
|
||||
* @return the branch name
|
||||
*/
|
||||
String name();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the commit id for the head of the branch.
|
||||
|
|
|
@ -33,5 +33,5 @@ public interface GitDBTransaction extends GitDBBranch {
|
|||
*
|
||||
* @return the transaction name
|
||||
*/
|
||||
String name();
|
||||
String getName();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ package net.kemitix.gitdb.impl;
|
|||
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kemitix.gitdb.GitDBBranch;
|
||||
import net.kemitix.gitdb.GitDBTransaction;
|
||||
|
@ -48,6 +49,7 @@ class GitDBBranchImpl implements GitDBBranch {
|
|||
private final GitDBRepo gitDBRepo;
|
||||
private final String userName;
|
||||
private final String userEmailAddress;
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
private static GitDBBranch select(
|
||||
|
@ -83,8 +85,8 @@ class GitDBBranchImpl implements GitDBBranch {
|
|||
@Override
|
||||
public GitDBBranch put(final String key, final String value) throws IOException {
|
||||
final ObjectId newTree = gitDBRepo.writeValue(branchRef, KEY_PREFIX + key, value);
|
||||
final Ref newBranch =
|
||||
gitDBRepo.writeCommit(branchRef, newTree, commitMessageForAdd(key, value), userName, userEmailAddress);
|
||||
final String message = String.format("Add key [%s] = [%s]", key, value);
|
||||
final Ref newBranch = gitDBRepo.writeCommit(branchRef, newTree, message, userName, userEmailAddress);
|
||||
return select(newBranch, gitDBRepo, userName, userEmailAddress);
|
||||
}
|
||||
|
||||
|
@ -95,7 +97,7 @@ class GitDBBranchImpl implements GitDBBranch {
|
|||
final Ref newBranch =
|
||||
gitDBRepo.writeCommit(
|
||||
branchRef, newTree.get(),
|
||||
commitMessageForRemove(key),
|
||||
String.format("Remove Key [%s]", key),
|
||||
userName,
|
||||
userEmailAddress);
|
||||
return select(newBranch, gitDBRepo, userName, userEmailAddress);
|
||||
|
@ -121,22 +123,9 @@ class GitDBBranchImpl implements GitDBBranch {
|
|||
return transaction(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommitId() {
|
||||
return branchRef.getObjectId().name();
|
||||
}
|
||||
|
||||
private String commitMessageForAdd(final String key, final String value) {
|
||||
return String.format("Add key [%s] = [%s]", key, value);
|
||||
}
|
||||
|
||||
private String commitMessageForRemove(final String key) {
|
||||
return String.format("Remove Key [%s]", key);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -71,8 +71,8 @@ class GitDBTransactionImpl implements GitDBTransaction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return branch.name();
|
||||
public String getName() {
|
||||
return branch.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -324,7 +324,7 @@ class GitDBTest implements WithAssertions {
|
|||
final GitDBTransaction transaction = gitDBBranch.transaction(name);
|
||||
//then
|
||||
assertThat(transaction).isNotNull();
|
||||
assertThat(transaction.name()).isEqualTo(name);
|
||||
assertThat(transaction.getName()).isEqualTo(name);
|
||||
}
|
||||
|
||||
// When starting an anonymous transaction then a GitDbTransaction is returned
|
||||
|
@ -336,7 +336,7 @@ class GitDBTest implements WithAssertions {
|
|||
final GitDBTransaction transaction = gitDBBranch.transaction();
|
||||
//then
|
||||
assertThat(transaction).isNotNull();
|
||||
assertThat(transaction.name()).isNotNull();
|
||||
assertThat(transaction.getName()).isNotNull();
|
||||
}
|
||||
|
||||
// When starting an anonymous transaction then original branch is unchanged
|
||||
|
@ -473,7 +473,7 @@ class GitDBTest implements WithAssertions {
|
|||
//then
|
||||
assertThat(secondTransaction).isNotNull();
|
||||
assertThat(secondTransaction).isNotSameAs(firstTransaction);
|
||||
assertThat(secondTransaction.name()).isEqualTo(name);
|
||||
assertThat(secondTransaction.getName()).isEqualTo(name);
|
||||
}
|
||||
|
||||
// Given a GitDbTransaction handle with a added, updated and removed keys
|
||||
|
|
Loading…
Reference in a new issue