@NotNull
  public static List<VcsCommitMetadata> loadMetadata(
      @NotNull final Project project,
      @NotNull final VirtualFile root,
      int limit,
      @NotNull List<String> parameters)
      throws VcsException {

    final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
    if (factory == null) {
      return Collections.emptyList();
    }
    HgVcs hgvcs = HgVcs.getInstance(project);
    assert hgvcs != null;
    HgVersion version = hgvcs.getVersion();
    List<String> templateList = HgBaseLogParser.constructDefaultTemplate(version);
    templateList.add("{desc}");
    String[] templates = ArrayUtil.toStringArray(templateList);
    HgCommandResult result =
        getLogResult(
            project, root, version, limit, parameters, HgChangesetUtil.makeTemplate(templates));
    HgBaseLogParser<VcsCommitMetadata> baseParser =
        new HgBaseLogParser<VcsCommitMetadata>() {

          @Override
          protected VcsCommitMetadata convertDetails(
              @NotNull String rev,
              @NotNull String changeset,
              @NotNull SmartList<HgRevisionNumber> parents,
              @NotNull Date revisionDate,
              @NotNull String author,
              @NotNull String email,
              @NotNull List<String> attributes) {
            String message = parseAdditionalStringAttribute(attributes, MESSAGE_INDEX);
            int subjectIndex = message.indexOf('\n');
            String subject = subjectIndex == -1 ? message : message.substring(0, subjectIndex);
            List<Hash> parentsHash = new SmartList<Hash>();
            for (HgRevisionNumber parent : parents) {
              parentsHash.add(factory.createHash(parent.getChangeset()));
            }
            return factory.createCommitMetadata(
                factory.createHash(changeset),
                parentsHash,
                revisionDate.getTime(),
                root,
                subject,
                author,
                email,
                message,
                author,
                email,
                revisionDate.getTime());
          }
        };
    return getCommitRecords(project, result, baseParser);
  }
 /**
  * Get & parse hg log detailed output with commits, their parents and their changes. For null
  * destination return log command result
  *
  * <p>
  *
  * <p>Warning: this is method is efficient by speed, but don't query too much, because the whole
  * log output is retrieved at once, and it can occupy too much memory. The estimate is ~600Kb for
  * 1000 commits.
  */
 @NotNull
 public static List<? extends VcsFullCommitDetails> history(
     @NotNull final Project project,
     @NotNull final VirtualFile root,
     int limit,
     @NotNull List<String> parameters)
     throws VcsException {
   HgVcs hgvcs = HgVcs.getInstance(project);
   assert hgvcs != null;
   final HgVersion version = hgvcs.getVersion();
   String[] templates = HgBaseLogParser.constructFullTemplateArgument(true, version);
   HgCommandResult result =
       getLogResult(
           project, root, version, limit, parameters, HgChangesetUtil.makeTemplate(templates));
   return createFullCommitsFromResult(project, root, result, version, false);
 }
  @NotNull
  public static List<TimedVcsCommit> readAllHashes(
      @NotNull Project project,
      @NotNull VirtualFile root,
      @NotNull final Consumer<VcsUser> userRegistry,
      @NotNull List<String> params)
      throws VcsException {

    final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
    if (factory == null) {
      return Collections.emptyList();
    }
    HgVcs hgvcs = HgVcs.getInstance(project);
    assert hgvcs != null;
    HgVersion version = hgvcs.getVersion();
    String[] templates = ArrayUtil.toStringArray(HgBaseLogParser.constructDefaultTemplate(version));
    HgCommandResult result =
        getLogResult(project, root, version, -1, params, HgChangesetUtil.makeTemplate(templates));
    return getCommitRecords(
        project,
        result,
        new HgBaseLogParser<TimedVcsCommit>() {

          @Override
          protected TimedVcsCommit convertDetails(
              @NotNull String rev,
              @NotNull String changeset,
              @NotNull SmartList<HgRevisionNumber> parents,
              @NotNull Date revisionDate,
              @NotNull String author,
              @NotNull String email,
              @NotNull List<String> attributes) {
            List<Hash> parentsHash = new SmartList<Hash>();
            for (HgRevisionNumber parent : parents) {
              parentsHash.add(factory.createHash(parent.getChangeset()));
            }
            userRegistry.consume(factory.createUser(author, email));
            return factory.createTimedCommit(
                factory.createHash(changeset), parentsHash, revisionDate.getTime());
          }
        });
  }
 @NotNull
 public static Collection<String> getDescendingHeadsOfBranches(
     @NotNull Project project, @NotNull VirtualFile root, @NotNull Hash hash) throws VcsException {
   // hg log -r "descendants(659db54c1b6865c97c4497fa867194bcd759ca76) and head()" --template
   // "{branch}{bookmarks}"
   Set<String> branchHeads = new HashSet<String>();
   List<String> params = new ArrayList<String>();
   params.add("-r");
   params.add("descendants(" + hash.asString() + ") and head()");
   HgLogCommand hgLogCommand = new HgLogCommand(project);
   hgLogCommand.setLogFile(false);
   String template = HgChangesetUtil.makeTemplate("{branch}", "{bookmarks}");
   HgCommandResult logResult = hgLogCommand.execute(root, template, -1, null, params);
   if (logResult == null || logResult.getExitValue() != 0) {
     throw new VcsException("Couldn't get commit details: log command execution error.");
   }
   String output = logResult.getRawOutput();
   List<String> changeSets = StringUtil.split(output, HgChangesetUtil.CHANGESET_SEPARATOR);
   for (String line : changeSets) {
     List<String> attributes = StringUtil.split(line, HgChangesetUtil.ITEM_SEPARATOR);
     branchHeads.addAll(attributes);
   }
   return branchHeads;
 }