Search in sources :

Example 11 with HgLogCommand

use of org.zmlx.hg4idea.command.HgLogCommand in project intellij-community by JetBrains.

the class HgCachingCommittedChangesProvider method getCommittedChangesForRevision.

@Nullable
public CommittedChangeList getCommittedChangesForRevision(@Nullable RepositoryLocation repositoryLocation, String revision) {
    if (repositoryLocation == null) {
        return null;
    }
    VirtualFile root = ((HgRepositoryLocation) repositoryLocation).getRoot();
    HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
    HgLogCommand hgLogCommand = new HgLogCommand(project);
    hgLogCommand.setLogFile(false);
    hgLogCommand.setFollowCopies(true);
    List<String> args = new ArrayList<>();
    args.add("--rev");
    args.add(revision);
    final List<HgFileRevision> revisions;
    revisions = hgLogCommand.execute(hgFile, 1, true, args);
    if (ContainerUtil.isEmpty(revisions)) {
        return null;
    }
    HgFileRevision localRevision = revisions.get(0);
    HgRevisionNumber vcsRevisionNumber = localRevision.getRevisionNumber();
    List<HgRevisionNumber> parents = vcsRevisionNumber.getParents();
    // can have no parents if it is a root
    HgRevisionNumber firstParent = parents.isEmpty() ? null : parents.get(0);
    List<Change> changes = new ArrayList<>();
    for (String file : localRevision.getModifiedFiles()) {
        changes.add(createChange(root, file, firstParent, file, vcsRevisionNumber, FileStatus.MODIFIED));
    }
    for (String file : localRevision.getAddedFiles()) {
        changes.add(createChange(root, null, null, file, vcsRevisionNumber, FileStatus.ADDED));
    }
    for (String file : localRevision.getDeletedFiles()) {
        changes.add(createChange(root, file, firstParent, null, vcsRevisionNumber, FileStatus.DELETED));
    }
    for (Map.Entry<String, String> copiedFile : localRevision.getMovedFiles().entrySet()) {
        changes.add(createChange(root, copiedFile.getKey(), firstParent, copiedFile.getValue(), vcsRevisionNumber, HgChangeProvider.RENAMED));
    }
    return new HgCommittedChangeList(myVcs, vcsRevisionNumber, localRevision.getBranchName(), localRevision.getCommitMessage(), localRevision.getAuthor(), localRevision.getRevisionDate(), changes);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Change(com.intellij.openapi.vcs.changes.Change) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with HgLogCommand

use of org.zmlx.hg4idea.command.HgLogCommand in project intellij-community by JetBrains.

the class HgHistoryProvider method getHistoryForUncommittedRenamed.

/**
   * Workaround for getting follow file history in case of uncommitted move/rename change
   */
private static List<HgFileRevision> getHistoryForUncommittedRenamed(@NotNull FilePath originalHgFilePath, @NotNull VirtualFile vcsRoot, @NotNull Project project, int limit) {
    HgFile originalHgFile = new HgFile(vcsRoot, originalHgFilePath);
    final HgLogCommand logCommand = new HgLogCommand(project);
    logCommand.setIncludeRemoved(true);
    final HgVersion version = logCommand.getVersion();
    String[] templates = HgBaseLogParser.constructFullTemplateArgument(false, version);
    String template = HgChangesetUtil.makeTemplate(templates);
    List<String> argsForCmd = ContainerUtil.newArrayList();
    String relativePath = originalHgFile.getRelativePath();
    argsForCmd.add("--rev");
    argsForCmd.add(String.format("reverse(follow(%s))", relativePath != null ? "'" + FileUtil.toSystemIndependentName(relativePath) + "'" : ""));
    HgCommandResult result = logCommand.execute(vcsRoot, template, limit, relativePath != null ? null : originalHgFile, argsForCmd);
    return HgHistoryUtil.getCommitRecords(project, result, new HgFileRevisionLogParser(project, originalHgFile, version));
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgFile(org.zmlx.hg4idea.HgFile) HgFileRevisionLogParser(org.zmlx.hg4idea.log.HgFileRevisionLogParser) HgVersion(org.zmlx.hg4idea.util.HgVersion) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Example 13 with HgLogCommand

use of org.zmlx.hg4idea.command.HgLogCommand in project intellij-community by JetBrains.

the class HgCommitTest method testAmendCommit.

public void testAmendCommit() throws HgCommandException, VcsException {
    String changedCommit = "anotherCommit";
    HgLogCommand logCommand = new HgLogCommand(myProject);
    logCommand.setLogFile(false);
    HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(myRepository));
    List<HgFileRevision> revisions = logCommand.execute(hgFile, -1, false);
    HgRepository hgRepo = HgRepositoryImpl.getInstance(myRepository, myProject, myProject);
    HgCommitCommand commit = new HgCommitCommand(myProject, hgRepo, changedCommit, true);
    commit.executeInCurrentThread();
    List<HgFileRevision> revisionsAfterAmendCommit = logCommand.execute(hgFile, -1, false);
    assertTrue(revisions.size() == revisionsAfterAmendCommit.size());
    assertEquals(revisionsAfterAmendCommit.get(0).getCommitMessage(), changedCommit);
}
Also used : HgFile(org.zmlx.hg4idea.HgFile) HgCommitCommand(org.zmlx.hg4idea.command.HgCommitCommand) HgFileRevision(org.zmlx.hg4idea.HgFileRevision) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Aggregations

HgLogCommand (org.zmlx.hg4idea.command.HgLogCommand)13 HgFile (org.zmlx.hg4idea.HgFile)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)7 File (java.io.File)3 Change (com.intellij.openapi.vcs.changes.Change)2 Nullable (org.jetbrains.annotations.Nullable)2 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)2 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)2 HgRepository (org.zmlx.hg4idea.repo.HgRepository)2 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.testng.annotations.Test)1 HgFileRevisionLogParser (org.zmlx.hg4idea.log.HgFileRevisionLogParser)1 HgVersion (org.zmlx.hg4idea.util.HgVersion)1