From c1a0302b1b8f982fe3b3f58a3d48edefe421e006 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Fri, 2 Jun 2017 21:44:05 +0300 Subject: [PATCH] [file-history] avoid calling bfs when previous file name is the same in all parents --- .../vcs/log/history/FileHistoryFilterer.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryFilterer.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryFilterer.java index 7f0511a64b9f..038323f78617 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryFilterer.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryFilterer.java @@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Function; import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; @@ -228,13 +229,24 @@ class FileHistoryFilterer extends VcsLogFilterer { int previousCommit = myPermanentCommitsInfo.getCommitId(previousNodeId); if (down) { - int parentIndex = BfsUtil.getCorrespondingParent(myPermanentLinearGraph, previousNodeId, currentNodeId, myVisibilityBuffer); - currentPath = myNamesData.getPathInParentRevision(previousCommit, myPermanentCommitsInfo.getCommitId(parentIndex), previousPath); + Function pathGetter = parentIndex -> myNamesData + .getPathInParentRevision(previousCommit, myPermanentCommitsInfo.getCommitId(parentIndex), previousPath); + currentPath = findPathWithoutConflict(previousNodeId, pathGetter); + if (currentPath == null) { + int parentIndex = BfsUtil.getCorrespondingParent(myPermanentLinearGraph, previousNodeId, currentNodeId, myVisibilityBuffer); + currentPath = pathGetter.fun(parentIndex); + } } else { - // since in reality there is no edge between the nodes, but the whole path, we need to know, which parent is affected by this path - int parentIndex = BfsUtil.getCorrespondingParent(myPermanentLinearGraph, currentNodeId, previousNodeId, myVisibilityBuffer); - currentPath = myNamesData.getPathInChildRevision(currentCommit, myPermanentCommitsInfo.getCommitId(parentIndex), previousPath); + Function pathGetter = + parentIndex -> myNamesData.getPathInChildRevision(currentCommit, myPermanentCommitsInfo.getCommitId(parentIndex), previousPath); + currentPath = findPathWithoutConflict(currentNodeId, pathGetter); + if (currentPath == null) { + // since in reality there is no edge between the nodes, but the whole path, we need to know, which parent is affected by this path + int parentIndex = + BfsUtil.getCorrespondingParent(myPermanentLinearGraph, currentNodeId, previousNodeId, myVisibilityBuffer); + currentPath = pathGetter.fun(parentIndex); + } } } @@ -242,6 +254,20 @@ class FileHistoryFilterer extends VcsLogFilterer { myPaths.push(currentPath); } + @Nullable + private FilePath findPathWithoutConflict(int nodeId, @NotNull Function pathGetter) { + List parents = myPermanentLinearGraph.getNodes(nodeId, LiteLinearGraph.NodeFilter.DOWN); + FilePath path = pathGetter.fun(parents.get(0)); + if (parents.size() == 1) return path; + + for (Integer parent : ContainerUtil.subList(parents, 1)) { + if (!Objects.equals(pathGetter.fun(parent), path)) { + return null; + } + } + return path; + } + @Override public void exitNode(int node) { myPaths.pop();