mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-135768 Show remote branches in creating task dialog
This commit is contained in:
@@ -29,13 +29,11 @@ import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class DvcsTaskHandler<R extends Repository> extends VcsTaskHandler {
|
||||
|
||||
@@ -153,16 +151,22 @@ public abstract class DvcsTaskHandler<R extends Repository> extends VcsTaskHandl
|
||||
@Override
|
||||
public TaskInfo[] getAllExistingTasks() {
|
||||
List<R> repositories = myRepositoryManager.getRepositories();
|
||||
MultiMap<String, String> tasks = new MultiMap<String, String>();
|
||||
MultiMap<String, TaskInfo> tasks = new MultiMap<String, TaskInfo>();
|
||||
for (R repository : repositories) {
|
||||
for (String branch : getAllBranches(repository)) {
|
||||
tasks.putValue(branch, repository.getPresentableUrl());
|
||||
for (TaskInfo branch : getAllBranches(repository)) {
|
||||
tasks.putValue(branch.getName(), branch);
|
||||
}
|
||||
}
|
||||
return ContainerUtil.map2Array(tasks.entrySet(), TaskInfo.class, new Function<Map.Entry<String, Collection<String>>, TaskInfo>() {
|
||||
return ContainerUtil.map2Array(tasks.entrySet(), TaskInfo.class, new Function<Map.Entry<String, Collection<TaskInfo>>, TaskInfo>() {
|
||||
@Override
|
||||
public TaskInfo fun(Map.Entry<String, Collection<String>> entry) {
|
||||
return new TaskInfo(entry.getKey(), entry.getValue());
|
||||
public TaskInfo fun(Map.Entry<String, Collection<TaskInfo>> entry) {
|
||||
Set<String> repositories = new HashSet<String>();
|
||||
boolean remote = false;
|
||||
for (TaskInfo info : entry.getValue()) {
|
||||
remote |= info.isRemote();
|
||||
repositories.addAll(info.getRepositories());
|
||||
}
|
||||
return new TaskInfo(entry.getKey(), repositories, remote);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -193,7 +197,7 @@ public abstract class DvcsTaskHandler<R extends Repository> extends VcsTaskHandl
|
||||
protected abstract String getActiveBranch(R repository);
|
||||
|
||||
@NotNull
|
||||
protected abstract Iterable<String> getAllBranches(@NotNull R repository);
|
||||
protected abstract Iterable<TaskInfo> getAllBranches(@NotNull R repository);
|
||||
|
||||
protected abstract void mergeAndClose(@NotNull String branch, @NotNull List<R> repositories);
|
||||
|
||||
|
||||
@@ -44,16 +44,24 @@ public abstract class VcsTaskHandler {
|
||||
|
||||
private final String myBranch;
|
||||
private final Collection<String> myRepositories;
|
||||
private final boolean myRemote;
|
||||
|
||||
public TaskInfo(String branch, Collection<String> repositories) {
|
||||
this(branch, repositories, false);
|
||||
}
|
||||
|
||||
public TaskInfo(String branch, Collection<String> repositories, boolean remote) {
|
||||
myBranch = branch;
|
||||
myRepositories = repositories;
|
||||
myRemote = remote;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myBranch;
|
||||
}
|
||||
|
||||
public boolean isRemote() { return myRemote; }
|
||||
|
||||
public Collection<String> getRepositories() {
|
||||
return myRepositories;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import git4idea.validators.GitRefNameValidator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -71,13 +71,25 @@ public class GitTaskHandler extends DvcsTaskHandler<GitRepository> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Collection<String> getAllBranches(@NotNull GitRepository repository) {
|
||||
return ContainerUtil.map(repository.getBranches().getLocalBranches(), new Function<GitLocalBranch, String>() {
|
||||
protected Iterable<TaskInfo> getAllBranches(@NotNull GitRepository repository) {
|
||||
List<TaskInfo> list = ContainerUtil.map(repository.getBranches().getLocalBranches(), new Function<GitBranch, TaskInfo>() {
|
||||
@Override
|
||||
public String fun(GitLocalBranch branch) {
|
||||
return branch.getName();
|
||||
public TaskInfo fun(GitBranch branch) {
|
||||
return new TaskInfo(branch.getName(), Collections.singleton(repository.getPresentableUrl()));
|
||||
}
|
||||
});
|
||||
list.addAll(ContainerUtil.map(repository.getBranches().getLocalBranches(), new Function<GitBranch, TaskInfo>() {
|
||||
@Override
|
||||
public TaskInfo fun(GitBranch branch) {
|
||||
return new TaskInfo(branch.getName(), Collections.singleton(repository.getPresentableUrl())) {
|
||||
@Override
|
||||
public boolean isRemote() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.VcsNotifier;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -37,6 +38,7 @@ import org.zmlx.hg4idea.util.HgErrorUtil;
|
||||
import org.zmlx.hg4idea.util.HgReferenceValidator;
|
||||
import org.zmlx.hg4idea.util.HgUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HgTaskHandler extends DvcsTaskHandler<HgRepository> {
|
||||
@@ -69,9 +71,16 @@ public class HgTaskHandler extends DvcsTaskHandler<HgRepository> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Iterable<String> getAllBranches(@NotNull HgRepository repository) {
|
||||
protected Iterable<TaskInfo> getAllBranches(@NotNull HgRepository repository) {
|
||||
//be careful with equality names of branches/bookmarks =(
|
||||
return ContainerUtil.concat(HgUtil.getSortedNamesWithoutHashes(repository.getBookmarks()), repository.getOpenedBranches());
|
||||
Iterable<String> names =
|
||||
ContainerUtil.concat(HgUtil.getSortedNamesWithoutHashes(repository.getBookmarks()), repository.getOpenedBranches());
|
||||
return ContainerUtil.map(names, new Function<String, TaskInfo>() {
|
||||
@Override
|
||||
public TaskInfo fun(String s) {
|
||||
return new TaskInfo(s, Collections.singleton(repository.getPresentableUrl()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="e6ce7"/>
|
||||
<labelFor value="60274"/>
|
||||
<text value="&from"/>
|
||||
</properties>
|
||||
</component>
|
||||
|
||||
@@ -159,13 +159,13 @@ public class VcsOpenTaskPanel extends TaskDialogPanel {
|
||||
myTaskManager.createChangeList(localTask, myChangelistName.getText());
|
||||
}
|
||||
if (myCreateBranch.isSelected()) {
|
||||
VcsTaskHandler.TaskInfo item = (VcsTaskHandler.TaskInfo)myBranchFrom.getSelectedItem();
|
||||
Runnable createBranch = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myTaskManager.createBranch(localTask, myPreviousTask, myBranchName.getText());
|
||||
}
|
||||
};
|
||||
VcsTaskHandler.TaskInfo item = (VcsTaskHandler.TaskInfo)myBranchFrom.getSelectedItem();
|
||||
if (item != null) {
|
||||
myVcsTaskHandler.switchToTask(item, createBranch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user