Skip to content

Commit

Permalink
[JENKINS-15747] Improved fix: not only cap total number of transitive…
Browse files Browse the repository at this point in the history
… 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 302140b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions core/src/main/java/hudson/model/Cause.java
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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);
Expand Down

0 comments on commit 302140b

Please sign in to comment.