Search in sources :

Example 1 with SubmitStrategy

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

the class MergeOp method getSubmitStrategies.

private List<SubmitStrategy> getSubmitStrategies(Map<Branch.NameKey, BranchBatch> toSubmit, SubmoduleOp submoduleOp, boolean dryrun) throws IntegrationException, NoSuchProjectException, IOException {
    List<SubmitStrategy> strategies = new ArrayList<>();
    Set<Branch.NameKey> allBranches = submoduleOp.getBranchesInOrder();
    Set<CodeReviewCommit> allCommits = toSubmit.values().stream().map(BranchBatch::commits).flatMap(Set::stream).collect(toSet());
    for (Branch.NameKey branch : allBranches) {
        OpenRepo or = orm.getRepo(branch.getParentKey());
        if (toSubmit.containsKey(branch)) {
            BranchBatch submitting = toSubmit.get(branch);
            OpenBranch ob = or.getBranch(branch);
            checkNotNull(submitting.submitType(), "null submit type for %s; expected to previously fail fast", submitting);
            Set<CodeReviewCommit> commitsToSubmit = submitting.commits();
            ob.mergeTip = new MergeTip(ob.oldTip, commitsToSubmit);
            SubmitStrategy strategy = submitStrategyFactory.create(submitting.submitType(), db, or.rw, or.canMergeFlag, getAlreadyAccepted(or, ob.oldTip), allCommits, branch, caller, ob.mergeTip, commitStatus, submissionId, submitInput.notify, accountsToNotify, submoduleOp, dryrun);
            strategies.add(strategy);
            strategy.addOps(or.getUpdate(batchUpdateFactory), commitsToSubmit);
            if (submitting.submitType().equals(SubmitType.FAST_FORWARD_ONLY) && submoduleOp.hasSubscription(branch)) {
                submoduleOp.addOp(or.getUpdate(batchUpdateFactory), branch);
            }
        } else {
            // no open change for this branch
            // add submodule triggered op into BatchUpdate
            submoduleOp.addOp(or.getUpdate(batchUpdateFactory), branch);
        }
    }
    return strategies;
}
Also used : ArrayList(java.util.ArrayList) Branch(com.google.gerrit.reviewdb.client.Branch) OpenBranch(com.google.gerrit.server.git.MergeOpRepoManager.OpenBranch) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) SubmitStrategy(com.google.gerrit.server.git.strategy.SubmitStrategy) OpenBranch(com.google.gerrit.server.git.MergeOpRepoManager.OpenBranch)

Example 2 with SubmitStrategy

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

the class MergeOp method integrateIntoHistory.

private void integrateIntoHistory(ChangeSet cs) throws IntegrationException, RestApiException {
    checkArgument(!cs.furtherHiddenChanges(), "cannot integrate hidden changes into history");
    logDebug("Beginning merge attempt on {}", cs);
    Map<Branch.NameKey, BranchBatch> toSubmit = new HashMap<>();
    ListMultimap<Branch.NameKey, ChangeData> cbb;
    try {
        cbb = cs.changesByBranch();
    } catch (OrmException e) {
        throw new IntegrationException("Error reading changes to submit", e);
    }
    Set<Branch.NameKey> branches = cbb.keySet();
    for (Branch.NameKey branch : branches) {
        OpenRepo or = openRepo(branch.getParentKey());
        if (or != null) {
            toSubmit.put(branch, validateChangeList(or, cbb.get(branch)));
        }
    }
    // Done checks that don't involve running submit strategies.
    commitStatus.maybeFailVerbose();
    try {
        SubmoduleOp submoduleOp = subOpFactory.create(branches, orm);
        List<SubmitStrategy> strategies = getSubmitStrategies(toSubmit, submoduleOp, dryrun);
        this.allProjects = submoduleOp.getProjectsInOrder();
        batchUpdateFactory.execute(orm.batchUpdates(batchUpdateFactory, allProjects), new SubmitStrategyListener(submitInput, strategies, commitStatus), submissionId, dryrun);
    } catch (NoSuchProjectException e) {
        throw new ResourceNotFoundException(e.getMessage());
    } catch (IOException | SubmoduleException e) {
        throw new IntegrationException(e);
    } catch (UpdateException e) {
        // BatchUpdate may have inadvertently wrapped an IntegrationException
        // thrown by some legacy SubmitStrategyOp code that intended the error
        // message to be user-visible. Copy the message from the wrapped
        // exception.
        //
        // If you happen across one of these, the correct fix is to convert the
        // inner IntegrationException to a ResourceConflictException.
        String msg;
        if (e.getCause() instanceof IntegrationException) {
            msg = e.getCause().getMessage();
        } else {
            msg = "Error submitting change" + (cs.size() != 1 ? "s" : "");
        }
        throw new IntegrationException(msg, e);
    }
}
Also used : HashMap(java.util.HashMap) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) IOException(java.io.IOException) ChangeData(com.google.gerrit.server.query.change.ChangeData) OrmException(com.google.gwtorm.server.OrmException) Branch(com.google.gerrit.reviewdb.client.Branch) OpenBranch(com.google.gerrit.server.git.MergeOpRepoManager.OpenBranch) SubmitStrategyListener(com.google.gerrit.server.git.strategy.SubmitStrategyListener) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) UpdateException(com.google.gerrit.server.update.UpdateException) SubmitStrategy(com.google.gerrit.server.git.strategy.SubmitStrategy) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

Branch (com.google.gerrit.reviewdb.client.Branch)2 OpenBranch (com.google.gerrit.server.git.MergeOpRepoManager.OpenBranch)2 OpenRepo (com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo)2 SubmitStrategy (com.google.gerrit.server.git.strategy.SubmitStrategy)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 SubmitStrategyListener (com.google.gerrit.server.git.strategy.SubmitStrategyListener)1 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1 UpdateException (com.google.gerrit.server.update.UpdateException)1 OrmException (com.google.gwtorm.server.OrmException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1