Search in sources :

Example 46 with StorageException

use of com.google.gerrit.exceptions.StorageException 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 47 with StorageException

use of com.google.gerrit.exceptions.StorageException 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 48 with StorageException

use of com.google.gerrit.exceptions.StorageException 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 49 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class MergeUtil method canCherryPick.

public boolean canCherryPick(MergeSorter mergeSorter, Repository repo, CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge) {
    if (mergeTip == null) {
        // 
        return true;
    }
    if (toMerge.getParentCount() == 0) {
        // 
        return false;
    }
    if (toMerge.getParentCount() == 1) {
        // 
        try (ObjectInserter ins = new InMemoryInserter(repo)) {
            ThreeWayMerger m = newThreeWayMerger(ins, repo.getConfig());
            m.setBase(toMerge.getParent(0));
            return m.merge(mergeTip, toMerge);
        } catch (IOException e) {
            throw new StorageException(String.format("Cannot merge commit %s with mergetip %s", toMerge.name(), mergeTip.name()), e);
        }
    }
    // 
    return canFastForward(mergeSorter, mergeTip, rw, toMerge) || canMerge(mergeSorter, repo, mergeTip, toMerge);
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ThreeWayMerger(org.eclipse.jgit.merge.ThreeWayMerger) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 50 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class MergeUtil method markCleanMerges.

public void markCleanMerges(RevWalk rw, RevFlag canMergeFlag, CodeReviewCommit mergeTip, Set<RevCommit> alreadyAccepted) {
    if (mergeTip == null) {
        // 
        return;
    }
    try {
        rw.resetRetain(canMergeFlag);
        rw.sort(RevSort.TOPO);
        rw.sort(RevSort.REVERSE, true);
        rw.markStart(mergeTip);
        for (RevCommit c : alreadyAccepted) {
            // If branch was not created by this submit.
            if (!Objects.equals(c, mergeTip)) {
                rw.markUninteresting(c);
            }
        }
        CodeReviewCommit c;
        while ((c = (CodeReviewCommit) rw.next()) != null) {
            if (c.getPatchsetId() != null && c.getStatusCode() == null) {
                c.setStatusCode(CommitMergeStatus.CLEAN_MERGE);
            }
        }
    } catch (IOException e) {
        throw new StorageException("Cannot mark clean merges", e);
    }
}
Also used : IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

StorageException (com.google.gerrit.exceptions.StorageException)153 IOException (java.io.IOException)68 Change (com.google.gerrit.entities.Change)47 ObjectId (org.eclipse.jgit.lib.ObjectId)37 Repository (org.eclipse.jgit.lib.Repository)33 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)30 PatchSet (com.google.gerrit.entities.PatchSet)29 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 ArrayList (java.util.ArrayList)25 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)24 Project (com.google.gerrit.entities.Project)22 Ref (org.eclipse.jgit.lib.Ref)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)21 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 Account (com.google.gerrit.entities.Account)20 Inject (com.google.inject.Inject)19 Map (java.util.Map)19 Test (org.junit.Test)19 List (java.util.List)18 BranchNameKey (com.google.gerrit.entities.BranchNameKey)17