[vcs-log] keep resolved commits and use them for navigation

This commit is contained in:
Julia Beliaeva
2018-01-21 19:30:19 +03:00
parent 1ca5a9bcd9
commit bfc3f0de67
5 changed files with 30 additions and 18 deletions
@@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.*;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.vcs.log.CommitId;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.impl.CommonUiProperties;
@@ -80,10 +81,10 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable
myDetailsPanel = new DetailsPanel(logData, myUi.getColorManager(), this) {
@Override
protected void navigate(@NotNull String hash) {
protected void navigate(@NotNull CommitId commit) {
VcsLogUiImpl mainLogUi = VcsProjectLog.getInstance(logData.getProject()).getMainLogUi();
if (mainLogUi != null) {
mainLogUi.getVcsLog().jumpToReference(hash);
mainLogUi.jumpToCommit(commit.getHash(), commit.getRoot());
}
}
};
@@ -45,6 +45,7 @@ import java.util.List;
import java.util.stream.Collectors;
import static com.intellij.openapi.vcs.history.VcsHistoryUtil.getCommitDetailsFont;
import static com.intellij.util.ObjectUtils.notNull;
import static com.intellij.vcs.log.ui.frame.CommitPresentationUtil.GO_TO_HASH;
import static com.intellij.vcs.log.ui.frame.CommitPresentationUtil.SHOW_HIDE_BRANCHES;
@@ -61,11 +62,11 @@ public class CommitPanel extends JBPanel {
@NotNull private final BranchesPanel myContainingBranchesPanel;
@NotNull private final RootPanel myRootPanel;
@NotNull private final VcsLogColorManager myColorManager;
@NotNull private final Consumer<String> myNavigate;
@NotNull private final Consumer<CommitId> myNavigate;
@Nullable private CommitId myCommit;
public CommitPanel(@NotNull VcsLogData logData, @NotNull VcsLogColorManager colorManager, @NotNull Consumer<String> navigate) {
public CommitPanel(@NotNull VcsLogData logData, @NotNull VcsLogColorManager colorManager, @NotNull Consumer<CommitId> navigate) {
myLogData = logData;
myColorManager = colorManager;
myNavigate = navigate;
@@ -181,7 +182,8 @@ public class CommitPanel extends JBPanel {
@Override
public void hyperlinkUpdate(@NotNull HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && e.getDescription().startsWith(GO_TO_HASH)) {
myNavigate.consume(e.getDescription().substring(GO_TO_HASH.length()));
CommitId commitId = notNull(myPresentation).parseTargetCommit(e);
if (commitId != null) myNavigate.consume(commitId);
}
else {
BrowserHyperlinkListener.INSTANCE.hyperlinkUpdate(e);
@@ -16,7 +16,9 @@ import com.intellij.vcs.log.util.VcsUserUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -82,7 +84,7 @@ public class CommitPresentationUtil {
CommitId commitId = resolvedHashes.get(hash);
if (commitId != null) {
hash = "<a href=\"" + GO_TO_HASH + commitId.getHash().asString() + "\">" + hash + "</a>";
hash = "<a href=\"" + GO_TO_HASH + hash + "\">" + hash + "</a>";
}
matcher.appendReplacement(result, hash);
}
@@ -268,7 +270,7 @@ public class CommitPresentationUtil {
Set<String> unresolvedHashesForCommit = findHashes(project, subject, description);
String text = formatCommitText(project, subject, description, hashAndAuthor, ContainerUtil.newHashMap());
if (unresolvedHashesForCommit.isEmpty()) {
return new CommitPresentation(text);
return new CommitPresentation(text, Collections.emptyMap());
}
unresolvedHashes.addAll(unresolvedHashesForCommit);
@@ -286,7 +288,7 @@ public class CommitPresentationUtil {
@NotNull String description,
@NotNull String hashAndAuthor,
@NotNull String text) {
super(text);
super(text, Collections.emptyMap());
myProject = project;
mySubject = subject;
myDescription = description;
@@ -296,7 +298,7 @@ public class CommitPresentationUtil {
@NotNull
public CommitPresentation resolve(@NotNull Map<String, CommitId> resolvedHashes) {
String text = formatCommitText(myProject, mySubject, myDescription, myHashAndAuthor, resolvedHashes);
return new CommitPresentation(text);
return new CommitPresentation(text, resolvedHashes);
}
@Override
@@ -307,9 +309,11 @@ public class CommitPresentationUtil {
public static class CommitPresentation {
@NotNull protected final String myText;
@NotNull private final Map<String, CommitId> myResolvedHashes;
public CommitPresentation(@NotNull String text) {
public CommitPresentation(@NotNull String text, @NotNull Map<String, CommitId> resolvedHashes) {
myText = text;
myResolvedHashes = resolvedHashes;
}
@NotNull
@@ -317,6 +321,13 @@ public class CommitPresentationUtil {
return myText;
}
@Nullable
public CommitId parseTargetCommit(@NotNull HyperlinkEvent e) {
if (!e.getDescription().startsWith(GO_TO_HASH)) return null;
String hash = e.getDescription().substring(GO_TO_HASH.length());
return myResolvedHashes.get(hash);
}
@NotNull
public CommitPresentation resolve(@NotNull Map<String, CommitId> resolvedHashes) {
return this;
@@ -139,7 +139,7 @@ public class DetailsPanel extends JPanel implements EditorColorsListener, Dispos
}
}
protected void navigate(@NotNull String hash) {
protected void navigate(@NotNull CommitId commitId) {
}
private void rebuildCommitPanels(int[] selection) {
@@ -21,14 +21,12 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.table.ComponentsListFocusTraversalPolicy;
import com.intellij.vcs.CommittedChangeListForRevision;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.VcsLog;
import com.intellij.vcs.log.VcsLogFilterUi;
import com.intellij.vcs.log.VcsLogUi;
import com.intellij.vcs.log.*;
import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.impl.CommonUiProperties;
import com.intellij.vcs.log.impl.MainVcsLogUiProperties;
import com.intellij.vcs.log.util.VcsLogUtil;
import com.intellij.vcs.log.ui.AbstractVcsLogUi;
import com.intellij.vcs.log.ui.VcsLogActionPlaces;
import com.intellij.vcs.log.ui.VcsLogInternalDataKeys;
import com.intellij.vcs.log.ui.VcsLogUiImpl;
@@ -56,7 +54,7 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
private static final String HELP_ID = "reference.changesToolWindow.log";
@NotNull private final VcsLogData myLogData;
@NotNull private final VcsLogUi myUi;
@NotNull private final AbstractVcsLogUi myUi;
@NotNull private final VcsLog myLog;
@NotNull private final VcsLogClassicFilterUi myFilterUi;
@@ -91,8 +89,8 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
PopupHandler.installPopupHandler(myGraphTable, VcsLogActionPlaces.POPUP_ACTION_GROUP, VcsLogActionPlaces.VCS_LOG_TABLE_PLACE);
myDetailsPanel = new DetailsPanel(logData, ui.getColorManager(), this) {
@Override
protected void navigate(@NotNull String hash) {
myLog.jumpToReference(hash);
protected void navigate(@NotNull CommitId commit) {
myUi.jumpToCommit(commit.getHash(), commit.getRoot());
}
};