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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations