From 0e2e04ab3da50c323242a307d305ad4d762ec1c6 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 24 Jan 2017 22:58:54 +0300 Subject: [PATCH] [file-history] provide file names data with visible pack for the ui --- .../vcs/log/data/index/IndexDataGetter.java | 14 +++++++ .../log/ui/history/FileHistoryFilterer.java | 12 +++--- .../vcs/log/ui/history/FileHistoryPanel.java | 19 ++++++++- .../ui/history/FileHistoryVisiblePack.java | 41 +++++++++++++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryVisiblePack.java diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java index 848d83982a8c..97714b603b23 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java @@ -171,5 +171,19 @@ public class IndexDataGetter { myCommitsToRenames.put(commit, ContainerUtil.set(new UnorderedPair<>(path, previousPath))); } } + + @NotNull + public Set getAffectedPaths(int commit) { + Set paths = myCommitsToPaths.get(commit); + if (paths != null) return paths; + + Set> renames = myCommitsToRenames.get(commit); + Set result = ContainerUtil.newHashSet(); + for (UnorderedPair rename : renames) { + result.add(rename.first); + result.add(rename.second); + } + return result; + } } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryFilterer.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryFilterer.java index 1311227e0470..d6e3ae4c8170 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryFilterer.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryFilterer.java @@ -76,7 +76,8 @@ class FileHistoryFilterer extends VcsLogFilterer { // No worries! It's going to be fine later! IndexDataGetter.FileNamesData namesData = myIndexDataGetter.buildFileNamesData(myFilePath); if (!namesData.hasRenames()) { - return super.createVisiblePack(dataPack, sortType, filters, matchingHeads, matchingCommits, canRequestMore); + VisibleGraph visibleGraph = createVisibleGraph(dataPack, sortType, matchingHeads, matchingCommits); + return new FileHistoryVisiblePack(dataPack, visibleGraph, canRequestMore, filters, namesData); } VisibleGraph visibleGraph = createVisibleGraph(dataPack, sortType, matchingHeads, matchingCommits); @@ -84,13 +85,14 @@ class FileHistoryFilterer extends VcsLogFilterer { FileHistoryRefiner refiner = new FileHistoryRefiner(visibleGraph, namesData); if (refiner.refine(((VisibleGraphImpl)visibleGraph).getLinearGraph(), getCurrentRow(dataPack, visibleGraph, namesData), myFilePath)) { // creating a vg is the most expensive task, so trying to avoid that when unnecessary - return new VisiblePack(dataPack, createVisibleGraph(dataPack, sortType, matchingHeads, refiner.getMatchingCommits()), - canRequestMore, - filters); + return new FileHistoryVisiblePack(dataPack, createVisibleGraph(dataPack, sortType, matchingHeads, refiner.getMatchingCommits()), + canRequestMore, + filters, + namesData); } } - return new VisiblePack(dataPack, visibleGraph, canRequestMore, filters); + return new FileHistoryVisiblePack(dataPack, visibleGraph, canRequestMore, filters, namesData); } private int getCurrentRow(@NotNull DataPack pack, diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryPanel.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryPanel.java index 2ad8191b5717..08bf29419cd4 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryPanel.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryPanel.java @@ -168,8 +168,7 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable @NotNull private List collectRelevantChanges(@NotNull VcsFullCommitDetails details) { - Set fileNames = myIndexDataGetter.getFileNames(myFilePath, - myLogData.getStorage().getCommitIndex(details.getId(), details.getRoot())); + Set fileNames = getFileNames(details); if (myFilePath.isDirectory()) { return ContainerUtil.filter(details.getChanges(), change -> affectsDirectories(change, fileNames)); } @@ -178,6 +177,22 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable } } + @NotNull + private Set getFileNames(@NotNull VcsFullCommitDetails details) { + int commitIndex = myLogData.getStorage().getCommitIndex(details.getId(), details.getRoot()); + VisiblePack pack = myGraphTable.getModel().getVisiblePack(); + Set names; + if (pack instanceof FileHistoryVisiblePack) { + IndexDataGetter.FileNamesData namesData = ((FileHistoryVisiblePack)pack).getNamesData(); + names = namesData.getAffectedPaths(commitIndex); + } + else { + names = myIndexDataGetter.getFileNames(myFilePath, commitIndex); + } + if (names.isEmpty()) return Collections.singleton(myFilePath); + return names; + } + private static boolean affectsFiles(@NotNull Change change, @NotNull Set files) { if (change.getAfterRevision() == null) { ContentRevision beforeRevision = change.getBeforeRevision(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryVisiblePack.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryVisiblePack.java new file mode 100644 index 000000000000..116a01946d21 --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/history/FileHistoryVisiblePack.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.vcs.log.ui.history; + +import com.intellij.vcs.log.VcsLogFilterCollection; +import com.intellij.vcs.log.data.DataPackBase; +import com.intellij.vcs.log.data.index.IndexDataGetter; +import com.intellij.vcs.log.graph.VisibleGraph; +import com.intellij.vcs.log.visible.VisiblePack; +import org.jetbrains.annotations.NotNull; + +public class FileHistoryVisiblePack extends VisiblePack { + @NotNull private final IndexDataGetter.FileNamesData myNamesData; + + public FileHistoryVisiblePack(@NotNull DataPackBase dataPack, + @NotNull VisibleGraph graph, + boolean canRequestMore, + @NotNull VcsLogFilterCollection filters, + @NotNull IndexDataGetter.FileNamesData namesData) { + super(dataPack, graph, canRequestMore, filters); + myNamesData = namesData; + } + + @NotNull + public IndexDataGetter.FileNamesData getNamesData() { + return myNamesData; + } +}