use of org.projectnessie.versioned.Ref in project nessie by projectnessie.
the class TreeApiImpl method getCommitLog.
@Override
public LogResponse getCommitLog(String namedRef, CommitLogParams params) throws NessieNotFoundException {
int max = Math.min(params.maxRecords() != null ? params.maxRecords() : MAX_COMMIT_LOG_ENTRIES, MAX_COMMIT_LOG_ENTRIES);
// we should only allow named references when no paging is defined
Ref endRef = namedRefWithHashOrThrow(namedRef, null == params.pageToken() ? params.endHash() : params.pageToken()).getHash();
boolean fetchAll = FetchOption.isFetchAll(params.fetchOption());
try (Stream<Commit<CommitMeta, Content>> commits = getStore().getCommits(endRef, fetchAll)) {
Stream<LogEntry> logEntries = commits.map(commit -> {
CommitMeta commitMetaWithHash = addHashToCommitMeta(commit.getHash(), commit.getCommitMeta());
ImmutableLogEntry.Builder logEntry = LogEntry.builder();
logEntry.commitMeta(commitMetaWithHash);
if (fetchAll) {
if (commit.getParentHash() != null) {
logEntry.parentCommitHash(commit.getParentHash().asString());
}
if (commit.getOperations() != null) {
commit.getOperations().forEach(op -> {
ContentKey key = ContentKey.of(op.getKey().getElements());
if (op instanceof Put) {
Content content = ((Put<Content>) op).getValue();
logEntry.addOperations(Operation.Put.of(key, content));
}
if (op instanceof Delete) {
logEntry.addOperations(Operation.Delete.of(key));
}
});
}
}
return logEntry.build();
});
logEntries = StreamSupport.stream(StreamUtil.takeUntilIncl(logEntries.spliterator(), x -> Objects.equals(x.getCommitMeta().getHash(), params.startHash())), false);
List<LogEntry> items = filterCommitLog(logEntries, params.filter()).limit(max + 1).collect(Collectors.toList());
if (items.size() == max + 1) {
return ImmutableLogResponse.builder().addAllLogEntries(items.subList(0, max)).isHasMore(true).token(items.get(max).getCommitMeta().getHash()).build();
}
return ImmutableLogResponse.builder().addAllLogEntries(items).build();
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
Aggregations