mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] got to ref jumps to the first reference that matches, not to any reference that matches IDEA-148029
This commit is contained in:
@@ -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<VcsRef> {
|
||||
@NotNull private final Map<VirtualFile, VcsLogProvider> myProviders;
|
||||
|
||||
public VcsGoToRefComparator(@NotNull Map<VirtualFile, VcsLogProvider> 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());
|
||||
}
|
||||
}
|
||||
@@ -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<Boolean> jumpToReference(final String reference) {
|
||||
Collection<VcsRef> references = getAllReferences();
|
||||
VcsRef ref = ContainerUtil.find(references, new Condition<VcsRef>() {
|
||||
List<VcsRef> matchingRefs = ContainerUtil.findAll(references, new Condition<VcsRef>() {
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<VcsRef> {
|
||||
@NotNull private final Map<VirtualFile, VcsLogProvider> myProviders;
|
||||
|
||||
public VcsRefComparator(@NotNull Map<VirtualFile, VcsLogProvider> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user