[vcs-log] distinguish nonexistent hashes from unmatched

This commit is contained in:
Julia Beliaeva
2018-07-06 16:36:51 +03:00
parent 0557e7f376
commit a2c8593389
4 changed files with 71 additions and 42 deletions
@@ -216,7 +216,14 @@ public class FileHistoryUi extends AbstractVcsLogUi {
}
@Override
protected <T> void handleCommitNotFound(@NotNull T commitId, @NotNull PairFunction<GraphTableModel, T, Integer> rowGetter) {
protected <T> void handleCommitNotFound(@NotNull T commitId,
boolean commitExists,
@NotNull PairFunction<GraphTableModel, T, Integer> rowGetter) {
if (!commitExists) {
super.handleCommitNotFound(commitId, false, rowGetter);
return;
}
String mainText = "Commit " + commitId.toString() + " does not exist in history for " + myPath.getName();
if (getFilterUi().getFilters().get(VcsLogFilterCollection.BRANCH_FILTER) != null) {
showWarningWithLink(mainText + " in current branch.", "Show all branches and search again.", () -> {
@@ -240,9 +247,6 @@ public class FileHistoryUi extends AbstractVcsLogUi {
}
});
}
else {
super.handleCommitNotFound(commitId, rowGetter);
}
}
}
@@ -185,9 +185,9 @@ public abstract class AbstractVcsLogUi implements VcsLogUi, Disposable {
GraphTableModel model = getTable().getModel();
int row = rowGetter.fun(model, commitId);
if (row >= 0) {
getTable().jumpToRow(row);
int result = rowGetter.fun(model, commitId);
if (result >= 0) {
getTable().jumpToRow(result);
future.set(true);
}
else if (model.canRequestMore()) {
@@ -197,13 +197,21 @@ public abstract class AbstractVcsLogUi implements VcsLogUi, Disposable {
invokeOnChange(() -> jumpTo(commitId, rowGetter, future));
}
else {
handleCommitNotFound(commitId, rowGetter);
handleCommitNotFound(commitId, result == GraphTableModel.COMMIT_DOES_NOT_MATCH, rowGetter);
future.set(false);
}
}
protected <T> void handleCommitNotFound(@NotNull T commitId, @NotNull PairFunction<GraphTableModel, T, Integer> rowGetter) {
VcsBalloonProblemNotifier.showOverChangesView(myProject, "Commit " + commitId.toString() + " not found.", MessageType.WARNING);
protected <T> void handleCommitNotFound(@NotNull T commitId,
boolean commitExists,
@NotNull PairFunction<GraphTableModel, T, Integer> rowGetter) {
String message = getCommitNotFoundMessage(commitId, commitExists);
VcsBalloonProblemNotifier.showOverChangesView(myProject, message, MessageType.WARNING);
}
@NotNull
protected static <T> String getCommitNotFoundMessage(@NotNull T commitId, boolean exists) {
return exists ? "Commit " + commitId.toString() + " does not match active filters" : "Commit " + commitId.toString() + " not found";
}
protected void showWarningWithLink(@NotNull String mainText, @NotNull String linkText, @NotNull Runnable onClick) {
@@ -99,35 +99,36 @@ public class VcsLogUiImpl extends AbstractVcsLogUi {
}
@Override
protected <T> void handleCommitNotFound(@NotNull T commitId, @NotNull PairFunction<GraphTableModel, T, Integer> rowGetter) {
if (getFilterUi().getFilters().isEmpty()) {
super.handleCommitNotFound(commitId, rowGetter);
protected <T> void handleCommitNotFound(@NotNull T commitId,
boolean commitExists,
@NotNull PairFunction<GraphTableModel, T, Integer> rowGetter) {
if (getFilterUi().getFilters().isEmpty() || !commitExists) {
super.handleCommitNotFound(commitId, commitExists, rowGetter);
return;
}
else {
List<NamedRunnable> runnables = ContainerUtil.newArrayList();
runnables.add(new NamedRunnable("Reset filters and search again.") {
List<NamedRunnable> runnables = ContainerUtil.newArrayList();
runnables.add(new NamedRunnable("Reset filters and search again.") {
@Override
public void run() {
getFilterUi().setFilter(null);
invokeOnChange(() -> jumpTo(commitId, rowGetter, SettableFuture.create()),
pack -> pack.getFilters().isEmpty());
}
});
if (VcsLogProjectTabsProperties.MAIN_LOG_ID.equals(getId())) {
runnables.add(new NamedRunnable("Search in new tab.") {
@Override
public void run() {
getFilterUi().setFilter(null);
invokeOnChange(() -> jumpTo(commitId, rowGetter, SettableFuture.create()),
pack -> pack.getFilters().isEmpty());
VcsProjectLog projectLog = VcsProjectLog.getInstance(myProject);
VcsLogUiImpl ui = projectLog.getTabsManager().openAnotherLogTab(notNull(projectLog.getLogManager()), true);
ui.invokeOnChange(() -> ui.jumpTo(commitId, rowGetter, SettableFuture.create()),
pack -> pack.getFilters().isEmpty());
}
});
if (VcsLogProjectTabsProperties.MAIN_LOG_ID.equals(getId())) {
runnables.add(new NamedRunnable("Search in new tab.") {
@Override
public void run() {
VcsProjectLog projectLog = VcsProjectLog.getInstance(myProject);
VcsLogUiImpl ui = projectLog.getTabsManager().openAnotherLogTab(notNull(projectLog.getLogManager()), true);
ui.invokeOnChange(() -> ui.jumpTo(commitId, rowGetter, SettableFuture.create()),
pack -> pack.getFilters().isEmpty());
}
});
}
VcsBalloonProblemNotifier
.showOverChangesView(myProject, "Commit " + commitId.toString() + " does not exist or does not match active filters",
MessageType.WARNING, runnables.toArray(new NamedRunnable[0]));
}
VcsBalloonProblemNotifier.showOverChangesView(myProject, getCommitNotFoundMessage(commitId, true), MessageType.WARNING,
runnables.toArray(new NamedRunnable[0]));
}
@Override
@@ -1,7 +1,7 @@
package com.intellij.vcs.log.ui.table;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.NotNullFunction;
@@ -12,8 +12,6 @@ import com.intellij.vcs.log.data.CommitIdByStringCondition;
import com.intellij.vcs.log.data.DataGetter;
import com.intellij.vcs.log.data.RefsModel;
import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.util.VcsLogUtil;
import com.intellij.vcs.log.ui.AbstractVcsLogUi;
import com.intellij.vcs.log.ui.render.GraphCommitCell;
import com.intellij.vcs.log.util.VcsUserUtil;
import com.intellij.vcs.log.visible.VisiblePack;
@@ -37,6 +35,9 @@ public class GraphTableModel extends AbstractTableModel {
private static final int UP_PRELOAD_COUNT = 20;
private static final int DOWN_PRELOAD_COUNT = 40;
public static final int COMMIT_NOT_FOUND = -1;
public static final int COMMIT_DOES_NOT_MATCH = -2;
@NotNull private final VcsLogData myLogData;
@NotNull private final Consumer<Runnable> myRequestMore;
@@ -70,16 +71,31 @@ public class GraphTableModel extends AbstractTableModel {
return myLogData.getCommitId(getIdAtRow(row));
}
public int getRowOfCommit(@NotNull final Hash hash, @NotNull VirtualFile root) {
final int commitIndex = myLogData.getCommitIndex(hash, root);
return ContainerUtil.indexOf(VcsLogUtil.getVisibleCommits(myDataPack.getVisibleGraph()), (Condition<Integer>)i -> i == commitIndex);
public int getRowOfCommit(@NotNull Hash hash, @NotNull VirtualFile root) {
if (!myLogData.getStorage().containsCommit(new CommitId(hash, root))) return COMMIT_NOT_FOUND;
return getRowOfCommitWithoutCheck(hash, root);
}
public int getRowOfCommitByPartOfHash(@NotNull String partialHash) {
final CommitIdByStringCondition hashByString = new CommitIdByStringCondition(partialHash);
CommitIdByStringCondition hashByString = new CommitIdByStringCondition(partialHash);
Ref<Boolean> commitExists = new Ref<>(false);
CommitId commitId = myLogData.getStorage().findCommitId(
commitId1 -> hashByString.value(commitId1) && getRowOfCommit(commitId1.getHash(), commitId1.getRoot()) != -1);
return commitId != null ? getRowOfCommit(commitId.getHash(), commitId.getRoot()) : -1;
commitId1 -> {
if (hashByString.value(commitId1)) {
commitExists.set(true);
return getRowOfCommitWithoutCheck(commitId1.getHash(), commitId1.getRoot()) >= 0;
}
return false;
});
return commitId != null
? getRowOfCommitWithoutCheck(commitId.getHash(), commitId.getRoot())
: (commitExists.get() ? COMMIT_DOES_NOT_MATCH : COMMIT_NOT_FOUND);
}
private int getRowOfCommitWithoutCheck(@NotNull Hash hash, @NotNull VirtualFile root) {
int commitIndex = myLogData.getCommitIndex(hash, root);
Integer rowIndex = myDataPack.getVisibleGraph().getVisibleRowIndex(commitIndex);
return rowIndex == null ? COMMIT_DOES_NOT_MATCH : rowIndex;
}
@Override