mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] replace CommitId-s in refs map with integers
This commit is contained in:
@@ -17,6 +17,8 @@ package com.intellij.vcs.log;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides {@link DataKey DataKeys} which can be used by actions to access data available in the VCS log.
|
||||
*/
|
||||
@@ -25,4 +27,5 @@ public class VcsLogDataKeys {
|
||||
public static final DataKey<VcsLog> VCS_LOG = DataKey.create("Vcs.Log");
|
||||
public static final DataKey<VcsLogUi> VCS_LOG_UI = DataKey.create("Vcs.Log.Ui");
|
||||
public static final DataKey<VcsLogDataProvider> VCS_LOG_DATA_PROVIDER = DataKey.create("Vcs.Log.DataProvider");
|
||||
public static final DataKey<List<VcsRef>> VCS_LOG_BRANCHES = DataKey.create("Vcs.Log.Branches");
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.vcs.log;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -32,7 +31,7 @@ public interface VcsLogRefs {
|
||||
Collection<VcsRef> getBranches();
|
||||
|
||||
@NotNull
|
||||
Collection<VcsRef> refsToCommit(@NotNull Hash hash, @NotNull VirtualFile root);
|
||||
Collection<VcsRef> refsToCommit(int commit);
|
||||
|
||||
@NotNull
|
||||
Collection<VcsRef> getAllRefs();
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package com.intellij.vcs.log.data;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.vcs.log.*;
|
||||
import com.intellij.vcs.log.CommitId;
|
||||
import com.intellij.vcs.log.VcsLogHashMap;
|
||||
import com.intellij.vcs.log.VcsLogRefs;
|
||||
import com.intellij.vcs.log.VcsRef;
|
||||
import gnu.trove.TIntObjectHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RefsModel implements VcsLogRefs {
|
||||
@NotNull private final Collection<VcsRef> myBranches;
|
||||
@NotNull private final Map<VirtualFile, Set<VcsRef>> myRefs;
|
||||
@NotNull private final MultiMap<CommitId, VcsRef> myRefsToHashes;
|
||||
@NotNull private final TIntObjectHashMap<SmartList<VcsRef>> myRefsToHashes;
|
||||
|
||||
@NotNull private final TIntObjectHashMap<SmartList<VcsRef>> myBranchesToIndices;
|
||||
@NotNull private final TIntObjectHashMap<SmartList<VcsRef>> myRefsToHeadIndices;
|
||||
@NotNull private final TIntObjectHashMap<VirtualFile> myRootsToHeadIndices;
|
||||
|
||||
@@ -37,9 +37,7 @@ public class RefsModel implements VcsLogRefs {
|
||||
}
|
||||
}
|
||||
|
||||
myRefsToHashes = prepareRefsMap(allRefs);
|
||||
|
||||
myBranchesToIndices = prepareRefsToIndicesMap(myBranches, hashMap);
|
||||
myRefsToHashes = prepareRefsToIndicesMap(allRefs, hashMap);
|
||||
myRefsToHeadIndices = prepareRefsToIndicesMap(Iterables.filter(Iterables.concat(refsByRoot.values()),
|
||||
vcsRef -> heads.contains(
|
||||
hashMap.getCommitIndex(vcsRef.getCommitHash(), vcsRef.getRoot()))),
|
||||
@@ -73,18 +71,10 @@ public class RefsModel implements VcsLogRefs {
|
||||
return map;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static MultiMap<CommitId, VcsRef> prepareRefsMap(@NotNull Iterable<VcsRef> refs) {
|
||||
MultiMap<CommitId, VcsRef> map = MultiMap.createSmart();
|
||||
for (VcsRef ref : refs) {
|
||||
map.putValue(new CommitId(ref.getCommitHash(), ref.getRoot()), ref);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<VcsRef> branchesToCommit(int index) {
|
||||
return myBranchesToIndices.containsKey(index) ? myBranchesToIndices.get(index) : Collections.<VcsRef>emptyList();
|
||||
Collection<VcsRef> refs = refsToCommit(index);
|
||||
return refs.stream().filter(ref -> ref.getType().isBranch()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -104,10 +94,9 @@ public class RefsModel implements VcsLogRefs {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VcsRef> refsToCommit(@NotNull Hash hash, @NotNull VirtualFile root) {
|
||||
CommitId commitId = new CommitId(hash, root);
|
||||
if (myRefsToHashes.containsKey(commitId)) {
|
||||
return myRefsToHashes.get(commitId);
|
||||
public Collection<VcsRef> refsToCommit(int index) {
|
||||
if (myRefsToHashes.containsKey(index)) {
|
||||
return myRefsToHashes.get(index);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -121,6 +110,17 @@ public class RefsModel implements VcsLogRefs {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VcsRef> getAllRefs() {
|
||||
return ContainerUtil.newHashSet(myRefsToHashes.values());
|
||||
return new AbstractCollection<VcsRef>() {
|
||||
@Override
|
||||
public Iterator<VcsRef> iterator() {
|
||||
List<Iterator<VcsRef>> iterators = myRefs.values().stream().map(Set::iterator).collect(Collectors.toList());
|
||||
return Iterators.concat(iterators.toArray(new Iterator[iterators.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return myRefs.values().stream().mapToInt(Set::size).sum();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class CommitPanel extends JBPanel {
|
||||
myDataPack = visiblePack;
|
||||
}
|
||||
|
||||
public void setCommit(@NotNull VcsFullCommitDetails commitData) {
|
||||
public void setCommit(@NotNull VcsFullCommitDetails commitData, @NotNull Collection<VcsRef> refs) {
|
||||
if (!Comparing.equal(myCommit, commitData)) {
|
||||
if (commitData instanceof LoadingDetails) {
|
||||
myDataPanel.setData(null);
|
||||
@@ -100,7 +100,7 @@ class CommitPanel extends JBPanel {
|
||||
}
|
||||
else {
|
||||
myDataPanel.setData(commitData);
|
||||
myReferencesPanel.setReferences(sortRefs(commitData.getId(), commitData.getRoot()));
|
||||
myReferencesPanel.setReferences(sortRefs(refs, commitData.getRoot()));
|
||||
updateBorder(commitData);
|
||||
}
|
||||
myCommit = commitData;
|
||||
@@ -132,8 +132,7 @@ class CommitPanel extends JBPanel {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<VcsRef> sortRefs(@NotNull Hash hash, @NotNull VirtualFile root) {
|
||||
Collection<VcsRef> refs = myDataPack.getRefs().refsToCommit(hash, root);
|
||||
private List<VcsRef> sortRefs(@NotNull Collection<VcsRef> refs, @NotNull VirtualFile root) {
|
||||
return ContainerUtil.sorted(refs, myLogData.getLogProvider(root).getReferenceManager().getLabelsOrderComparator());
|
||||
}
|
||||
|
||||
|
||||
@@ -221,7 +221,8 @@ class DetailsPanel extends JPanel implements EditorColorsListener {
|
||||
Set<VcsFullCommitDetails> newCommitDetails = ContainerUtil.newHashSet(detailsList);
|
||||
for (int i = 0; i < mySelection.size(); i++) {
|
||||
CommitPanel commitPanel = getCommitPanel(i);
|
||||
commitPanel.setCommit(detailsList.get(i));
|
||||
Integer commit = myDataPack.getVisibleGraph().getRowInfo(mySelection.get(i)).getCommit();
|
||||
commitPanel.setCommit(detailsList.get(i), myDataPack.getRefs().refsToCommit(commit));
|
||||
}
|
||||
|
||||
if (!ContainerUtil.intersects(myCommitDetails, newCommitDetails)) {
|
||||
|
||||
@@ -283,6 +283,10 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
|
||||
if (roots.size() == 1) {
|
||||
return myLogData.getLogProvider(assertNotNull(getFirstItem(roots))).getSupportedVcs();
|
||||
}
|
||||
} else if (VcsLogDataKeys.VCS_LOG_BRANCHES.is(dataId)) {
|
||||
int[] selectedRows = myGraphTable.getSelectedRows();
|
||||
if (selectedRows.length != 1) return null;
|
||||
return myGraphTable.getModel().getBranchesAtRow(selectedRows[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GraphTableModel extends AbstractTableModel {
|
||||
public static final int ROOT_COLUMN = 0;
|
||||
@@ -111,7 +113,7 @@ public class GraphTableModel extends AbstractTableModel {
|
||||
case ROOT_COLUMN:
|
||||
return getRoot(rowIndex);
|
||||
case COMMIT_COLUMN:
|
||||
return new GraphCommitCell(data.getSubject(), myDataPack.getRefs().refsToCommit(data.getId(), data.getRoot()));
|
||||
return new GraphCommitCell(data.getSubject(), getRefsAtRow(rowIndex));
|
||||
case AUTHOR_COLUMN:
|
||||
String authorString = VcsUserUtil.getShortPresentation(data.getAuthor());
|
||||
return authorString + (VcsUserUtil.isSamePerson(data.getAuthor(), data.getCommitter()) ? "" : "*");
|
||||
@@ -182,6 +184,16 @@ public class GraphTableModel extends AbstractTableModel {
|
||||
return dataGetter.getCommitData(getIdAtRow(row), iterable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<VcsRef> getRefsAtRow(int row) {
|
||||
return myDataPack.getRefs().refsToCommit(getIdAtRow(row));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<VcsRef> getBranchesAtRow(int row) {
|
||||
return getRefsAtRow(row).stream().filter(ref -> ref.getType().isBranch()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Iterable<Integer> createRowsIterable(final int row, final int above, final int below, final int maxRows) {
|
||||
return () -> new Iterator<Integer>() {
|
||||
|
||||
@@ -31,7 +31,10 @@ import git4idea.ui.branch.GitBranchPopupActions.LocalBranchActions;
|
||||
import git4idea.ui.branch.GitBranchPopupActions.RemoteBranchActions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class GitLogBranchOperationsActionGroup extends ActionGroup implements DumbAware {
|
||||
private static final int MAX_BRANCH_GROUPS = 2;
|
||||
@@ -52,7 +55,8 @@ public class GitLogBranchOperationsActionGroup extends ActionGroup implements Du
|
||||
Project project = e.getProject();
|
||||
VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG);
|
||||
VcsLogUi logUI = e.getData(VcsLogDataKeys.VCS_LOG_UI);
|
||||
if (project == null || log == null || logUI == null) {
|
||||
List<VcsRef> branches = e.getData(VcsLogDataKeys.VCS_LOG_BRANCHES);
|
||||
if (project == null || log == null || logUI == null || branches == null) {
|
||||
return AnAction.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -64,10 +68,7 @@ public class GitLogBranchOperationsActionGroup extends ActionGroup implements Du
|
||||
final GitRepository root = repositoryManager.getRepositoryForRoot(commit.getRoot());
|
||||
if (root == null) return AnAction.EMPTY_ARRAY;
|
||||
|
||||
VcsLogDataPack dataPack = logUI.getDataPack();
|
||||
Collection<VcsRef> allVcsRefs = dataPack.getRefs().refsToCommit(commit.getHash(), commit.getRoot());
|
||||
|
||||
List<VcsRef> vcsRefs = ContainerUtil.filter(allVcsRefs, new Condition<VcsRef>() {
|
||||
List<VcsRef> vcsRefs = ContainerUtil.filter(branches, new Condition<VcsRef>() {
|
||||
@Override
|
||||
public boolean value(VcsRef ref) {
|
||||
if (ref.getType() == GitRefManager.LOCAL_BRANCH) {
|
||||
@@ -78,7 +79,7 @@ public class GitLogBranchOperationsActionGroup extends ActionGroup implements Du
|
||||
}
|
||||
});
|
||||
|
||||
VcsLogProvider provider = dataPack.getLogProviders().get(root.getRoot());
|
||||
VcsLogProvider provider = logUI.getDataPack().getLogProviders().get(root.getRoot());
|
||||
if (provider != null) {
|
||||
VcsLogRefManager refManager = provider.getReferenceManager();
|
||||
Comparator<VcsRef> comparator = refManager.getLabelsOrderComparator();
|
||||
|
||||
Reference in New Issue
Block a user