public RefsModel(
      @NotNull Map<VirtualFile, CompressedRefs> refs,
      @NotNull Set<Integer> heads,
      @NotNull VcsLogStorage hashMap,
      @NotNull Map<VirtualFile, VcsLogProvider> providers) {
    myRefs = refs;
    myHashMap = hashMap;

    myBestRefForHead = new TIntObjectHashMap<>();
    myRootForHead = new TIntObjectHashMap<>();
    for (int head : heads) {
      CommitId commitId = myHashMap.getCommitId(head);
      if (commitId != null) {
        VirtualFile root = commitId.getRoot();
        myRootForHead.put(head, root);
        Optional<VcsRef> bestRef =
            myRefs
                .get(root)
                .refsToCommit(head)
                .stream()
                .min(providers.get(root).getReferenceManager().getBranchLayoutComparator());
        if (bestRef.isPresent()) {
          myBestRefForHead.put(head, bestRef.get());
        } else {
          LOG.warn("No references at head " + commitId);
        }
      }
    }
  }
 @Override
 @NotNull
 public Collection<VcsRef> getBranches() {
   return myRefs
       .values()
       .stream()
       .flatMap(CompressedRefs::streamBranches)
       .collect(Collectors.toList());
 }
 @NotNull
 public Stream<VcsRef> stream() {
   assert !ApplicationManager.getApplication().isDispatchThread();
   return myRefs.values().stream().flatMap(CompressedRefs::stream);
 }
 public Collection<VcsRef> refsToCommit(int index) {
   CommitId id = myHashMap.getCommitId(index);
   if (id == null) return Collections.emptyList();
   VirtualFile root = id.getRoot();
   return myRefs.get(root).refsToCommit(index);
 }