Search in sources :

Example 6 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class LinearBekGraphBuilder method getFragment.

@Nullable
private MergeFragment getFragment(int leftChild, int rightChild, int parent) {
    MergeFragment fragment = new MergeFragment(parent, leftChild, rightChild);
    int leftLi = myGraphLayout.getLayoutIndex(leftChild);
    int rightLi = myGraphLayout.getLayoutIndex(rightChild);
    int rowsCount = 1;
    int blockSize = 1;
    PriorityQueue<GraphEdge> queue = new PriorityQueue<>(MAX_BLOCK_SIZE, new GraphEdgeComparator());
    queue.addAll(myLinearBekGraph.getAdjacentEdges(rightChild, EdgeFilter.NORMAL_DOWN));
    @Nullable Set<Integer> magicSet = null;
    while (!queue.isEmpty()) {
        GraphEdge nextEdge = queue.poll();
        Integer next = nextEdge.getDownNodeIndex();
        Integer upNodeIndex = nextEdge.getUpNodeIndex();
        // can not happen
        assert upNodeIndex != null;
        if (next == null) {
            fragment.addTail(upNodeIndex);
            // allow very long edges down
            continue;
        }
        if (next == leftChild) {
            // found first child
            fragment.addTail(upNodeIndex);
            fragment.setMergeWithOldCommit(true);
        } else if (next == rightChild + rowsCount) {
            // all is fine, continuing
            rowsCount++;
            blockSize++;
            queue.addAll(myLinearBekGraph.getAdjacentEdges(next, EdgeFilter.NORMAL_DOWN));
            fragment.addBody(upNodeIndex);
        } else if (next > rightChild + rowsCount && next < leftChild) {
            rowsCount = next - rightChild + 1;
            blockSize++;
            queue.addAll(myLinearBekGraph.getAdjacentEdges(next, EdgeFilter.NORMAL_DOWN));
            fragment.addBody(upNodeIndex);
        } else if (next > leftChild) {
            int li = myGraphLayout.getLayoutIndex(next);
            if (leftLi > rightLi && !fragment.isMergeWithOldCommit()) {
                if (next > leftChild + MAGIC_SET_SIZE) {
                    return null;
                }
                if (magicSet == null) {
                    magicSet = calculateMagicSet(leftChild);
                }
                if (magicSet.contains(next)) {
                    fragment.addTailEdge(upNodeIndex, next);
                } else {
                    return null;
                }
            } else {
                if ((li > leftLi && li < rightLi) || (li == leftLi)) {
                    fragment.addTailEdge(upNodeIndex, next);
                } else {
                    if (li >= rightLi) {
                        return null;
                    } else {
                        if (next > leftChild + MAGIC_SET_SIZE) {
                            if (!fragment.hasTailEdge(upNodeIndex) && !fragment.isBody(upNodeIndex))
                                return null;
                        } else {
                            if (magicSet == null) {
                                magicSet = calculateMagicSet(leftChild);
                            }
                            if (magicSet.contains(next)) {
                                fragment.addTailEdge(upNodeIndex, next);
                            } else {
                                return null;
                            }
                        }
                    }
                }
            }
        }
        if (blockSize >= MAX_BLOCK_SIZE) {
            return null;
        }
    }
    if (fragment.getTails().isEmpty()) {
        // this can happen if we ran into initial import
        return null;
    }
    return fragment;
}
Also used : PriorityQueue(java.util.PriorityQueue) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class CollapsedActionManager method isForDelegateGraph.

private static boolean isForDelegateGraph(@NotNull ActionContext context) {
    GraphElement affectedGraphElement = context.getAffectedGraphElement();
    if (affectedGraphElement == null)
        return false;
    GraphEdge dottedEdge = getDottedEdge(context.getAffectedGraphElement(), context.getCompiledGraph());
    if (dottedEdge != null) {
        int upNodeIndex = context.convertToDelegateNodeIndex(assertInt(dottedEdge.getUpNodeIndex()));
        int downNodeIndex = context.convertToDelegateNodeIndex(assertInt(dottedEdge.getDownNodeIndex()));
        if (!context.myCollapsedGraph.isMyCollapsedEdge(upNodeIndex, downNodeIndex))
            return true;
    }
    return false;
}
Also used : GraphElement(com.intellij.vcs.log.graph.api.elements.GraphElement) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 8 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class PrintElementManagerImpl method isSelected.

@Override
public boolean isSelected(@NotNull PrintElementWithGraphElement printElement) {
    if (printElement.equals(mySelectedPrintElement))
        return true;
    GraphElement graphElement = printElement.getGraphElement();
    if (graphElement instanceof GraphNode) {
        int nodeId = myLinearGraph.getNodeId(((GraphNode) graphElement).getNodeIndex());
        return mySelectedNodeIds.contains(nodeId);
    }
    if (graphElement instanceof GraphEdge) {
        GraphEdge edge = (GraphEdge) graphElement;
        boolean selected = edge.getTargetId() == null || mySelectedNodeIds.contains(edge.getTargetId());
        selected &= edge.getUpNodeIndex() == null || mySelectedNodeIds.contains(myLinearGraph.getNodeId(edge.getUpNodeIndex()));
        selected &= edge.getDownNodeIndex() == null || mySelectedNodeIds.contains(myLinearGraph.getNodeId(edge.getDownNodeIndex()));
        return selected;
    }
    return false;
}
Also used : GraphElement(com.intellij.vcs.log.graph.api.elements.GraphElement) PrintElementWithGraphElement(com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 9 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class CollapsedController method convertToDelegate.

@Nullable
public static GraphElement convertToDelegate(@NotNull GraphElement graphElement, CollapsedGraph collapsedGraph) {
    if (graphElement instanceof GraphEdge) {
        Integer upIndex = ((GraphEdge) graphElement).getUpNodeIndex();
        Integer downIndex = ((GraphEdge) graphElement).getDownNodeIndex();
        if (upIndex != null && downIndex != null && collapsedGraph.isMyCollapsedEdge(upIndex, downIndex))
            return null;
        Integer convertedUpIndex = upIndex == null ? null : collapsedGraph.convertToDelegateNodeIndex(upIndex);
        Integer convertedDownIndex = downIndex == null ? null : collapsedGraph.convertToDelegateNodeIndex(downIndex);
        return new GraphEdge(convertedUpIndex, convertedDownIndex, ((GraphEdge) graphElement).getTargetId(), ((GraphEdge) graphElement).getType());
    } else if (graphElement instanceof GraphNode) {
        return new GraphNode(collapsedGraph.convertToDelegateNodeIndex((((GraphNode) graphElement).getNodeIndex())), ((GraphNode) graphElement).getType());
    }
    return null;
}
Also used : GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class BekBaseController method convertToDelegate.

@Nullable
@Override
protected GraphElement convertToDelegate(@NotNull GraphElement graphElement) {
    if (graphElement instanceof GraphEdge) {
        Integer upIndex = ((GraphEdge) graphElement).getUpNodeIndex();
        Integer downIndex = ((GraphEdge) graphElement).getDownNodeIndex();
        Integer convertedUpIndex = upIndex == null ? null : myBekIntMap.getUsualIndex(upIndex);
        Integer convertedDownIndex = downIndex == null ? null : myBekIntMap.getUsualIndex(downIndex);
        return new GraphEdge(convertedUpIndex, convertedDownIndex, ((GraphEdge) graphElement).getTargetId(), ((GraphEdge) graphElement).getType());
    } else if (graphElement instanceof GraphNode) {
        return new GraphNode(myBekIntMap.getUsualIndex((((GraphNode) graphElement).getNodeIndex())), ((GraphNode) graphElement).getType());
    }
    return null;
}
Also used : GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GraphEdge (com.intellij.vcs.log.graph.api.elements.GraphEdge)15 GraphNode (com.intellij.vcs.log.graph.api.elements.GraphNode)9 GraphElement (com.intellij.vcs.log.graph.api.elements.GraphElement)5 NormalEdge (com.intellij.vcs.log.graph.utils.NormalEdge)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 PrintElementWithGraphElement (com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement)2 ArrayList (java.util.ArrayList)2 Pair (com.intellij.openapi.util.Pair)1 SmartList (com.intellij.util.SmartList)1 GraphEdgeType (com.intellij.vcs.log.graph.api.elements.GraphEdgeType)1 TerminalEdgePrintElement (com.intellij.vcs.log.graph.impl.print.elements.TerminalEdgePrintElement)1 EdgeNodeCharConverter.parseGraphEdgeType (com.intellij.vcs.log.graph.parser.EdgeNodeCharConverter.parseGraphEdgeType)1 LinearGraphUtils.asNormalEdge (com.intellij.vcs.log.graph.utils.LinearGraphUtils.asNormalEdge)1 List (java.util.List)1 PriorityQueue (java.util.PriorityQueue)1