Search in sources :

Example 11 with CodeReviewCommit

use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.

the class SubmitStrategyListener method checkCommitStatus.

private List<Change.Id> checkCommitStatus() throws ResourceConflictException {
    List<Change.Id> alreadyMerged = new ArrayList<>(commitStatus.getChangeIds().size());
    for (Change.Id id : commitStatus.getChangeIds()) {
        CodeReviewCommit commit = commitStatus.get(id);
        CommitMergeStatus s = commit != null ? commit.getStatusCode() : null;
        if (s == null) {
            commitStatus.problem(id, "internal error: change not processed by merge strategy");
            continue;
        }
        switch(s) {
            case CLEAN_MERGE:
            case CLEAN_REBASE:
            case CLEAN_PICK:
            case SKIPPED_IDENTICAL_TREE:
                // Merge strategy accepted this change.
                break;
            case ALREADY_MERGED:
                // Already an ancestor of tip.
                alreadyMerged.add(commit.getPatchsetId().getParentKey());
                break;
            case PATH_CONFLICT:
            case REBASE_MERGE_CONFLICT:
            case MANUAL_RECURSIVE_MERGE:
            case CANNOT_CHERRY_PICK_ROOT:
            case CANNOT_REBASE_ROOT:
            case NOT_FAST_FORWARD:
                // TODO(dborowitz): Reformat these messages to be more appropriate for
                // short problem descriptions.
                commitStatus.problem(id, CharMatcher.is('\n').collapseFrom(s.getMessage(), ' '));
                break;
            case MISSING_DEPENDENCY:
                commitStatus.problem(id, "depends on change that was not submitted");
                break;
            default:
                commitStatus.problem(id, "unspecified merge failure: " + s);
                break;
        }
    }
    commitStatus.maybeFailVerbose();
    return alreadyMerged;
}
Also used : ArrayList(java.util.ArrayList) Change(com.google.gerrit.reviewdb.client.Change) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit)

Example 12 with CodeReviewCommit

use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.

the class CherryPick method buildOps.

@Override
public List<SubmitStrategyOp> buildOps(Collection<CodeReviewCommit> toMerge) throws IntegrationException {
    List<CodeReviewCommit> sorted = CodeReviewCommit.ORDER.sortedCopy(toMerge);
    List<SubmitStrategyOp> ops = new ArrayList<>(sorted.size());
    boolean first = true;
    while (!sorted.isEmpty()) {
        CodeReviewCommit n = sorted.remove(0);
        if (first && args.mergeTip.getInitialTip() == null) {
            ops.add(new FastForwardOp(args, n));
        } else if (n.getParentCount() == 0) {
            ops.add(new CherryPickRootOp(n));
        } else if (n.getParentCount() == 1) {
            ops.add(new CherryPickOneOp(n));
        } else {
            ops.add(new CherryPickMultipleParentsOp(n));
        }
        first = false;
    }
    return ops;
}
Also used : ArrayList(java.util.ArrayList) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit)

Example 13 with CodeReviewCommit

use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.

the class MergeOneOp method updateRepoImpl.

@Override
public void updateRepoImpl(RepoContext ctx) throws IntegrationException, IOException {
    PersonIdent caller = ctx.getIdentifiedUser().newCommitterIdent(ctx.getWhen(), ctx.getTimeZone());
    if (args.mergeTip.getCurrentTip() == null) {
        throw new IllegalStateException("cannot merge commit " + toMerge.name() + " onto a null tip; expected at least one fast-forward prior to" + " this operation");
    }
    CodeReviewCommit merged = args.mergeUtil.mergeOneCommit(caller, args.serverIdent, args.rw, ctx.getInserter(), ctx.getRepoView().getConfig(), args.destBranch, args.mergeTip.getCurrentTip(), toMerge);
    args.mergeTip.moveTipTo(amendGitlink(merged), toMerge);
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit)

Aggregations

CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)13 ArrayList (java.util.ArrayList)8 Change (com.google.gerrit.reviewdb.client.Change)4 IntegrationException (com.google.gerrit.server.git.IntegrationException)4 Branch (com.google.gerrit.reviewdb.client.Branch)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 CodeReviewRevWalk (com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk)2 ProjectState (com.google.gerrit.server.project.ProjectState)2 OrmException (com.google.gwtorm.server.OrmException)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Repository (org.eclipse.jgit.lib.Repository)2 Function (com.google.common.base.Function)1 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Iterables (com.google.common.collect.Iterables)1 SubmitRecord (com.google.gerrit.common.data.SubmitRecord)1 MergeConflictException (com.google.gerrit.extensions.restapi.MergeConflictException)1 Account (com.google.gerrit.reviewdb.client.Account)1