use of com.google.gerrit.server.change.WalkSorter.PatchSetData in project gerrit by GerritCodeReview.
the class WalkSorterTest method subsetOfSeriesOfChangesWithReverseTimestamps.
@Test
public void subsetOfSeriesOfChangesWithReverseTimestamps() throws Exception {
TestRepository<Repo> p = newRepo("p");
RevCommit c0 = p.commit().tick(-1).create();
RevCommit c1 = p.commit().tick(-1).parent(c0).create();
RevCommit c2 = p.commit().tick(-1).parent(c1).create();
RevCommit c3 = p.commit().tick(-1).parent(c2).create();
RevCommit c4 = p.commit().tick(-1).parent(c3).create();
RevWalk rw = p.getRevWalk();
rw.parseCommit(c1);
assertThat(rw.parseCommit(c2).getCommitTime()).isLessThan(c1.getCommitTime());
assertThat(rw.parseCommit(c3).getCommitTime()).isLessThan(c2.getCommitTime());
assertThat(rw.parseCommit(c4).getCommitTime()).isLessThan(c3.getCommitTime());
ChangeData cd1 = newChange(p, c1);
ChangeData cd2 = newChange(p, c2);
ChangeData cd4 = newChange(p, c4);
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd4);
WalkSorter sorter = new WalkSorter(repoManager);
List<PatchSetData> expected = ImmutableList.of(patchSetData(cd4, c4), patchSetData(cd2, c2), patchSetData(cd1, c1));
for (List<ChangeData> list : permutations(changes)) {
// Not inOrder(); since child of c2 is missing, partial topo sort isn't
// guaranteed to work.
assertThat(sorter.sort(list)).containsExactlyElementsIn(expected);
}
}
use of com.google.gerrit.server.change.WalkSorter.PatchSetData in project gerrit by GerritCodeReview.
the class SubmittedTogether method sort.
private ImmutableList<ChangeData> sort(List<ChangeData> cds, int hidden) throws IOException {
if (cds.size() <= 1 && hidden == 0) {
// repo just to fill out the commit field in PatchSetData.
return ImmutableList.of();
}
long numProjectsDistinct = cds.stream().map(ChangeData::project).distinct().count();
long numProjects = cds.stream().map(ChangeData::project).count();
if (numProjects == numProjectsDistinct || numProjectsDistinct > 5) {
// which would make WalkSorter too expensive for this call.
return cds.stream().sorted(COMPARATOR).collect(toImmutableList());
}
// Perform more expensive walk-sort.
ImmutableList.Builder<ChangeData> sorted = ImmutableList.builderWithExpectedSize(cds.size());
for (PatchSetData psd : sorter.get().sort(cds)) {
sorted.add(psd.data());
}
return sorted.build();
}
use of com.google.gerrit.server.change.WalkSorter.PatchSetData in project gerrit by GerritCodeReview.
the class RevertSubmission method revertSubmission.
private RevertSubmissionInfo revertSubmission(List<ChangeData> changeData, RevertInput revertInput) throws RestApiException, IOException, UpdateException, ConfigInvalidException, StorageException, PermissionBackendException {
Multimap<BranchNameKey, ChangeData> changesPerProjectAndBranch = ArrayListMultimap.create();
changeData.stream().forEach(c -> changesPerProjectAndBranch.put(c.change().getDest(), c));
cherryPickInput = createCherryPickInput(revertInput);
Instant timestamp = TimeUtil.now();
for (BranchNameKey projectAndBranch : changesPerProjectAndBranch.keySet()) {
cherryPickInput.base = null;
Project.NameKey project = projectAndBranch.project();
cherryPickInput.destination = projectAndBranch.branch();
if (revertInput.workInProgress) {
cherryPickInput.notify = firstNonNull(cherryPickInput.notify, NotifyHandling.OWNER);
}
Collection<ChangeData> changesInProjectAndBranch = changesPerProjectAndBranch.get(projectAndBranch);
// Sort the changes topologically.
Iterator<PatchSetData> sortedChangesInProjectAndBranch = sorter.sort(changesInProjectAndBranch).iterator();
Set<ObjectId> commitIdsInProjectAndBranch = changesInProjectAndBranch.stream().map(c -> c.currentPatchSet().commitId()).collect(Collectors.toSet());
revertAllChangesInProjectAndBranch(revertInput, project, sortedChangesInProjectAndBranch, commitIdsInProjectAndBranch, timestamp);
}
results.sort(Comparator.comparing(c -> c.revertOf));
RevertSubmissionInfo revertSubmissionInfo = new RevertSubmissionInfo();
revertSubmissionInfo.revertChanges = results;
return revertSubmissionInfo;
}
Aggregations