use of com.google.gerrit.server.change.RelatedChangesSorter.PatchSetData in project gerrit by GerritCodeReview.
the class GetRelated method getRelated.
private List<ChangeAndCommit> getRelated(RevisionResource rsrc) throws OrmException, IOException {
Set<String> groups = getAllGroups(rsrc.getNotes());
if (groups.isEmpty()) {
return Collections.emptyList();
}
List<ChangeData> cds = queryProvider.get().enforceVisibility(true).byProjectGroups(rsrc.getChange().getProject(), groups);
if (cds.isEmpty()) {
return Collections.emptyList();
}
if (cds.size() == 1 && cds.get(0).getId().equals(rsrc.getChange().getId())) {
return Collections.emptyList();
}
List<ChangeAndCommit> result = new ArrayList<>(cds.size());
boolean isEdit = rsrc.getEdit().isPresent();
PatchSet basePs = isEdit ? rsrc.getEdit().get().getBasePatchSet() : rsrc.getPatchSet();
reloadChangeIfStale(cds, basePs);
for (PatchSetData d : sorter.sort(cds, basePs)) {
PatchSet ps = d.patchSet();
RevCommit commit;
if (isEdit && ps.getId().equals(basePs.getId())) {
// Replace base of an edit with the edit itself.
ps = rsrc.getPatchSet();
commit = rsrc.getEdit().get().getEditCommit();
} else {
commit = d.commit();
}
result.add(new ChangeAndCommit(d.data().change(), ps, commit));
}
if (result.size() == 1) {
ChangeAndCommit r = result.get(0);
if (r.commit != null && r.commit.commit.equals(rsrc.getPatchSet().getRevision().get())) {
return Collections.emptyList();
}
}
return result;
}
Aggregations