mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] use commit id in the map and remove myRoot field
This commit is contained in:
@@ -10,7 +10,10 @@ import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.OnePixelSplitter;
|
||||
import com.intellij.ui.PopupHandler;
|
||||
import com.intellij.ui.SearchTextField;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.ui.components.JBLoadingPanel;
|
||||
import com.intellij.ui.components.panels.Wrapper;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -88,8 +91,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);
|
||||
|
||||
myChangesBrowser = new VcsLogChangesBrowser(project, myUiProperties, (hash, root) -> {
|
||||
int index = myLogData.getCommitIndex(hash, root);
|
||||
myChangesBrowser = new VcsLogChangesBrowser(project, myUiProperties, (commitId) -> {
|
||||
int index = myLogData.getCommitIndex(commitId.getHash(), commitId.getRoot());
|
||||
return myLogData.getMiniDetailsGetter().getCommitData(index, Collections.singleton(index));
|
||||
}, this);
|
||||
myChangesBrowser.getDiffAction().registerCustomShortcutSet(myChangesBrowser.getDiffAction().getShortcutSet(), getGraphTable());
|
||||
|
||||
@@ -23,19 +23,19 @@ import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangesUtil;
|
||||
import com.intellij.openapi.vcs.changes.actions.diff.ChangeDiffRequestProducer;
|
||||
import com.intellij.openapi.vcs.changes.committed.CommittedChangesTreeBrowser;
|
||||
import com.intellij.openapi.vcs.changes.ui.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.UI;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.vcs.log.CommitId;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.VcsShortCommitDetails;
|
||||
@@ -52,7 +52,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.notNull;
|
||||
import static com.intellij.util.containers.ContainerUtil.getFirstItem;
|
||||
@@ -64,17 +63,16 @@ import static com.intellij.vcs.log.impl.MainVcsLogUiProperties.SHOW_CHANGES_FROM
|
||||
class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final MainVcsLogUiProperties myUiProperties;
|
||||
@NotNull private final BiFunction<Hash, VirtualFile, VcsShortCommitDetails> myDataGetter;
|
||||
@NotNull private final Function<CommitId, VcsShortCommitDetails> myDataGetter;
|
||||
|
||||
@NotNull private final VcsLogUiProperties.PropertiesChangeListener myListener;
|
||||
|
||||
@Nullable private VirtualFile myRoot;
|
||||
@NotNull private final List<Change> myChanges = ContainerUtil.newArrayList();
|
||||
@NotNull private final Map<Hash, Set<Change>> myChangesToParents = ContainerUtil.newHashMap();
|
||||
@NotNull private final Map<CommitId, Set<Change>> myChangesToParents = ContainerUtil.newHashMap();
|
||||
|
||||
public VcsLogChangesBrowser(@NotNull Project project,
|
||||
@NotNull MainVcsLogUiProperties uiProperties,
|
||||
@NotNull BiFunction<Hash, VirtualFile, VcsShortCommitDetails> getter,
|
||||
@NotNull Function<CommitId, VcsShortCommitDetails> getter,
|
||||
@NotNull Disposable parent) {
|
||||
super(project, false, false);
|
||||
myProject = project;
|
||||
@@ -114,7 +112,6 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
}
|
||||
|
||||
public void resetSelectedDetails() {
|
||||
myRoot = null;
|
||||
myChanges.clear();
|
||||
myChangesToParents.clear();
|
||||
myViewer.setEmptyText("");
|
||||
@@ -122,7 +119,6 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
}
|
||||
|
||||
public void setSelectedDetails(@NotNull List<VcsFullCommitDetails> detailsList) {
|
||||
myRoot = null;
|
||||
myChanges.clear();
|
||||
myChangesToParents.clear();
|
||||
|
||||
@@ -131,13 +127,12 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
}
|
||||
else if (detailsList.size() == 1) {
|
||||
VcsFullCommitDetails detail = notNull(getFirstItem(detailsList));
|
||||
myRoot = detail.getRoot();
|
||||
myChanges.addAll(detail.getChanges());
|
||||
|
||||
if (detail.getParents().size() > 1) {
|
||||
for (int i = 0; i < detail.getParents().size(); i++) {
|
||||
THashSet<Change> changesSet = ContainerUtil.newIdentityTroveSet(detail.getChanges(i));
|
||||
myChangesToParents.put(detail.getParents().get(i), changesSet);
|
||||
myChangesToParents.put(new CommitId(detail.getParents().get(i), detail.getRoot()), changesSet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,10 +175,10 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
if (myChanges.isEmpty()) {
|
||||
builder.addEmptyTextNode("No merged conflicts");
|
||||
}
|
||||
for (Hash hash : myChangesToParents.keySet()) {
|
||||
Collection<Change> changesFromParent = myChangesToParents.get(hash);
|
||||
for (CommitId commitId : myChangesToParents.keySet()) {
|
||||
Collection<Change> changesFromParent = myChangesToParents.get(commitId);
|
||||
if (!changesFromParent.isEmpty()) {
|
||||
builder.addChangesFromParentNode(changesFromParent, hash, myRoot);
|
||||
builder.addChangesFromParentNode(changesFromParent, commitId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,16 +200,10 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
@Override
|
||||
public Object getData(@NotNull String dataId) {
|
||||
if (VcsDataKeys.VCS.is(dataId)) {
|
||||
if (myRoot != null) {
|
||||
AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(myRoot);
|
||||
return vcs == null ? null : vcs.getKeyInstanceMethod();
|
||||
}
|
||||
else {
|
||||
List<Change> selectedChanges = VcsTreeModelData.selected(myViewer).userObjects(Change.class);
|
||||
Set<AbstractVcs> abstractVcs = ChangesUtil.getAffectedVcses(selectedChanges, myProject);
|
||||
if (abstractVcs.size() == 1) return notNull(getFirstItem(abstractVcs)).getKeyInstanceMethod();
|
||||
return null;
|
||||
}
|
||||
List<Change> selectedChanges = VcsTreeModelData.selected(myViewer).userObjects(Change.class);
|
||||
Set<AbstractVcs> abstractVcs = ChangesUtil.getAffectedVcses(selectedChanges, myProject);
|
||||
if (abstractVcs.size() == 1) return notNull(getFirstItem(abstractVcs)).getKeyInstanceMethod();
|
||||
return null;
|
||||
}
|
||||
return super.getData(dataId);
|
||||
}
|
||||
@@ -231,20 +220,20 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
if (userObject instanceof Change) {
|
||||
Change change = (Change)userObject;
|
||||
|
||||
Hash parentHash = null;
|
||||
for (Hash hash : myChangesToParents.keySet()) {
|
||||
if (myChangesToParents.get(hash).contains(change)) {
|
||||
parentHash = hash;
|
||||
CommitId parentId = null;
|
||||
for (CommitId commitId : myChangesToParents.keySet()) {
|
||||
if (myChangesToParents.get(commitId).contains(change)) {
|
||||
parentId = commitId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parentHash != null && myRoot != null) {
|
||||
RootTag tag = new RootTag(parentHash, getText(parentHash, myRoot));
|
||||
if (parentId != null) {
|
||||
RootTag tag = new RootTag(parentId.getHash(), getText(parentId));
|
||||
Map<Key, Object> context = Collections.singletonMap(ChangeDiffRequestProducer.TAG_KEY, tag);
|
||||
return ChangeDiffRequestProducer.create(myProject, change, context);
|
||||
}
|
||||
|
||||
|
||||
return ChangeDiffRequestProducer.create(myProject, change);
|
||||
}
|
||||
return null;
|
||||
@@ -262,8 +251,8 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
myModel.insertNodeInto(textNode, myRoot, myRoot.getChildCount());
|
||||
}
|
||||
|
||||
public void addChangesFromParentNode(@NotNull Collection<Change> changes, @NotNull Hash hash, VirtualFile root) {
|
||||
ChangesBrowserNode parentNode = new ChangesBrowserParentNode(hash, root);
|
||||
public void addChangesFromParentNode(@NotNull Collection<Change> changes, @NotNull CommitId commitId) {
|
||||
ChangesBrowserNode parentNode = new ChangesBrowserParentNode(commitId);
|
||||
parentNode.markAsHelperNode();
|
||||
|
||||
myModel.insertNodeInto(parentNode, myRoot, myRoot.getChildCount());
|
||||
@@ -280,15 +269,15 @@ class VcsLogChangesBrowser extends ChangesBrowserBase implements Disposable {
|
||||
}
|
||||
|
||||
private class ChangesBrowserParentNode extends ChangesBrowserNode {
|
||||
protected ChangesBrowserParentNode(@NotNull Hash parentCommit, @NotNull VirtualFile root) {
|
||||
super(getText(parentCommit, root));
|
||||
protected ChangesBrowserParentNode(@NotNull CommitId commitId) {
|
||||
super(getText(commitId));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getText(@NotNull Hash commit, @NotNull VirtualFile root) {
|
||||
String text = "Changes to " + commit.toShortString();
|
||||
VcsShortCommitDetails detail = myDataGetter.apply(commit, root);
|
||||
private String getText(@NotNull CommitId commitId) {
|
||||
String text = "Changes to " + commitId;
|
||||
VcsShortCommitDetails detail = myDataGetter.fun(commitId);
|
||||
if (!(detail instanceof LoadingDetails) || (detail instanceof IndexedDetails)) {
|
||||
text += " " + StringUtil.shortenTextWithEllipsis(detail.getSubject(), 50, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user