Search in sources :

Example 1 with SingletonRefGroup

use of com.intellij.vcs.log.impl.SingletonRefGroup in project intellij-community by JetBrains.

the class GitRefManager method groupForBranchFilter.

@NotNull
@Override
public List<RefGroup> groupForBranchFilter(@NotNull Collection<VcsRef> refs) {
    List<RefGroup> simpleGroups = ContainerUtil.newArrayList();
    List<VcsRef> localBranches = ContainerUtil.newArrayList();
    List<VcsRef> trackedBranches = ContainerUtil.newArrayList();
    MultiMap<GitRemote, VcsRef> remoteRefGroups = MultiMap.create();
    MultiMap<VirtualFile, VcsRef> refsByRoot = groupRefsByRoot(refs);
    for (Map.Entry<VirtualFile, Collection<VcsRef>> entry : refsByRoot.entrySet()) {
        VirtualFile root = entry.getKey();
        List<VcsRef> refsInRoot = ContainerUtil.sorted(entry.getValue(), myLabelsComparator);
        GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
        if (repository == null) {
            LOG.warn("No repository for root: " + root);
            continue;
        }
        Set<String> locals = getLocalBranches(repository);
        Set<String> tracked = getTrackedRemoteBranches(repository);
        Map<String, GitRemote> allRemote = getAllRemoteBranches(repository);
        for (VcsRef ref : refsInRoot) {
            if (ref.getType() == HEAD) {
                simpleGroups.add(new SingletonRefGroup(ref));
                continue;
            }
            String refName = ref.getName();
            if (locals.contains(refName)) {
                localBranches.add(ref);
            } else if (allRemote.containsKey(refName)) {
                remoteRefGroups.putValue(allRemote.get(refName), ref);
                if (tracked.contains(refName)) {
                    trackedBranches.add(ref);
                }
            } else {
                LOG.debug("Didn't find ref neither in local nor in remote branches: " + ref);
            }
        }
    }
    List<RefGroup> result = ContainerUtil.newArrayList();
    result.addAll(simpleGroups);
    if (!localBranches.isEmpty())
        result.add(new LogicalRefGroup("Local", localBranches));
    if (!trackedBranches.isEmpty())
        result.add(new LogicalRefGroup("Tracked", trackedBranches));
    for (Map.Entry<GitRemote, Collection<VcsRef>> entry : remoteRefGroups.entrySet()) {
        final GitRemote remote = entry.getKey();
        final Collection<VcsRef> branches = entry.getValue();
        result.add(new RemoteRefGroup(remote, branches));
    }
    return result;
}
Also used : GitRemote(git4idea.repo.GitRemote) VirtualFile(com.intellij.openapi.vfs.VirtualFile) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) SingletonRefGroup(com.intellij.vcs.log.impl.SingletonRefGroup) GitRepository(git4idea.repo.GitRepository) MultiMap(com.intellij.util.containers.MultiMap) SingletonRefGroup(com.intellij.vcs.log.impl.SingletonRefGroup) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MultiMap (com.intellij.util.containers.MultiMap)1 SimpleRefGroup (com.intellij.vcs.log.impl.SimpleRefGroup)1 SingletonRefGroup (com.intellij.vcs.log.impl.SingletonRefGroup)1 GitRemote (git4idea.repo.GitRemote)1 GitRepository (git4idea.repo.GitRepository)1 NotNull (org.jetbrains.annotations.NotNull)1