[file-history] provide file names data with visible pack for the ui

This commit is contained in:
Julia Beliaeva
2017-01-31 23:54:52 +03:00
parent bb53f896a8
commit 0e2e04ab3d
4 changed files with 79 additions and 7 deletions
@@ -171,5 +171,19 @@ public class IndexDataGetter {
myCommitsToRenames.put(commit, ContainerUtil.set(new UnorderedPair<>(path, previousPath)));
}
}
@NotNull
public Set<FilePath> getAffectedPaths(int commit) {
Set<FilePath> paths = myCommitsToPaths.get(commit);
if (paths != null) return paths;
Set<UnorderedPair<FilePath>> renames = myCommitsToRenames.get(commit);
Set<FilePath> result = ContainerUtil.newHashSet();
for (UnorderedPair<FilePath> rename : renames) {
result.add(rename.first);
result.add(rename.second);
}
return result;
}
}
}
@@ -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<Integer> visibleGraph = createVisibleGraph(dataPack, sortType, matchingHeads, matchingCommits);
return new FileHistoryVisiblePack(dataPack, visibleGraph, canRequestMore, filters, namesData);
}
VisibleGraph<Integer> 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,
@@ -168,8 +168,7 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable
@NotNull
private List<Change> collectRelevantChanges(@NotNull VcsFullCommitDetails details) {
Set<FilePath> fileNames = myIndexDataGetter.getFileNames(myFilePath,
myLogData.getStorage().getCommitIndex(details.getId(), details.getRoot()));
Set<FilePath> 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<FilePath> getFileNames(@NotNull VcsFullCommitDetails details) {
int commitIndex = myLogData.getStorage().getCommitIndex(details.getId(), details.getRoot());
VisiblePack pack = myGraphTable.getModel().getVisiblePack();
Set<FilePath> 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<FilePath> files) {
if (change.getAfterRevision() == null) {
ContentRevision beforeRevision = change.getBeforeRevision();
@@ -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<Integer> graph,
boolean canRequestMore,
@NotNull VcsLogFilterCollection filters,
@NotNull IndexDataGetter.FileNamesData namesData) {
super(dataPack, graph, canRequestMore, filters);
myNamesData = namesData;
}
@NotNull
public IndexDataGetter.FileNamesData getNamesData() {
return myNamesData;
}
}