Search in sources :

Example 1 with SimpleRefGroup

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

the class GitRefManager method groupForTable.

@NotNull
@Override
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references, boolean compact, boolean showTagNames) {
    List<VcsRef> sortedReferences = ContainerUtil.sorted(references, myLabelsComparator);
    MultiMap<VcsRefType, VcsRef> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType);
    List<RefGroup> result = ContainerUtil.newArrayList();
    if (groupedRefs.isEmpty())
        return result;
    VcsRef head = null;
    Map.Entry<VcsRefType, Collection<VcsRef>> firstGroup = ObjectUtils.notNull(ContainerUtil.getFirstItem(groupedRefs.entrySet()));
    if (firstGroup.getKey().equals(HEAD)) {
        head = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(firstGroup.getValue()));
        groupedRefs.remove(HEAD, head);
    }
    GitRepository repository = getRepository(references);
    if (repository != null) {
        result.addAll(getTrackedRefs(groupedRefs, repository));
    }
    result.forEach(refGroup -> {
        groupedRefs.remove(LOCAL_BRANCH, refGroup.getRefs().get(0));
        groupedRefs.remove(REMOTE_BRANCH, refGroup.getRefs().get(1));
    });
    SimpleRefGroup.buildGroups(groupedRefs, compact, showTagNames, result);
    if (head != null) {
        if (repository != null && !repository.isOnBranch()) {
            result.add(0, new SimpleRefGroup("!", Collections.singletonList(head)));
        } else {
            if (!result.isEmpty()) {
                RefGroup first = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(result));
                first.getRefs().add(0, head);
            } else {
                result.add(0, new SimpleRefGroup("", Collections.singletonList(head)));
            }
        }
    }
    return result;
}
Also used : GitRepository(git4idea.repo.GitRepository) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) MultiMap(com.intellij.util.containers.MultiMap) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) SingletonRefGroup(com.intellij.vcs.log.impl.SingletonRefGroup) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SimpleRefGroup

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

the class GitRefManager method getTrackedRefs.

@NotNull
private static List<RefGroup> getTrackedRefs(@NotNull MultiMap<VcsRefType, VcsRef> groupedRefs, @NotNull GitRepository repository) {
    List<RefGroup> result = ContainerUtil.newArrayList();
    Collection<VcsRef> locals = groupedRefs.get(LOCAL_BRANCH);
    Collection<VcsRef> remotes = groupedRefs.get(REMOTE_BRANCH);
    for (VcsRef localRef : locals) {
        SimpleRefGroup group = createTrackedGroup(repository, remotes, localRef);
        if (group != null) {
            result.add(group);
        }
    }
    return result;
}
Also used : SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) SingletonRefGroup(com.intellij.vcs.log.impl.SingletonRefGroup) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SimpleRefGroup

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

the class GitRefManager method createTrackedGroup.

@Nullable
private static SimpleRefGroup createTrackedGroup(@NotNull GitRepository repository, @NotNull Collection<VcsRef> references, @NotNull VcsRef localRef) {
    List<VcsRef> remoteBranches = ContainerUtil.filter(references, ref -> ref.getType().equals(REMOTE_BRANCH));
    GitBranchTrackInfo trackInfo = ContainerUtil.find(repository.getBranchTrackInfos(), info -> info.getLocalBranch().getName().equals(localRef.getName()));
    if (trackInfo != null) {
        VcsRef trackedRef = ContainerUtil.find(remoteBranches, ref -> ref.getName().equals(trackInfo.getRemoteBranch().getName()));
        if (trackedRef != null) {
            return new SimpleRefGroup(trackInfo.getRemote().getName() + REMOTE_TABLE_SEPARATOR + localRef.getName(), ContainerUtil.newArrayList(localRef, trackedRef));
        }
    }
    List<VcsRef> trackingCandidates = ContainerUtil.filter(remoteBranches, ref -> ref.getName().endsWith(SEPARATOR + localRef.getName()));
    for (GitRemote remote : repository.getRemotes()) {
        for (VcsRef candidate : trackingCandidates) {
            if (candidate.getName().equals(remote.getName() + SEPARATOR + localRef.getName())) {
                return new SimpleRefGroup(remote.getName() + REMOTE_TABLE_SEPARATOR + localRef.getName(), ContainerUtil.newArrayList(localRef, candidate));
            }
        }
    }
    return null;
}
Also used : GitRemote(git4idea.repo.GitRemote) GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SimpleRefGroup (com.intellij.vcs.log.impl.SimpleRefGroup)3 SingletonRefGroup (com.intellij.vcs.log.impl.SingletonRefGroup)2 NotNull (org.jetbrains.annotations.NotNull)2 MultiMap (com.intellij.util.containers.MultiMap)1 GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)1 GitRemote (git4idea.repo.GitRemote)1 GitRepository (git4idea.repo.GitRepository)1 Nullable (org.jetbrains.annotations.Nullable)1