Search in sources :

Example 1 with BranchItem

use of com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem 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)

Example 2 with BranchItem

use of com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem in project git-machete-intellij-plugin by VirtusLab.

the class RepositoryGraphBuilder method addRootBranch.

private void addRootBranch(java.util.List<IGraphItem> graphItems, IRootManagedBranchSnapshot branch) {
    BranchItem branchItem = createBranchItemFor(branch, /* prevSiblingItemIndex */
    -1, GraphItemColor.GREEN, /* indentLevel */
    0);
    graphItems.add(branchItem);
}
Also used : BranchItem(com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem)

Example 3 with BranchItem

use of com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem in project git-machete-intellij-plugin by VirtusLab.

the class RepositoryGraphBuilder method createBranchItemFor.

/**
 * @return {@link BranchItem} for given properties and provide additional attributes if the branch is the current one
 */
private BranchItem createBranchItemFor(IManagedBranchSnapshot branch, @GTENegativeOne int prevSiblingItemIndex, GraphItemColor graphItemColor, @NonNegative int indentLevel) {
    RelationToRemote relationToRemote = branch.getRelationToRemote();
    Option<IManagedBranchSnapshot> currentBranch = repositorySnapshot.getCurrentBranchIfManaged();
    boolean isCurrentBranch = currentBranch.isDefined() && currentBranch.get().equals(branch);
    boolean hasChildItem = !branch.getChildren().isEmpty();
    return new BranchItem(branch, graphItemColor, relationToRemote, prevSiblingItemIndex, indentLevel, isCurrentBranch, hasChildItem);
}
Also used : BranchItem(com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem) IManagedBranchSnapshot(com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot) RelationToRemote(com.virtuslab.gitmachete.backend.api.RelationToRemote)

Aggregations

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