Skip to content
Permalink
Browse files

[JENKINS-15747] Improved fix: not only cap total number of transitive…

… upstream causes but also avoid redundantly storing information about upstream causes listed elsewhere.
  • Loading branch information
jglick committed Feb 1, 2013
1 parent 8b1df85 commit 302140b2c69442e81f7b0b2af9d6e39277ac5674
Showing with 9 additions and 10 deletions.
  1. +9 −10 core/src/main/java/hudson/model/Cause.java
@@ -34,7 +34,8 @@
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nonnull;

/**
@@ -133,9 +134,9 @@ public UpstreamCause(Run<?, ?> up) {
upstreamProject = up.getParent().getFullName();
upstreamUrl = up.getParent().getUrl();
upstreamCauses = new ArrayList<Cause>();
AtomicInteger leaf = new AtomicInteger(MAX_LEAF);
Set<String> traversed = new HashSet<String>();
for (Cause c : up.getCauses()) {
upstreamCauses.add(trim(c, MAX_DEPTH, leaf));
upstreamCauses.add(trim(c, MAX_DEPTH, traversed));
}
}

@@ -146,21 +147,19 @@ private UpstreamCause(String upstreamProject, int upstreamBuild, String upstream
this.upstreamCauses = upstreamCauses;
}

private @Nonnull Cause trim(@Nonnull Cause c, int depth, AtomicInteger leaf) {
private @Nonnull Cause trim(@Nonnull Cause c, int depth, Set<String> traversed) {
if (!(c instanceof UpstreamCause)) {
return c;
}
UpstreamCause uc = (UpstreamCause) c;
List<Cause> cs = new ArrayList<Cause>();
if (depth > 0) {
for (Cause c2 : uc.upstreamCauses) {
if (leaf.decrementAndGet() > 0) {
cs.add(trim(c2, depth - 1, leaf));
} else {
cs.add(new DeeplyNestedUpstreamCause());
if (traversed.add(uc.upstreamUrl + uc.upstreamBuild)) {
for (Cause c2 : uc.upstreamCauses) {
cs.add(trim(c2, depth - 1, traversed));
}
}
} else {
} else if (traversed.size() < MAX_LEAF) {
cs.add(new DeeplyNestedUpstreamCause());
}
return new UpstreamCause(uc.upstreamProject, uc.upstreamBuild, uc.upstreamUrl, cs);

0 comments on commit 302140b

Please sign in to comment.
You can’t perform that action at this time.