From 3ab5f46f6d1665e0bdf777b31422bcfc6fdc6caa Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Thu, 10 Mar 2016 18:54:30 +0300 Subject: [PATCH] [vcs-log] got to ref jumps to the first reference that matches, not to any reference that matches IDEA-148029 --- .../vcs/log/impl/VcsGoToRefComparator.java | 47 +++++++++++++++++++ .../com/intellij/vcs/log/impl/VcsLogImpl.java | 10 ++-- .../log/ui/actions/GoToHashOrRefAction.java | 29 +----------- 3 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsGoToRefComparator.java diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsGoToRefComparator.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsGoToRefComparator.java new file mode 100644 index 000000000000..1981806fab69 --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsGoToRefComparator.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2016 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.impl; + +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.vcs.log.VcsLogProvider; +import com.intellij.vcs.log.VcsRef; +import org.jetbrains.annotations.NotNull; + +import java.util.Comparator; +import java.util.Map; + +public class VcsGoToRefComparator implements Comparator { + @NotNull private final Map myProviders; + + public VcsGoToRefComparator(@NotNull Map providers) { + myProviders = providers; + } + + @Override + public int compare(@NotNull VcsRef ref1, @NotNull VcsRef ref2) { + VcsLogProvider provider1 = myProviders.get(ref1.getRoot()); + VcsLogProvider provider2 = myProviders.get(ref1.getRoot()); + + if (provider1 == null) return provider2 == null ? ref1.getName().compareTo(ref2.getName()) : 1; + if (provider2 == null) return -1; + + if (provider1 == provider2) { + return provider1.getReferenceManager().getLabelsOrderComparator().compare(ref1, ref2); + } + + return provider1.getSupportedVcs().getName().compareTo(provider2.getSupportedVcs().getName()); + } +} diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogImpl.java index af956d3435dc..c86a9fd6d00e 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogImpl.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable; import java.util.AbstractList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.Future; @@ -105,17 +106,18 @@ public class VcsLogImpl implements VcsLog { @Override public Future jumpToReference(final String reference) { Collection references = getAllReferences(); - VcsRef ref = ContainerUtil.find(references, new Condition() { + List matchingRefs = ContainerUtil.findAll(references, new Condition() { @Override public boolean value(VcsRef ref) { return ref.getName().startsWith(reference); } }); - if (ref != null) { - return myUi.jumpToCommit(ref.getCommitHash(), ref.getRoot()); + if (matchingRefs.isEmpty()) { + return myUi.jumpToCommitByPartOfHash(reference); } else { - return myUi.jumpToCommitByPartOfHash(reference); + VcsRef ref = Collections.min(matchingRefs, new VcsGoToRefComparator(myUi.getDataPack().getLogProviders())); + return myUi.jumpToCommit(ref.getCommitHash(), ref.getRoot()); } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/GoToHashOrRefAction.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/GoToHashOrRefAction.java index 338dba40e373..de9280874e5d 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/GoToHashOrRefAction.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/GoToHashOrRefAction.java @@ -22,13 +22,11 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Function; import com.intellij.vcs.log.*; +import com.intellij.vcs.log.impl.VcsGoToRefComparator; import com.intellij.vcs.log.impl.VcsLogUtil; import com.intellij.vcs.log.ui.VcsLogUiImpl; -import org.jetbrains.annotations.NotNull; import java.util.Collection; -import java.util.Comparator; -import java.util.Map; import java.util.Set; import java.util.concurrent.Future; @@ -52,7 +50,7 @@ public class GoToHashOrRefAction extends DumbAwareAction { public Future fun(VcsRef vcsRef) { return logUi.jumpToCommit(vcsRef.getCommitHash(), vcsRef.getRoot()); } - }, logUi.getColorManager(), new VcsRefComparator(logUi.getDataPack().getLogProviders())); + }, logUi.getColorManager(), new VcsGoToRefComparator(logUi.getDataPack().getLogProviders())); popup.show(logUi.getTable()); } @@ -62,27 +60,4 @@ public class GoToHashOrRefAction extends DumbAwareAction { VcsLogUi logUi = e.getData(VcsLogDataKeys.VCS_LOG_UI); e.getPresentation().setEnabledAndVisible(e.getProject() != null && log != null && logUi != null); } - - private static class VcsRefComparator implements Comparator { - @NotNull private final Map myProviders; - - public VcsRefComparator(@NotNull Map providers) { - myProviders = providers; - } - - @Override - public int compare(@NotNull VcsRef ref1, @NotNull VcsRef ref2) { - VcsLogProvider provider1 = myProviders.get(ref1.getRoot()); - VcsLogProvider provider2 = myProviders.get(ref1.getRoot()); - - if (provider1 == null) return provider2 == null ? ref1.getName().compareTo(ref2.getName()) : 1; - if (provider2 == null) return -1; - - if (provider1 == provider2) { - return provider1.getReferenceManager().getLabelsOrderComparator().compare(ref1, ref2); - } - - return provider1.getSupportedVcs().getName().compareTo(provider2.getSupportedVcs().getName()); - } - } }