Fix duplicate "Needed By" pointers between changes
Sometimes multiple "Needed By" pointers to the same change were shown
in the web UI, as multiple patch sets of that other change used this
change as an ancestor. Fix that by taking a distinct set of them.
Change-Id: I6d28937008688d1610f5bab1f121fc83ed20c067
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java
index d641c86..2855e31 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java
@@ -199,11 +199,14 @@
}
final RevId cprev = loader.patchSet.getRevision();
- final List<PatchSetAncestor> descendants =
- cprev != null ? db.patchSetAncestors().descendantsOf(cprev).toList()
- : Collections.<PatchSetAncestor> emptyList();
- for (final PatchSetAncestor a : descendants) {
- changesToGet.add(a.getPatchSet().getParentKey());
+ final Set<Change.Id> descendants = new HashSet<Change.Id>();
+ if (cprev != null) {
+ for (PatchSetAncestor a : db.patchSetAncestors().descendantsOf(cprev)) {
+ final Change.Id ck = a.getPatchSet().getParentKey();
+ if (descendants.add(ck)) {
+ changesToGet.add(a.getPatchSet().getParentKey());
+ }
+ }
}
final Map<Change.Id, Change> m =
db.changes().toMap(db.changes().get(changesToGet));
@@ -218,8 +221,8 @@
}
final ArrayList<ChangeInfo> neededBy = new ArrayList<ChangeInfo>();
- for (final PatchSetAncestor a : descendants) {
- final Change ac = m.get(a.getPatchSet().getParentKey());
+ for (final Change.Id a : descendants) {
+ final Change ac = m.get(a);
if (ac != null) {
aic.want(ac.getOwner());
neededBy.add(new ChangeInfo(ac));