Search in sources :

Example 1 with ICommitOfManagedBranch

use of com.virtuslab.gitmachete.backend.api.ICommitOfManagedBranch in project git-machete-intellij-plugin by VirtusLab.

the class RepositoryGraphBuilder method buildCommitsAndNonRootBranch.

private void buildCommitsAndNonRootBranch(java.util.List<IGraphItem> graphItems, INonRootManagedBranchSnapshot branch, @NonNegative int parentBranchIndex, @NonNegative int indentLevel) {
    List<ICommitOfManagedBranch> commits = branchGetCommitsStrategy.getCommitsOf(branch).reverse();
    val syncToParentStatus = branch.getSyncToParentStatus();
    GraphItemColor graphItemColor = getGraphItemColor(syncToParentStatus);
    int branchItemIndex = graphItems.size() + commits.size();
    // We are building some non root branch here so some root branch item has been added already.
    assert branchItemIndex > 0 : "Branch node index is not greater than 0 but should be";
    boolean isFirstItemInBranch = true;
    for (ICommitOfManagedBranch commit : commits) {
        int lastItemIndex = graphItems.size() - 1;
        // We are building some non root branch here so some root branch item has been added already.
        assert lastItemIndex >= 0 : "Last node index is less than 0 but shouldn't be";
        int prevSiblingItemIndex = isFirstItemInBranch ? parentBranchIndex : lastItemIndex;
        int nextSiblingItemIndex = graphItems.size() + 1;
        val c = new CommitItem(commit, branch, graphItemColor, prevSiblingItemIndex, nextSiblingItemIndex, indentLevel);
        graphItems.add(c);
        isFirstItemInBranch = false;
    }
    int lastItemIndex = graphItems.size() - 1;
    /*
     * If a branch has no commits (possibly due to commits getting strategy being {@code EMPTY_GET_COMMITS}) its {@code
     * prevSiblingItemIndex} is just the {@code parentBranchIndex}. Otherwise the {@code prevSiblingItemIndex} is an index of
     * most recently added item (its last commit).
     */
    int prevSiblingItemIndex = commits.isEmpty() ? parentBranchIndex : lastItemIndex;
    BranchItem branchItem = createBranchItemFor(branch, prevSiblingItemIndex, graphItemColor, indentLevel);
    graphItems.add(branchItem);
}
Also used : lombok.val(lombok.val) ICommitOfManagedBranch(com.virtuslab.gitmachete.backend.api.ICommitOfManagedBranch) BranchItem(com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem) CommitItem(com.virtuslab.gitmachete.frontend.graph.impl.items.CommitItem) GraphItemColor(com.virtuslab.gitmachete.frontend.graph.api.items.GraphItemColor)

Aggregations

ICommitOfManagedBranch (com.virtuslab.gitmachete.backend.api.ICommitOfManagedBranch)1 GraphItemColor (com.virtuslab.gitmachete.frontend.graph.api.items.GraphItemColor)1 BranchItem (com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem)1 CommitItem (com.virtuslab.gitmachete.frontend.graph.impl.items.CommitItem)1 lombok.val (lombok.val)1