[log] Don't store Hash in CommitCell to avoid memory waste.

Instead get the hash by row differently from different table models.
This is a better fix for IDEA-115480
This commit is contained in:
Kirill Likhodedov
2013-10-28 19:41:56 +04:00
parent a9f1c74150
commit 0024cf32e8
7 changed files with 31 additions and 25 deletions
@@ -1,9 +1,7 @@
package com.intellij.vcs.log.graph.render;
import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.VcsRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -14,14 +12,8 @@ public class CommitCell {
private final String text;
private final Collection<VcsRef> refsToThisCommit;
private Hash myHash;
/**
* Hash can be null, if, for example, this is a cell which doesn't contain a commit, but contains only a part of the graph
* (such situations may appear, for example, if graph is filtered by branch, as described in IDEA-115442).
*/
public CommitCell(@Nullable Hash hash, @NotNull String text, @NotNull Collection<VcsRef> refsToThisCommit) {
myHash = hash;
public CommitCell(@NotNull String text, @NotNull Collection<VcsRef> refsToThisCommit) {
this.text = text;
this.refsToThisCommit = refsToThisCommit;
}
@@ -34,8 +26,4 @@ public class CommitCell {
return refsToThisCommit;
}
@Nullable
public Hash getHash() {
return myHash;
}
}
@@ -1,10 +1,8 @@
package com.intellij.vcs.log.graph.render;
import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.VcsRef;
import com.intellij.vcs.log.printmodel.GraphPrintCell;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -16,9 +14,9 @@ public class GraphCommitCell extends CommitCell {
private final GraphPrintCell row;
public GraphCommitCell(@Nullable Hash hash, @NotNull GraphPrintCell row, @NotNull String text,
public GraphCommitCell(@NotNull GraphPrintCell row, @NotNull String text,
@NotNull Collection<VcsRef> refsToThisCommit) {
super(hash, text, refsToThisCommit);
super(text, refsToThisCommit);
this.row = row;
}
@@ -21,7 +21,6 @@ import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.VcsLog;
import com.intellij.vcs.log.data.VcsLogDataHolder;
import com.intellij.vcs.log.graph.render.CommitCell;
import com.intellij.vcs.log.ui.VcsLogUI;
import com.intellij.vcs.log.ui.tables.AbstractVcsLogTableModel;
import org.jetbrains.annotations.NotNull;
@@ -57,8 +56,7 @@ public class VcsLogImpl implements VcsLog {
List<Hash> hashes = ContainerUtil.newArrayList();
JBTable table = myUi.getTable();
for (int row : table.getSelectedRows()) {
CommitCell cell = (CommitCell)table.getModel().getValueAt(row, AbstractVcsLogTableModel.COMMIT_COLUMN);
Hash hash = cell.getHash();
Hash hash = ((AbstractVcsLogTableModel)table.getModel()).getHashAtRow(row);
if (hash != null) {
hashes.add(hash);
}
@@ -15,7 +15,6 @@ import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.VcsRef;
import com.intellij.vcs.log.data.LoadingDetails;
import com.intellij.vcs.log.data.VcsLogDataHolder;
import com.intellij.vcs.log.graph.render.CommitCell;
import com.intellij.vcs.log.graph.render.PrintParameters;
import com.intellij.vcs.log.ui.VcsLogColorManager;
import com.intellij.vcs.log.ui.render.RefPainter;
@@ -83,8 +82,7 @@ class DetailsPanel extends JPanel implements ListSelectionListener {
}
else {
((CardLayout)getLayout()).show(this, STANDARD_LAYER);
CommitCell cell = (CommitCell)myGraphTable.getModel().getValueAt(rows[0], AbstractVcsLogTableModel.COMMIT_COLUMN);
Hash hash = cell.getHash();
Hash hash = ((AbstractVcsLogTableModel)myGraphTable.getModel()).getHashAtRow(rows[0]);
if (hash == null) {
showMessage("Nothing selected");
return;
@@ -4,6 +4,7 @@ import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.impl.NullVirtualFile;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.VcsShortCommitDetails;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -80,6 +81,14 @@ public abstract class AbstractVcsLogTableModel<T> extends AbstractTableModel {
@NotNull
protected abstract Class<T> getCommitColumnClass();
/**
* Returns the Hash of the commit displayed in the given row.
* May be null if there is no commit in the row
* (such situations may appear, for example, if graph is filtered by branch, as described in IDEA-115442).
*/
@Nullable
public abstract Hash getHashAtRow(int row);
@Override
public Class<?> getColumnClass(int column) {
switch (column) {
@@ -121,7 +121,7 @@ public class GraphTableModel extends AbstractVcsLogTableModel<GraphCommitCell> {
message = details.getSubject();
refs = (List<VcsRef>)myDataPack.getRefsModel().refsToCommit(details.getHash());
}
return new GraphCommitCell(hash, graphPrintCell, message, refs);
return new GraphCommitCell(graphPrintCell, message, refs);
}
@NotNull
@@ -129,4 +129,12 @@ public class GraphTableModel extends AbstractVcsLogTableModel<GraphCommitCell> {
protected Class<GraphCommitCell> getCommitColumnClass() {
return GraphCommitCell.class;
}
@Nullable
@Override
public Hash getHashAtRow(int row) {
Node node = myDataPack.getGraphModel().getGraph().getCommitNodeInRow(row);
return node == null ? null : node.getCommitHash();
}
}
@@ -4,6 +4,7 @@ import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.VcsRef;
import com.intellij.vcs.log.VcsShortCommitDetails;
@@ -96,7 +97,7 @@ public class NoGraphTableModel extends AbstractVcsLogTableModel<CommitCell> {
subject = details.getSubject();
refs = myRefsModel.refsToCommit(details.getHash());
}
return new CommitCell(myCommits.get(index).getHash(), subject, refs);
return new CommitCell(subject, refs);
}
@NotNull
@@ -105,4 +106,10 @@ public class NoGraphTableModel extends AbstractVcsLogTableModel<CommitCell> {
return CommitCell.class;
}
@Nullable
@Override
public Hash getHashAtRow(int row) {
return myCommits.get(row).getHash();
}
}