KeyRemover.remove: refactor - rename GitTreeReader.stream as entries

This commit is contained in:
Paul Campbell 2018-07-21 07:57:17 +01:00
parent 660b74c965
commit 3789afb824
4 changed files with 21 additions and 9 deletions

View file

@ -92,7 +92,7 @@ class GitDBRepo {
}
private Result<Stream<NamedRevBlob>> streamTree(final Ref branchRef, final GitTreeReader treeFilter) {
return treeFilter.stream(branchRef);
return treeFilter.entries(branchRef);
}
/**

View file

@ -55,7 +55,7 @@ class GitTreeReader {
* @param branchRef the branch to read
* @return a stream of key/value pairs as NamedRevBlobs
*/
Result<Stream<NamedRevBlob>> stream(final Ref branchRef) {
Result<Stream<NamedRevBlob>> entries(final Ref branchRef) {
final RevWalk revWalk = new RevWalk(repository);
return Result.of(parseTree(branchRef, revWalk))
.andThen(configureFilter())

View file

@ -24,11 +24,13 @@ package net.kemitix.gitdb.impl;
import lombok.RequiredArgsConstructor;
import net.kemitix.mon.maybe.Maybe;
import net.kemitix.mon.result.Result;
import net.kemitix.mon.result.WithResultContinuation;
import org.eclipse.jgit.lib.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static net.kemitix.conditional.Condition.where;
@ -52,12 +54,22 @@ class KeyRemover {
Result<Maybe<ObjectId>> remove(final Ref branchRef, final String key) {
final TreeFormatter treeFormatter = new TreeFormatter();
final AtomicBoolean removed = new AtomicBoolean(false);
new GitTreeReader(repository)
.stream(branchRef)
.peek(s -> s.peek(flagIfFound(key, removed))
return new GitTreeReader(repository)
.entries(branchRef)
.thenWith(s -> addOthersToTree(key, treeFormatter, removed, s))
.flatMap(s -> insertTree(treeFormatter))
.maybe(oi -> removed.get());
}
private static WithResultContinuation<Stream<NamedRevBlob>> addOthersToTree(
final String key,
final TreeFormatter treeFormatter,
final AtomicBoolean removed,
final Stream<NamedRevBlob> s) {
return () -> s
.peek(flagIfFound(key, removed))
.filter(isNotKey(key))
.forEach(addToTree(treeFormatter)));
return insertTree(treeFormatter).maybe(oi -> removed.get());
.forEach(addToTree(treeFormatter));
}
/**

View file

@ -71,7 +71,7 @@ class KeyWriter {
private Result<TreeFormatter> getTreeFormatter(final Ref branchRef) {
final TreeFormatter treeFormatter = new TreeFormatter();
final GitTreeReader gitTreeReader = new GitTreeReader(repository);
return gitTreeReader.stream(branchRef)
return gitTreeReader.entries(branchRef)
.peek(s -> s.forEach(item -> treeFormatter.append(item.getName(), item.getRevBlob())))
.map(x -> treeFormatter);
}