Search in sources :

Example 1 with PatchSetData

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);
    }
}
Also used : PatchSetData(com.google.gerrit.server.change.WalkSorter.PatchSetData) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 2 with PatchSetData

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();
}
Also used : PatchSetData(com.google.gerrit.server.change.WalkSorter.PatchSetData) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 3 with PatchSetData

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;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Arrays(java.util.Arrays) CommitMessageUtil(com.google.gerrit.server.util.CommitMessageUtil) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ProjectCache(com.google.gerrit.server.project.ProjectCache) Inject(com.google.inject.Inject) BooleanCondition.and(com.google.gerrit.extensions.conditions.BooleanCondition.and) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) UpdateException(com.google.gerrit.server.update.UpdateException) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) Matcher(java.util.regex.Matcher) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) UiAction(com.google.gerrit.extensions.webui.UiAction) CREATE_CHANGE(com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE) REVERT(com.google.gerrit.server.permissions.ChangePermission.REVERT) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) Collection(java.util.Collection) ChangeMessages(com.google.gerrit.server.change.ChangeMessages) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BranchNameKey(com.google.gerrit.entities.BranchNameKey) CommitUtil(com.google.gerrit.server.git.CommitUtil) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) ChangeReverted(com.google.gerrit.server.extensions.events.ChangeReverted) InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) ChangeJson(com.google.gerrit.server.change.ChangeJson) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) Pattern(java.util.regex.Pattern) FluentLogger(com.google.common.flogger.FluentLogger) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Iterables(com.google.common.collect.Iterables) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) WalkSorter(com.google.gerrit.server.change.WalkSorter) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ChangePermission(com.google.gerrit.server.permissions.ChangePermission) Multimap(com.google.common.collect.Multimap) Response(com.google.gerrit.extensions.restapi.Response) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) MessageIdGenerator(com.google.gerrit.server.mail.send.MessageIdGenerator) ChangeResource(com.google.gerrit.server.change.ChangeResource) PostUpdateContext(com.google.gerrit.server.update.PostUpdateContext) Objects.requireNonNull(java.util.Objects.requireNonNull) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevertedSender(com.google.gerrit.server.mail.send.RevertedSender) Change(com.google.gerrit.entities.Change) ContributorAgreementsChecker(com.google.gerrit.server.project.ContributorAgreementsChecker) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ChangeUtil(com.google.gerrit.server.ChangeUtil) ChangeContext(com.google.gerrit.server.update.ChangeContext) PatchSetData(com.google.gerrit.server.change.WalkSorter.PatchSetData) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) CurrentUser(com.google.gerrit.server.CurrentUser) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) Sequences(com.google.gerrit.server.notedb.Sequences) Iterator(java.util.Iterator) StorageException(com.google.gerrit.exceptions.StorageException) ProjectState(com.google.gerrit.server.project.ProjectState) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) ObjectId(org.eclipse.jgit.lib.ObjectId) Provider(com.google.inject.Provider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RevisionResource(com.google.gerrit.server.change.RevisionResource) Project(com.google.gerrit.entities.Project) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) Result(com.google.gerrit.server.restapi.change.CherryPickChange.Result) Comparator(java.util.Comparator) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) PatchSetData(com.google.gerrit.server.change.WalkSorter.PatchSetData) ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) ChangeData(com.google.gerrit.server.query.change.ChangeData) Project(com.google.gerrit.entities.Project) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) BranchNameKey(com.google.gerrit.entities.BranchNameKey)

Aggregations

PatchSetData (com.google.gerrit.server.change.WalkSorter.PatchSetData)3 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 FluentLogger (com.google.common.flogger.FluentLogger)1 BranchNameKey (com.google.gerrit.entities.BranchNameKey)1 Change (com.google.gerrit.entities.Change)1 Project (com.google.gerrit.entities.Project)1 RefNames (com.google.gerrit.entities.RefNames)1 StorageException (com.google.gerrit.exceptions.StorageException)1 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)1 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)1 RevertInput (com.google.gerrit.extensions.api.changes.RevertInput)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 RevertSubmissionInfo (com.google.gerrit.extensions.common.RevertSubmissionInfo)1