Search in sources :

Example 1 with RevCommitList

use of org.eclipse.jgit.revwalk.RevCommitList in project gerrit by GerritCodeReview.

the class MergeSorter method sort.

Collection<CodeReviewCommit> sort(final Collection<CodeReviewCommit> toMerge) throws IOException {
    final Set<CodeReviewCommit> heads = new HashSet<>();
    final Set<CodeReviewCommit> sort = new HashSet<>(toMerge);
    while (!sort.isEmpty()) {
        final CodeReviewCommit n = removeOne(sort);
        rw.resetRetain(canMergeFlag);
        rw.markStart(n);
        for (RevCommit c : accepted) {
            rw.markUninteresting(c);
        }
        CodeReviewCommit c;
        RevCommitList<RevCommit> contents = new RevCommitList<>();
        while ((c = rw.next()) != null) {
            if (!c.has(canMergeFlag) || !incoming.contains(c)) {
                // We cannot merge n as it would bring something we
                // aren't permitted to merge at this time. Drop n.
                //
                n.setStatusCode(CommitMergeStatus.MISSING_DEPENDENCY);
                break;
            }
            contents.add(c);
        }
        if (n.getStatusCode() == CommitMergeStatus.MISSING_DEPENDENCY) {
            continue;
        }
        // Anything reachable through us is better merged by just
        // merging us directly. So prune our ancestors out and let
        // us merge instead.
        //
        sort.removeAll(contents);
        heads.removeAll(contents);
        heads.add(n);
    }
    return heads;
}
Also used : RevCommitList(org.eclipse.jgit.revwalk.RevCommitList) HashSet(java.util.HashSet) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with RevCommitList

use of org.eclipse.jgit.revwalk.RevCommitList in project gerrit by GerritCodeReview.

the class MergeSorter method sort.

public Collection<CodeReviewCommit> sort(Collection<CodeReviewCommit> toMerge) throws IOException {
    final Set<CodeReviewCommit> heads = new HashSet<>();
    final Set<CodeReviewCommit> sort = new HashSet<>(toMerge);
    while (!sort.isEmpty()) {
        final CodeReviewCommit n = removeOne(sort);
        rw.resetRetain(canMergeFlag);
        rw.markStart(n);
        for (RevCommit c : accepted) {
            rw.markUninteresting(c);
        }
        CodeReviewCommit c;
        RevCommitList<RevCommit> contents = new RevCommitList<>();
        while ((c = rw.next()) != null) {
            if (!c.has(canMergeFlag) || !incoming.contains(c)) {
                // We cannot merge n as it would bring something we
                // aren't permitted to merge at this time. Drop n.
                // 
                n.setStatusCode(CommitMergeStatus.MISSING_DEPENDENCY);
                n.setStatusMessage(CommitMergeStatus.createMissingDependencyMessage(caller, queryProvider, n.name(), c.name()));
                break;
            }
            contents.add(c);
        }
        if (n.getStatusCode() == CommitMergeStatus.MISSING_DEPENDENCY) {
            continue;
        }
        // Anything reachable through us is better merged by just
        // merging us directly. So prune our ancestors out and let
        // us merge instead.
        // 
        sort.removeAll(contents);
        heads.removeAll(contents);
        heads.add(n);
    }
    return heads;
}
Also used : RevCommitList(org.eclipse.jgit.revwalk.RevCommitList) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) HashSet(java.util.HashSet) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

HashSet (java.util.HashSet)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 RevCommitList (org.eclipse.jgit.revwalk.RevCommitList)2 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)1