List<RefGroup> (@NotNull Collection<? extends VcsRef> references, boolean compact, boolean showTagNames) { List<VcsRef> sortedReferences = sort(references); List<VcsRef> headAndTip = new ArrayList<>(); MultiMap<VcsRefType, VcsRef> groupedRefs = MultiMap.createLinked(); for (VcsRef ref : sortedReferences) { if (ref.getType().equals(HEAD) || ref.getType().equals(TIP)) { headAndTip.add(ref); } else { groupedRefs.putValue(ref.getType(), ref); } } List<RefGroup> refGroups = SimpleRefGroup.buildGroups(emptyList(), groupedRefs, compact, showTagNames); if (headAndTip.isEmpty()) return refGroups; RefGroup firstGroup = getFirstItem(refGroups); if (firstGroup != null) { firstGroup.getRefs().addAll(0, headAndTip); return refGroups; } List<RefGroup> result = new ArrayList<>(); result.add(new SimpleRefGroup("", headAndTip)); result.addAll(refGroups); return result; }