mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] get rid of VcsLogUtil.collectFirstPackOfLoadedSelectedDetails() call from cherry pick action
This commit is contained in:
@@ -17,12 +17,16 @@ package com.intellij.dvcs.cherrypick;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.vcs.VcsKey;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.VcsLog;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class VcsCherryPicker {
|
||||
|
||||
@@ -52,8 +56,8 @@ public abstract class VcsCherryPicker {
|
||||
* Return true if all selected commits can be cherry-picked by this cherry-picker
|
||||
*
|
||||
* @param log additional log information
|
||||
* @param details commits to cherry-pick
|
||||
* @param commits commits to cherry-pick, grouped by version control root
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean isEnabled(@NotNull VcsLog log, @NotNull List<VcsFullCommitDetails> details);
|
||||
public abstract boolean isEnabled(@NotNull VcsLog log, @NotNull Map<VirtualFile, List<Hash>> commits);
|
||||
}
|
||||
|
||||
@@ -33,13 +33,11 @@ import com.intellij.openapi.vcs.VcsKey;
|
||||
import com.intellij.openapi.vcs.VcsNotifier;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManagerEx;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.VcsLog;
|
||||
import com.intellij.vcs.log.VcsLogDataKeys;
|
||||
import com.intellij.vcs.log.*;
|
||||
import com.intellij.vcs.log.impl.VcsLogUtil;
|
||||
import icons.DvcsImplIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -102,12 +100,13 @@ public class VcsCherryPickAction extends DumbAwareAction {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<VcsFullCommitDetails> details = VcsLogUtil.collectFirstPackOfLoadedSelectedDetails(log);
|
||||
List<CommitId> details = VcsLogUtil.collectFirstPack(log.getSelectedCommits(), VcsLogUtil.COMMITS_LIMIT);
|
||||
final Map<VirtualFile, List<Hash>> groupedByRoot = groupByRoot(details);
|
||||
VcsCherryPicker enabledCherryPicker = ContainerUtil.find(cherryPickers, new Condition<VcsCherryPicker>() {
|
||||
@Override
|
||||
public boolean value(VcsCherryPicker picker) {
|
||||
//all commits should be from one vcs, if not then all pickers should return false
|
||||
return picker.isEnabled(log, details);
|
||||
return picker.isEnabled(log, groupedByRoot);
|
||||
}
|
||||
});
|
||||
e.getPresentation().setEnabled(enabledCherryPicker != null);
|
||||
@@ -115,6 +114,20 @@ public class VcsCherryPickAction extends DumbAwareAction {
|
||||
enabledCherryPicker == null ? concatActionNamesForAllAvailable(cherryPickers) : enabledCherryPicker.getActionTitle());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Map<VirtualFile, List<Hash>> groupByRoot(@NotNull List<CommitId> details) {
|
||||
Map<VirtualFile, List<Hash>> result = ContainerUtil.newHashMap();
|
||||
for (CommitId commit: details) {
|
||||
List<Hash> hashes = result.get(commit.getRoot());
|
||||
if (hashes == null) {
|
||||
hashes = ContainerUtil.newArrayList();
|
||||
result.put(commit.getRoot(), hashes);
|
||||
}
|
||||
hashes.add(commit.getHash());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String concatActionNamesForAllAvailable(@NotNull final List<VcsCherryPicker> pickers) {
|
||||
return StringUtil.join(pickers, new Function<VcsCherryPicker, String>() {
|
||||
|
||||
@@ -106,7 +106,7 @@ public abstract class VcsLogAction<Repo extends Repository> extends DumbAwareAct
|
||||
@Nullable
|
||||
private MultiMap<Repo, Hash> groupFirstPackOfCommits(@NotNull Project project, @NotNull VcsLog log) {
|
||||
MultiMap<Repo, CommitId> commitIds =
|
||||
groupCommits(project, VcsLogUtil.collectFirstPack(log.getSelectedCommits(), VcsLogUtil.DETAILS_LIMIT),
|
||||
groupCommits(project, VcsLogUtil.collectFirstPack(log.getSelectedCommits(), VcsLogUtil.COMMITS_LIMIT),
|
||||
new Function<CommitId, VirtualFile>() {
|
||||
@Override
|
||||
public VirtualFile fun(CommitId hash) {
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class VcsLogUtil {
|
||||
public static final int DETAILS_LIMIT = 100;
|
||||
public static final int COMMITS_LIMIT = 100;
|
||||
|
||||
@NotNull
|
||||
public static MultiMap<VirtualFile, VcsRef> groupRefsByRoot(@NotNull Collection<VcsRef> refs) {
|
||||
@@ -181,7 +181,7 @@ public class VcsLogUtil {
|
||||
}
|
||||
else {
|
||||
result.add(next);
|
||||
if (result.size() >= DETAILS_LIMIT) break;
|
||||
if (result.size() >= COMMITS_LIMIT) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.VcsLog;
|
||||
import git4idea.GitLocalBranch;
|
||||
@@ -546,20 +548,23 @@ public class GitCherryPicker extends VcsCherryPicker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(@NotNull VcsLog log, @NotNull List<VcsFullCommitDetails> details) {
|
||||
if (details.isEmpty()) {
|
||||
public boolean isEnabled(@NotNull VcsLog log, @NotNull Map<VirtualFile, List<Hash>> commits) {
|
||||
if (commits.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (VcsFullCommitDetails commit : details) {
|
||||
GitRepository repository = myPlatformFacade.getRepositoryManager(myProject).getRepositoryForRoot(commit.getRoot());
|
||||
|
||||
for (VirtualFile root : commits.keySet()) {
|
||||
GitRepository repository = myPlatformFacade.getRepositoryManager(myProject).getRepositoryForRoot(root);
|
||||
if (repository == null) {
|
||||
return false;
|
||||
}
|
||||
GitLocalBranch currentBranch = repository.getCurrentBranch();
|
||||
Collection<String> containingBranches = log.getContainingBranches(commit.getId());
|
||||
if (currentBranch != null && containingBranches != null && containingBranches.contains(currentBranch.getName())) {
|
||||
// already is contained in the current branch
|
||||
return false;
|
||||
for (Hash commit : commits.get(root)) {
|
||||
GitLocalBranch currentBranch = repository.getCurrentBranch();
|
||||
Collection<String> containingBranches = log.getContainingBranches(commit);
|
||||
if (currentBranch != null && containingBranches != null && containingBranches.contains(currentBranch.getName())) {
|
||||
// already is contained in the current branch
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.intellij.openapi.vcs.update.UpdatedFiles;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.VcsLog;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -103,17 +105,18 @@ public class HgCherryPicker extends VcsCherryPicker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(@NotNull VcsLog log, @NotNull List<VcsFullCommitDetails> details) {
|
||||
if (details.isEmpty()) {
|
||||
public boolean isEnabled(@NotNull VcsLog log, @NotNull Map<VirtualFile, List<Hash>> commits) {
|
||||
if (commits.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (VcsFullCommitDetails commit : details) {
|
||||
HgRepository repository = HgUtil.getRepositoryManager(myProject).getRepositoryForRoot(commit.getRoot());
|
||||
for (VirtualFile root: commits.keySet()) {
|
||||
HgRepository repository = HgUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
|
||||
if (repository == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user