public static @NotNull @Nls String getBranchesLinkText(@Nullable List<@NlsSafe String> branches,
                                                         boolean expanded,
                                                         int availableWidth,
                                                         @NotNull FontMetrics metrics) {
    if (branches == null) {
      return VcsLogBundle.message("vcs.log.details.in.branches.loading");
    }
    if (branches.isEmpty()) return VcsLogBundle.message("vcs.log.details.in.branches.empty");

    String head = VcsLogBundle.message("vcs.log.details.in.branches", branches.size()) + " ";

    if (expanded) {
      return new HtmlBuilder().append(head)
        .append(HtmlChunk.link(SHOW_HIDE_BRANCHES, VcsLogBundle.message("vcs.log.details.in.branches.hide")))
        .toString();
    }

    String tail = "… " + HtmlChunk.link(SHOW_HIDE_BRANCHES, VcsLogBundle.message("vcs.log.details.in.branches.show.all"));
    int headAndTailWidth = metrics.stringWidth(head) + metrics.stringWidth(StringUtil.removeHtmlTags(tail));
    if (availableWidth <= headAndTailWidth) {
      return head + tail;
    }
    availableWidth -= headAndTailWidth;

    StringBuilder branchesText = new StringBuilder();
    for (int i = 0; i < branches.size(); i++) {
      String branch = branches.get(i) + (i != branches.size() - 1 ? ", " : "");
      int branchWidth = metrics.stringWidth(branch);
      if (branchWidth < availableWidth) {
        branchesText.append(branch);
        availableWidth -= branchWidth;
      }
      else {
        StringBuilder shortenedBranch = new StringBuilder();
        for (char c : branch.toCharArray()) {
          if (metrics.stringWidth(shortenedBranch.toString() + c) >= availableWidth) {
            break;
          }
          shortenedBranch.append(c);
        }
        branchesText.append(shortenedBranch);
        branchesText.append(tail);
        break;
      }
    }

    return head + branchesText;
  }


public static @NotNull @Nls String getBranchesLinkText(@Nullable List<@NlsSafe String> branches,
                                                         boolean expanded,
                                                         int availableWidth,
                                                         @NotNull FontMetrics metrics)