Add table to diff view

Pushed-by: Florian Scholdei<florian.scholdei@cloudogu.com>
Pushed-by: Viktor Egorov<viktor.egorov-extern@cloudogu.com>
Pushed-by: k8s-git-ops<admin@cloudogu.com>
Committed-by: Thomas Zerr<thomas.zerr@cloudogu.com>
Co-authored-by: Viktor<viktor.egorov@triology.de>
Co-authored-by: Thomas Zerr<thomas.zerr@cloudogu.com>
Pushed-by: Thomas Zerr<thomas.zerr@cloudogu.com>
This commit is contained in:
Thomas Zerr
2024-09-16 17:52:10 +02:00
parent 96466807be
commit 8f0ed74b7a
18 changed files with 547 additions and 35 deletions

View File

@@ -57,6 +57,8 @@ public class GitDiffResult implements DiffResult {
private final int offset;
private final Integer limit;
private DiffTreeNode tree;
public GitDiffResult(Repository scmRepository,
org.eclipse.jgit.lib.Repository repository,
Differ.Diff diff,
@@ -210,4 +212,32 @@ public class GitDiffResult implements DiffResult {
DiffStatistics stats = new DiffStatistics(addCounter, modifiedCounter, deletedCounter);
return Optional.of(stats);
}
@Override
public Optional<DiffTreeNode> getDiffTree() {
if (this.tree == null) {
tree = DiffTreeNode.createRootNode();
for (DiffEntry diffEntry : diffEntries) {
DiffEntry.Side side = DiffEntry.Side.NEW;
if (diffEntry.getChangeType() == DiffEntry.ChangeType.DELETE) {
side = DiffEntry.Side.OLD;
}
DiffEntry.ChangeType type = diffEntry.getChangeType();
String path = diffEntry.getPath(side);
tree.addChild(path, mapChangeType(type));
}
}
return Optional.of(tree);
}
private DiffFile.ChangeType mapChangeType(DiffEntry.ChangeType changeType) {
return switch (changeType) {
case ADD -> DiffFile.ChangeType.ADD;
case MODIFY -> DiffFile.ChangeType.MODIFY;
case DELETE -> DiffFile.ChangeType.DELETE;
case COPY -> DiffFile.ChangeType.COPY;
case RENAME -> DiffFile.ChangeType.RENAME;
};
}
}