private static String printCommits(List<VcsCommitMetadata> commits) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < Math.min(commits.size(), 100); i++) {
     GraphCommit<Hash> commit = commits.get(i);
     sb.append(
         String.format(
             "%s -> %s\n",
             commit.getId().toShortString(),
             StringUtil.join(
                 commit.getParents(),
                 new Function<Hash, String>() {
                   @Override
                   public String fun(Hash hash) {
                     return hash.toShortString();
                   }
                 },
                 ", ")));
   }
   return sb.toString();
 }
Ejemplo n.º 2
0
  public static List<? extends VcsFullCommitDetails> createFullCommitsFromResult(
      @NotNull Project project,
      @NotNull VirtualFile root,
      @Nullable HgCommandResult result,
      @NotNull HgVersion version,
      boolean silent) {
    final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
    if (factory == null) {
      return Collections.emptyList();
    }
    List<HgFileRevision> hgRevisions =
        getCommitRecords(
            project,
            result,
            new HgFileRevisionLogParser(project, getOriginalHgFile(project, root), version),
            silent);
    List<VcsFullCommitDetails> vcsFullCommitDetailsList = new ArrayList<VcsFullCommitDetails>();
    for (HgFileRevision revision : hgRevisions) {

      HgRevisionNumber vcsRevisionNumber = revision.getRevisionNumber();
      List<HgRevisionNumber> parents = vcsRevisionNumber.getParents();
      HgRevisionNumber firstParent =
          parents.isEmpty() ? null : parents.get(0); // can have no parents if it is a root
      List<Hash> parentsHash = new SmartList<Hash>();
      for (HgRevisionNumber parent : parents) {
        parentsHash.add(factory.createHash(parent.getChangeset()));
      }

      final Collection<Change> changes = new ArrayList<Change>();
      for (String file : revision.getModifiedFiles()) {
        changes.add(
            createChange(
                project, root, file, firstParent, file, vcsRevisionNumber, FileStatus.MODIFIED));
      }
      for (String file : revision.getAddedFiles()) {
        changes.add(
            createChange(project, root, null, null, file, vcsRevisionNumber, FileStatus.ADDED));
      }
      for (String file : revision.getDeletedFiles()) {
        changes.add(
            createChange(
                project, root, file, firstParent, null, vcsRevisionNumber, FileStatus.DELETED));
      }
      for (Map.Entry<String, String> copiedFile : revision.getCopiedFiles().entrySet()) {
        changes.add(
            createChange(
                project,
                root,
                copiedFile.getKey(),
                firstParent,
                copiedFile.getValue(),
                vcsRevisionNumber,
                FileStatus.ADDED));
      }

      vcsFullCommitDetailsList.add(
          factory.createFullDetails(
              factory.createHash(vcsRevisionNumber.getChangeset()),
              parentsHash,
              revision.getRevisionDate().getTime(),
              root,
              vcsRevisionNumber.getSubject(),
              vcsRevisionNumber.getAuthor(),
              vcsRevisionNumber.getEmail(),
              vcsRevisionNumber.getCommitMessage(),
              vcsRevisionNumber.getAuthor(),
              vcsRevisionNumber.getEmail(),
              revision.getRevisionDate().getTime(),
              new ThrowableComputable<Collection<Change>, Exception>() {
                @Override
                public Collection<Change> compute() throws Exception {
                  return changes;
                }
              }));
    }
    return vcsFullCommitDetailsList;
  }