Search in sources :

Example 1 with OpenRepo

use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo 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 2 with OpenRepo

use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo in project gerrit by GerritCodeReview.

the class SubmoduleCommits method amendGitlinksCommit.

/**
 * Amend an existing commit with gitlink updates
 */
CodeReviewCommit amendGitlinksCommit(BranchNameKey subscriber, CodeReviewCommit currentCommit, Collection<SubmoduleSubscription> subscriptions) throws IOException, SubmoduleConflictException {
    OpenRepo or;
    try {
        or = orm.getRepo(subscriber.project());
    } catch (NoSuchProjectException | IOException e) {
        throw new StorageException("Cannot access superproject", e);
    }
    StringBuilder msgbuf = new StringBuilder();
    DirCache dc = readTree(or.rw, currentCommit);
    DirCacheEditor ed = dc.editor();
    for (SubmoduleSubscription s : sortByPath(subscriptions)) {
        updateSubmodule(dc, ed, msgbuf, s);
    }
    ed.finish();
    ObjectId newTreeId = dc.writeTree(or.ins);
    // Gitlinks are already updated, just return the commit
    if (newTreeId.equals(currentCommit.getTree())) {
        return currentCommit;
    }
    or.rw.parseBody(currentCommit);
    CommitBuilder commit = new CommitBuilder();
    commit.setTreeId(newTreeId);
    commit.setParentIds(currentCommit.getParents());
    if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
        // TODO(czhen): handle cherrypick footer
        commit.setMessage(currentCommit.getFullMessage() + "\n\n* submodules:\n" + msgbuf.toString());
    } else {
        commit.setMessage(currentCommit.getFullMessage());
    }
    commit.setAuthor(currentCommit.getAuthorIdent());
    commit.setCommitter(myIdent);
    ObjectId id = or.ins.insert(commit);
    CodeReviewCommit newCommit = or.getCodeReviewRevWalk().parseCommit(id);
    newCommit.copyFrom(currentCommit);
    return newCommit;
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ObjectId(org.eclipse.jgit.lib.ObjectId) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) IOException(java.io.IOException) DirCacheEditor(org.eclipse.jgit.dircache.DirCacheEditor) StorageException(com.google.gerrit.exceptions.StorageException) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit)

Example 3 with OpenRepo

use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo 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 4 with OpenRepo

use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo 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 5 with OpenRepo

use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo in project gerrit by GerritCodeReview.

the class LocalMergeSuperSetComputation method getRepo.

private OpenRepo getRepo(MergeOpRepoManager orm, Project.NameKey project) throws IOException {
    try {
        OpenRepo or = orm.getRepo(project);
        checkState(or.rw.hasRevSort(RevSort.TOPO));
        return or;
    } catch (NoSuchProjectException e) {
        throw new IOException(e);
    }
}
Also used : NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) IOException(java.io.IOException)

Aggregations

OpenRepo (com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo)10 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)7 IOException (java.io.IOException)7 StorageException (com.google.gerrit.exceptions.StorageException)6 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)6 BranchNameKey (com.google.gerrit.entities.BranchNameKey)5 ObjectId (org.eclipse.jgit.lib.ObjectId)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 DirCache (org.eclipse.jgit.dircache.DirCache)3 DirCacheEditor (org.eclipse.jgit.dircache.DirCacheEditor)3 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)3 Project (com.google.gerrit.entities.Project)2 SubmoduleSubscription (com.google.gerrit.entities.SubmoduleSubscription)2 ArrayList (java.util.ArrayList)2 PathEdit (org.eclipse.jgit.dircache.DirCacheEditor.PathEdit)2 DirCacheEntry (org.eclipse.jgit.dircache.DirCacheEntry)2 Ref (org.eclipse.jgit.lib.Ref)2 Attempt (com.github.rholder.retry.Attempt)1 RetryListener (com.github.rholder.retry.RetryListener)1 AutoValue (com.google.auto.value.AutoValue)1