From 1bf9d3a3bcde4a6c137ce1bc71266700820facb7 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Fri, 29 Dec 2017 05:13:22 +0300 Subject: [PATCH] [vcs-log] introduce getAllVisibleRoots util method for VcsLogFilterCollection --- .../com/intellij/vcs/log/impl/VcsLogUtil.java | 19 ++++++++++++------- .../vcs/log/ui/table/IndexSpeedSearch.java | 3 +-- .../vcs/log/visible/VcsLogFilterer.java | 8 +++----- .../git4idea/branch/DeepCompareAction.java | 10 ++-------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUtil.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUtil.java index b80f4e735713..66dcbe5fa942 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUtil.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogUtil.java @@ -122,7 +122,19 @@ public class VcsLogUtil { return selectedRoots; } + @NotNull + public static Set getVisibleRoots(@NotNull VcsLogUi logUi) { + VcsLogFilterCollection filters = logUi.getFilterUi().getFilters(); + Set roots = logUi.getDataPack().getLogProviders().keySet(); + return getAllVisibleRoots(roots, filters); + } + @NotNull + public static Set getAllVisibleRoots(@NotNull Collection roots, + @NotNull VcsLogFilterCollection collection) { + return getAllVisibleRoots(roots, collection.getRootFilter(), collection.getStructureFilter()); + } + // collect absolutely all roots that might be visible // if filters unset returns just all roots @NotNull @@ -170,13 +182,6 @@ public class VcsLogUtil { return list.subList(0, Math.min(list.size(), max)); } - @NotNull - public static Set getVisibleRoots(@NotNull VcsLogUi logUi) { - VcsLogFilterCollection filters = logUi.getFilterUi().getFilters(); - Set roots = logUi.getDataPack().getLogProviders().keySet(); - return getAllVisibleRoots(roots, filters.getRootFilter(), filters.getStructureFilter()); - } - @Nullable public static String getSingleFilteredBranch(@NotNull VcsLogBranchFilter filter, @NotNull VcsLogRefs refs) { String branchName = null; diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/IndexSpeedSearch.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/IndexSpeedSearch.java index 92942c350f17..d582fdc94fc6 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/IndexSpeedSearch.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/table/IndexSpeedSearch.java @@ -75,8 +75,7 @@ public class IndexSpeedSearch extends VcsLogSpeedSearch { if (super.isSpeedSearchEnabled()) { VisiblePack visiblePack = myComponent.getModel().getVisiblePack(); Set roots = visiblePack.getLogProviders().keySet(); - Set visibleRoots = VcsLogUtil.getAllVisibleRoots(roots, visiblePack.getFilters().getRootFilter(), - visiblePack.getFilters().getStructureFilter()); + Set visibleRoots = VcsLogUtil.getAllVisibleRoots(roots, visiblePack.getFilters()); for (VirtualFile root : visibleRoots) { if (!myIndex.isIndexed(root)) return false; } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/visible/VcsLogFilterer.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/visible/VcsLogFilterer.java index 21fe7d9c1f6a..5bfb5f5023fa 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/visible/VcsLogFilterer.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/visible/VcsLogFilterer.java @@ -71,8 +71,7 @@ public class VcsLogFilterer { return Pair.create(applyHashFilter(dataPack, hashFilter.getHashes(), sortType), commitCount); } - Collection visibleRoots = - VcsLogUtil.getAllVisibleRoots(dataPack.getLogProviders().keySet(), filters.getRootFilter(), filters.getStructureFilter()); + Collection visibleRoots = VcsLogUtil.getAllVisibleRoots(dataPack.getLogProviders().keySet(), filters); Set matchingHeads = getMatchingHeads(dataPack.getRefsModel(), visibleRoots, filters); FilterByDetailsResult filterResult = filterByDetails(dataPack, filters, commitCount, visibleRoots, matchingHeads); @@ -264,8 +263,7 @@ public class VcsLogFilterer { private static Collection getFilteredDetailsFromTheVcs(@NotNull Map providers, @NotNull VcsLogFilterCollection filterCollection, int maxCount) throws VcsException { - Set visibleRoots = - VcsLogUtil.getAllVisibleRoots(providers.keySet(), filterCollection.getRootFilter(), filterCollection.getStructureFilter()); + Set visibleRoots = VcsLogUtil.getAllVisibleRoots(providers.keySet(), filterCollection); Collection commits = ContainerUtil.newArrayList(); for (Map.Entry entry : providers.entrySet()) { @@ -304,7 +302,7 @@ public class VcsLogFilterer { List detailsFilters = filters.getDetailsFilters(); if (detailsFilters.isEmpty()) return false; - Set affectedRoots = VcsLogUtil.getAllVisibleRoots(roots, filters.getRootFilter(), filters.getStructureFilter()); + Set affectedRoots = VcsLogUtil.getAllVisibleRoots(roots, filters); boolean needsIndex = !affectedRoots.isEmpty(); if (needsIndex) { LOG.debug(filters + " are affected by indexing of " + affectedRoots); diff --git a/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java b/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java index 69ccd826c255..834a29acc863 100644 --- a/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java +++ b/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java @@ -67,7 +67,7 @@ public class DeepCompareAction extends ToggleAction implements DumbAware { selectBranchAndPerformAction(ui.getDataPack(), e, selectedBranch -> { ui.getFilterUi().setFilter(VcsLogBranchFilterImpl.fromBranch(selectedBranch)); dc.highlightInBackground(selectedBranch, dataProvider); - }, getAllVisibleRoots(ui)); + }, VcsLogUtil.getVisibleRoots(ui)); return; } dc.highlightInBackground(singleBranchName, dataProvider); @@ -110,17 +110,11 @@ public class DeepCompareAction extends ToggleAction implements DumbAware { Project project = e.getData(CommonDataKeys.PROJECT); VcsLogUi ui = e.getData(VcsLogDataKeys.VCS_LOG_UI); e.getPresentation().setEnabledAndVisible(project != null && ui != null && - hasGitRoots(project, getAllVisibleRoots(ui))); + hasGitRoots(project, VcsLogUtil.getVisibleRoots(ui))); } private static boolean hasGitRoots(@NotNull Project project, @NotNull Set roots) { final GitRepositoryManager manager = GitRepositoryManager.getInstance(project); return ContainerUtil.exists(roots, root -> manager.getRepositoryForRootQuick(root) != null); } - - @NotNull - private static Set getAllVisibleRoots(@NotNull VcsLogUi ui) { - return VcsLogUtil.getAllVisibleRoots(ui.getDataPack().getLogProviders().keySet(), ui.getFilterUi().getFilters().getRootFilter(), - ui.getFilterUi().getFilters().getStructureFilter()); - } }