Search in sources :

Example 16 with BranchNameKey

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

the class MergeOp method getSubmitStrategies.

private List<SubmitStrategy> getSubmitStrategies(Map<BranchNameKey, BranchBatch> toSubmit, UpdateOrderCalculator updateOrderCalculator, SubmoduleCommits submoduleCommits, SubscriptionGraph subscriptionGraph, boolean dryrun) throws IntegrationConflictException, NoSuchProjectException, IOException {
    List<SubmitStrategy> strategies = new ArrayList<>();
    Set<BranchNameKey> allBranches = updateOrderCalculator.getBranchesInOrder();
    Set<CodeReviewCommit> allCommits = toSubmit.values().stream().map(BranchBatch::commits).flatMap(Set::stream).collect(toSet());
    for (BranchNameKey branch : allBranches) {
        OpenRepo or = orm.getRepo(branch.project());
        if (toSubmit.containsKey(branch)) {
            BranchBatch submitting = toSubmit.get(branch);
            logger.atFine().log("adding ops for branch batch %s", submitting);
            OpenBranch ob = or.getBranch(branch);
            requireNonNull(submitting.submitType(), String.format("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(), or.rw, or.canMergeFlag, getAlreadyAccepted(or, ob.oldTip), allCommits, branch, caller, ob.mergeTip, commitStatus, submissionId, submitInput, submoduleCommits, subscriptionGraph, dryrun);
            strategies.add(strategy);
            strategy.addOps(or.getUpdate(), commitsToSubmit);
        }
    }
    return strategies;
}
Also used : MergeTip(com.google.gerrit.server.git.MergeTip) BranchNameKey(com.google.gerrit.entities.BranchNameKey) ArrayList(java.util.ArrayList) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) OpenBranch(com.google.gerrit.server.submit.MergeOpRepoManager.OpenBranch)

Example 17 with BranchNameKey

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

the class SubmoduleOp method updateSuperProjects.

public void updateSuperProjects(boolean dryrun) throws RestApiException {
    ImmutableSet<Project.NameKey> projects = updateOrderCalculator.getProjectsInOrder();
    if (projects == null) {
        return;
    }
    if (dryrun) {
        // On dryrun, the refs hasn't been updated.
        // force the new tips on submoduleCommits
        forceRefTips(updatedBranches, submoduleCommits);
    }
    LinkedHashSet<Project.NameKey> superProjects = new LinkedHashSet<>();
    try {
        GitlinkOp.Factory gitlinkOpFactory = new GitlinkOp.Factory(submoduleCommits, subscriptionGraph);
        for (Project.NameKey project : projects) {
            // only need superprojects
            if (subscriptionGraph.isAffectedSuperProject(project)) {
                superProjects.add(project);
                // get a new BatchUpdate for the super project
                OpenRepo or = orm.getRepo(project);
                for (BranchNameKey branch : subscriptionGraph.getAffectedSuperBranches(project)) {
                    or.getUpdate().addRepoOnlyOp(gitlinkOpFactory.create(branch));
                }
            }
        }
        BatchUpdate.execute(orm.batchUpdates(superProjects), ImmutableList.of(), dryrun);
    } catch (UpdateException | IOException | NoSuchProjectException e) {
        throw new StorageException("Cannot update gitlinks", e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) IOException(java.io.IOException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) UpdateException(com.google.gerrit.server.update.UpdateException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 18 with BranchNameKey

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

the class SubmoduleOp method forceRefTips.

private void forceRefTips(Map<BranchNameKey, ReceiveCommand> updatedBranches, SubmoduleCommits submoduleCommits) {
    // This is dryrun, all commands succeeded (no need to filter success).
    for (Map.Entry<BranchNameKey, ReceiveCommand> updateBranch : updatedBranches.entrySet()) {
        try {
            ReceiveCommand command = updateBranch.getValue();
            if (command.getType() == ReceiveCommand.Type.DELETE) {
                continue;
            }
            BranchNameKey branchNameKey = updateBranch.getKey();
            OpenRepo openRepo = orm.getRepo(branchNameKey.project());
            CodeReviewCommit fakeTip = openRepo.rw.parseCommit(command.getNewId());
            submoduleCommits.addBranchTip(branchNameKey, fakeTip);
        } catch (NoSuchProjectException | IOException e) {
            throw new StorageException("Cannot find branch tip target in dryrun", e);
        }
    }
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) BranchNameKey(com.google.gerrit.entities.BranchNameKey) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) IOException(java.io.IOException) Map(java.util.Map) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) StorageException(com.google.gerrit.exceptions.StorageException)

Example 19 with BranchNameKey

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

the class FastForwardOnly method buildOps.

@Override
public ImmutableList<SubmitStrategyOp> buildOps(Collection<CodeReviewCommit> toMerge) {
    List<CodeReviewCommit> sorted = args.mergeUtil.reduceToMinimalMerge(args.mergeSorter, toMerge);
    Map<BranchNameKey, CodeReviewCommit> branchToCommit = new HashMap<>();
    for (CodeReviewCommit codeReviewCommit : sorted) {
        BranchNameKey branchNameKey = codeReviewCommit.change().getDest();
        CodeReviewCommit otherCommitInBranch = branchToCommit.get(branchNameKey);
        if (otherCommitInBranch == null) {
            branchToCommit.put(branchNameKey, codeReviewCommit);
        } else {
            // we found another change with the same destination branch.
            codeReviewCommit.setStatusCode(CommitMergeStatus.FAST_FORWARD_INDEPENDENT_CHANGES);
            otherCommitInBranch.setStatusCode(CommitMergeStatus.FAST_FORWARD_INDEPENDENT_CHANGES);
            return ImmutableList.of();
        }
    }
    ImmutableList.Builder<SubmitStrategyOp> ops = ImmutableList.builderWithExpectedSize(sorted.size());
    CodeReviewCommit newTipCommit = args.mergeUtil.getFirstFastForward(args.mergeTip.getInitialTip(), args.rw, sorted);
    if (!newTipCommit.equals(args.mergeTip.getInitialTip())) {
        ops.add(new FastForwardOp(args, newTipCommit));
    } else {
        for (CodeReviewCommit c : toMerge) {
            ops.add(new NotFastForwardOp(c));
        }
    }
    return ops.build();
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit)

Example 20 with BranchNameKey

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

the class LocalMergeSuperSetComputation method completeWithoutTopic.

@Override
public ChangeSet completeWithoutTopic(MergeOpRepoManager orm, ChangeSet changeSet, CurrentUser user) throws IOException {
    Collection<ChangeData> visibleChanges = new ArrayList<>();
    Collection<ChangeData> nonVisibleChanges = new ArrayList<>();
    // For each target branch we run a separate rev walk to find open changes
    // reachable from changes already in the merge super set.
    ImmutableSet<BranchNameKey> branches = byBranch(Iterables.concat(changeSet.changes(), changeSet.nonVisibleChanges())).keySet();
    ImmutableListMultimap<BranchNameKey, ChangeData> visibleChangesPerBranch = byBranch(changeSet.changes());
    ImmutableListMultimap<BranchNameKey, ChangeData> nonVisibleChangesPerBranch = byBranch(changeSet.nonVisibleChanges());
    for (BranchNameKey branchNameKey : branches) {
        OpenRepo or = getRepo(orm, branchNameKey.project());
        List<RevCommit> visibleCommits = new ArrayList<>();
        List<RevCommit> nonVisibleCommits = new ArrayList<>();
        for (ChangeData cd : visibleChangesPerBranch.get(branchNameKey)) {
            if (submitType(cd) == SubmitType.CHERRY_PICK) {
                visibleChanges.add(cd);
            } else {
                visibleCommits.add(or.rw.parseCommit(cd.currentPatchSet().commitId()));
            }
        }
        for (ChangeData cd : nonVisibleChangesPerBranch.get(branchNameKey)) {
            if (submitType(cd) == SubmitType.CHERRY_PICK) {
                nonVisibleChanges.add(cd);
            } else {
                nonVisibleCommits.add(or.rw.parseCommit(cd.currentPatchSet().commitId()));
            }
        }
        Set<String> visibleHashes = walkChangesByHashes(visibleCommits, Collections.emptySet(), or, branchNameKey);
        Set<String> nonVisibleHashes = walkChangesByHashes(nonVisibleCommits, visibleHashes, or, branchNameKey);
        ChangeSet partialSet = byCommitsOnBranchNotMerged(or, branchNameKey, visibleHashes, nonVisibleHashes, user);
        Iterables.addAll(visibleChanges, partialSet.changes());
        Iterables.addAll(nonVisibleChanges, partialSet.nonVisibleChanges());
    }
    return new ChangeSet(visibleChanges, nonVisibleChanges);
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) ArrayList(java.util.ArrayList) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

BranchNameKey (com.google.gerrit.entities.BranchNameKey)75 Test (org.junit.Test)48 Project (com.google.gerrit.entities.Project)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)25 Config (org.eclipse.jgit.lib.Config)19 SubmoduleSubscription (com.google.gerrit.entities.SubmoduleSubscription)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 AuthException (com.google.gerrit.extensions.restapi.AuthException)13 Change (com.google.gerrit.entities.Change)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 StorageException (com.google.gerrit.exceptions.StorageException)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Repository (org.eclipse.jgit.lib.Repository)9 PatchSet (com.google.gerrit.entities.PatchSet)8 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)8 HashMap (java.util.HashMap)7 Ref (org.eclipse.jgit.lib.Ref)7