Skip to content

Commit

Permalink
Re-work nested cause trimming algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay committed May 7, 2024
1 parent 1b276a4 commit 625abf4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions core/src/main/java/hudson/model/Cause.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public UpstreamCause(Run<?, ?> up) {
upstreamCauses = new ArrayList<>();
Set<String> traversed = new HashSet<>();
for (Cause c : up.getCauses()) {
if (traversed.size() >= MAX_LEAF) {
upstreamCauses.add(new DeeplyNestedUpstreamCause());
break;
}
upstreamCauses.add(trim(c, MAX_DEPTH, traversed));
}
}
Expand Down Expand Up @@ -239,14 +243,16 @@ public int hashCode() {
}
UpstreamCause uc = (UpstreamCause) c;
List<Cause> cs = new ArrayList<>();
if (depth > 0) {
if (traversed.add(uc.upstreamUrl + uc.upstreamBuild)) {
for (Cause c2 : uc.upstreamCauses) {
cs.add(trim(c2, depth - 1, traversed));
if (traversed.add(uc.upstreamUrl + uc.upstreamBuild)) {
for (Cause c2 : uc.upstreamCauses) {
if (depth <= 0 || traversed.size() >= MAX_LEAF) {
cs.add(new DeeplyNestedUpstreamCause());
break;
}
cs.add(trim(c2, depth - 1, traversed));
}
} else if (traversed.size() < MAX_LEAF) {
cs.add(new DeeplyNestedUpstreamCause());
} else {
traversed.add(uc.upstreamUrl + uc.upstreamBuild + '#' + traversed.size());
}
return new UpstreamCause(uc.upstreamProject, uc.upstreamBuild, uc.upstreamUrl, cs);
}
Expand Down

0 comments on commit 625abf4

Please sign in to comment.