From b00e8a249f445a02d466e5035d5ee9e1460bf7c6 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 11 Mar 2014 18:54:27 +0400 Subject: [PATCH] [log] IDEA-121992 Recalculate old heads values The VcsLogBranchFilter used to store precalculated values of commit indices of its heads. However, is it likely that after refresh these values change => setFilter will get either non-head commits, or even invalid (if head commit was rebased/amended). Don't precalculate these values, perform calculation each time, which is fast because there are not too many head ref in the filter (usually 0, 1 or 2). --- .../intellij/vcs/log/VcsLogBranchFilter.java | 5 ----- .../vcs/log/data/VcsLogBranchFilterImpl.java | 22 +------------------ .../intellij/vcs/log/data/VcsLogFilterer.java | 18 ++++++++++++++- .../ui/filter/BranchFilterPopupComponent.java | 3 +-- .../git4idea/branch/DeepCompareAction.java | 3 +-- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogBranchFilter.java b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogBranchFilter.java index 60e588ded1cc..983da2ca38b9 100644 --- a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogBranchFilter.java +++ b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogBranchFilter.java @@ -26,9 +26,4 @@ public interface VcsLogBranchFilter extends VcsLogFilter { @NotNull Collection getBranchNames(); - - // TODO remove from the API - @NotNull - Collection getMatchingHeads(); - } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogBranchFilterImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogBranchFilterImpl.java index f16a44094002..501d5d47980b 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogBranchFilterImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogBranchFilterImpl.java @@ -1,29 +1,16 @@ package com.intellij.vcs.log.data; -import com.intellij.util.Function; -import com.intellij.util.containers.ContainerUtil; import com.intellij.vcs.log.VcsLogBranchFilter; -import com.intellij.vcs.log.VcsRef; import org.jetbrains.annotations.NotNull; import java.util.Collection; public class VcsLogBranchFilterImpl implements VcsLogBranchFilter { - @NotNull private final Collection myMatchingHeads; @NotNull private final Collection myBranchNames; - public VcsLogBranchFilterImpl(@NotNull Collection allRefs, @NotNull final Collection branchNames) { + public VcsLogBranchFilterImpl(@NotNull final Collection branchNames) { myBranchNames = branchNames; - myMatchingHeads = ContainerUtil.mapNotNull(allRefs, new Function() { - @Override - public Integer fun(VcsRef ref) { - if (branchNames.contains(ref.getName())) { - return ref.getCommitIndex(); - } - return null; - } - }); } @Override @@ -36,11 +23,4 @@ public class VcsLogBranchFilterImpl implements VcsLogBranchFilter { public Collection getBranchNames() { return myBranchNames; } - - @Override - @NotNull - public Collection getMatchingHeads() { - return myMatchingHeads; - } - } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogFilterer.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogFilterer.java index e07e92fda5ac..5f007b3459a8 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogFilterer.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogFilterer.java @@ -18,6 +18,8 @@ import gnu.trove.TIntHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -119,7 +121,21 @@ public class VcsLogFilterer { myUI.getTable().executeWithoutRepaint(new Runnable() { @Override public void run() { - dataPack.getGraphFacade().setVisibleBranches(branchFilter != null ? branchFilter.getMatchingHeads() : null); + dataPack.getGraphFacade().setVisibleBranches(branchFilter != null ? getMatchingHeads(dataPack, branchFilter) : null); + } + }); + } + + @NotNull + private static Collection getMatchingHeads(@NotNull DataPack dataPack, @NotNull VcsLogBranchFilter branchFilter) { + final Collection branchNames = new HashSet(branchFilter.getBranchNames()); + return ContainerUtil.mapNotNull(dataPack.getRefsModel().getAllRefs(), new Function() { + @Override + public Integer fun(VcsRef ref) { + if (branchNames.contains(ref.getName())) { + return ref.getCommitIndex(); + } + return null; } }); } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java index 0af25568ed60..d358e86c2a40 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java @@ -158,8 +158,7 @@ public class BranchFilterPopupComponent extends MultipleValueFilterPopupComponen if (getSelectedValues() == null) { return null; } - Collection allBranches = myDataPack.getRefs().getBranches(); - return new VcsLogBranchFilterImpl(allBranches, getSelectedValues()); + return new VcsLogBranchFilterImpl(getSelectedValues()); } @NotNull diff --git a/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java b/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java index ddb6f24042c6..52ccb25a0ce2 100644 --- a/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java +++ b/plugins/git4idea/src/git4idea/branch/DeepCompareAction.java @@ -60,8 +60,7 @@ public class DeepCompareAction extends ToggleAction implements DumbAware { selectBranchAndPerformAction(ui.getDataPack(), e, new Consumer() { @Override public void consume(String selectedBranch) { - ui.getFilterUi().setFilter(new VcsLogBranchFilterImpl(ui.getDataPack().getRefs().getBranches(), - Collections.singleton(selectedBranch))); + ui.getFilterUi().setFilter(new VcsLogBranchFilterImpl(Collections.singleton(selectedBranch))); dc.highlightInBackground(selectedBranch, dataProvider); } });