Search in sources :

Example 31 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class ChangeNotesParser method buildPatchSets.

private Map<PatchSet.Id, PatchSet> buildPatchSets() throws ConfigInvalidException {
    Map<PatchSet.Id, PatchSet> result = Maps.newHashMapWithExpectedSize(patchSets.size());
    for (Map.Entry<PatchSet.Id, PatchSet.Builder> e : patchSets.entrySet()) {
        try {
            PatchSet ps = e.getValue().build();
            result.put(ps.id(), ps);
        } catch (Exception ex) {
            ConfigInvalidException cie = parseException("Error building patch set %s", e.getKey());
            cie.initCause(ex);
            throw cie;
        }
    }
    return result;
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) MultimapBuilder(com.google.common.collect.MultimapBuilder) PatchSet(com.google.gerrit.entities.PatchSet) LabelId(com.google.gerrit.entities.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId) Map(java.util.Map) NoteMap(org.eclipse.jgit.notes.NoteMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InvalidObjectIdException(org.eclipse.jgit.errors.InvalidObjectIdException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException)

Example 32 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class ReviewCommand method run.

@Override
protected void run() throws UnloggedFailure {
    enableGracefulStop();
    if (abandonChange) {
        if (restoreChange) {
            throw die("abandon and restore actions are mutually exclusive");
        }
        if (submitChange) {
            throw die("abandon and submit actions are mutually exclusive");
        }
        if (rebaseChange) {
            throw die("abandon and rebase actions are mutually exclusive");
        }
        if (moveToBranch != null) {
            throw die("abandon and move actions are mutually exclusive");
        }
    }
    if (json) {
        if (restoreChange) {
            throw die("json and restore actions are mutually exclusive");
        }
        if (submitChange) {
            throw die("json and submit actions are mutually exclusive");
        }
        if (abandonChange) {
            throw die("json and abandon actions are mutually exclusive");
        }
        if (changeComment != null) {
            throw die("json and message are mutually exclusive");
        }
        if (rebaseChange) {
            throw die("json and rebase actions are mutually exclusive");
        }
        if (moveToBranch != null) {
            throw die("json and move actions are mutually exclusive");
        }
        if (changeTag != null) {
            throw die("json and tag actions are mutually exclusive");
        }
    }
    if (rebaseChange) {
        if (submitChange) {
            throw die("rebase and submit actions are mutually exclusive");
        }
    }
    boolean ok = true;
    ReviewInput input = null;
    if (json) {
        input = reviewFromJson();
    }
    for (PatchSet patchSet : patchSets) {
        try {
            if (input != null) {
                applyReview(patchSet, input);
            } else {
                reviewPatchSet(patchSet);
            }
        } catch (RestApiException | UnloggedFailure e) {
            ok = false;
            writeError("error", e.getMessage() + "\n");
        } catch (NoSuchChangeException e) {
            ok = false;
            writeError("error", "no such change " + patchSet.id().changeId().get());
        } catch (Exception e) {
            ok = false;
            writeError("fatal", "internal server error while reviewing " + patchSet.id() + "\n");
            logger.atSevere().withCause(e).log("internal error while reviewing %s", patchSet.id());
        }
    }
    if (!ok) {
        throw die("one or more reviews failed; review output above");
    }
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) PatchSet(com.google.gerrit.entities.PatchSet) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) CmdLineException(org.kohsuke.args4j.CmdLineException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) JsonSyntaxException(com.google.gson.JsonSyntaxException) StorageException(com.google.gerrit.exceptions.StorageException) IOException(java.io.IOException)

Example 33 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PatchsetOperationsImplTest method commentCanBeCreatedOnOlderPatchset.

@Test
public void commentCanBeCreatedOnOlderPatchset() throws Exception {
    Change.Id changeId = changeOperations.newChange().create();
    PatchSet.Id previousPatchsetId = changeOperations.change(changeId).currentPatchset().get().patchsetId();
    changeOperations.change(changeId).newPatchset().create();
    String commentUuid = changeOperations.change(changeId).patchset(previousPatchsetId).newComment().create();
    CommentInfo comment = getCommentFromServer(changeId, commentUuid);
    assertThat(comment).patchSet().isEqualTo(previousPatchsetId.get());
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 34 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class RebaseUtil method findBaseRevision.

/**
 * Find the commit onto which a patch set should be rebased.
 *
 * <p>This is defined as the latest patch set of the change corresponding to this commit's parent,
 * or the destination branch tip in the case where the parent's change is merged.
 *
 * @param patchSet patch set for which the new base commit should be found.
 * @param destBranch the destination branch.
 * @param git the repository.
 * @param rw the RevWalk.
 * @return the commit onto which the patch set should be rebased.
 * @throws RestApiException if rebase is not possible.
 * @throws IOException if accessing the repository fails.
 */
public ObjectId findBaseRevision(PatchSet patchSet, BranchNameKey destBranch, Repository git, RevWalk rw) throws RestApiException, IOException {
    ObjectId baseId = null;
    RevCommit commit = rw.parseCommit(patchSet.commitId());
    if (commit.getParentCount() > 1) {
        throw new UnprocessableEntityException("Cannot rebase a change with multiple parents.");
    } else if (commit.getParentCount() == 0) {
        throw new UnprocessableEntityException("Cannot rebase a change without any parents (is this the initial commit?).");
    }
    ObjectId parentId = commit.getParent(0);
    CHANGES: for (ChangeData cd : queryProvider.get().byBranchCommit(destBranch, parentId.name())) {
        for (PatchSet depPatchSet : cd.patchSets()) {
            if (!depPatchSet.commitId().equals(parentId)) {
                continue;
            }
            Change depChange = cd.change();
            if (depChange.isAbandoned()) {
                throw new ResourceConflictException("Cannot rebase a change with an abandoned parent: " + depChange.getKey());
            }
            if (depChange.isNew()) {
                if (depPatchSet.id().equals(depChange.currentPatchSetId())) {
                    throw new ResourceConflictException("Change is already based on the latest patch set of the dependent change.");
                }
                baseId = cd.currentPatchSet().commitId();
            }
            break CHANGES;
        }
    }
    if (baseId == null) {
        // We are dependent on a merged PatchSet or have no PatchSet
        // dependencies at all.
        Ref destRef = git.getRefDatabase().exactRef(destBranch.branch());
        if (destRef == null) {
            throw new UnprocessableEntityException("The destination branch does not exist: " + destBranch.branch());
        }
        baseId = destRef.getObjectId();
        if (baseId.equals(parentId)) {
            throw new ResourceConflictException("Change is already up to date.");
        }
    }
    return baseId;
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 35 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PureRevert method get.

public boolean get(ChangeNotes notes, Optional<String> claimedOriginal) throws IOException, BadRequestException, ResourceConflictException {
    PatchSet currentPatchSet = notes.getCurrentPatchSet();
    if (currentPatchSet == null) {
        throw new ResourceConflictException("current revision is missing");
    }
    if (!claimedOriginal.isPresent()) {
        return pureRevertCache.isPureRevert(notes);
    }
    ObjectId claimedOriginalObjectId;
    try {
        claimedOriginalObjectId = ObjectId.fromString(claimedOriginal.get());
    } catch (InvalidObjectIdException e) {
        throw new BadRequestException("invalid object ID", e);
    }
    return pureRevertCache.isPureRevert(notes.getProjectName(), notes.getCurrentPatchSet().commitId(), claimedOriginalObjectId);
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ObjectId(org.eclipse.jgit.lib.ObjectId) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PatchSet(com.google.gerrit.entities.PatchSet) InvalidObjectIdException(org.eclipse.jgit.errors.InvalidObjectIdException)

Aggregations

PatchSet (com.google.gerrit.entities.PatchSet)123 Change (com.google.gerrit.entities.Change)61 Test (org.junit.Test)48 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)41 ObjectId (org.eclipse.jgit.lib.ObjectId)35 RevCommit (org.eclipse.jgit.revwalk.RevCommit)29 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Project (com.google.gerrit.entities.Project)25 StorageException (com.google.gerrit.exceptions.StorageException)25 Repository (org.eclipse.jgit.lib.Repository)22 IOException (java.io.IOException)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 ChangeData (com.google.gerrit.server.query.change.ChangeData)18 HumanComment (com.google.gerrit.entities.HumanComment)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 Inject (com.google.inject.Inject)14 Map (java.util.Map)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11