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;
}
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;
}
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;
}
Aggregations