Search in sources :

Example 16 with HgFile

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

the class HgDiffProvider method createFileContent.

public ContentRevision createFileContent(VcsRevisionNumber revisionNumber, VirtualFile file) {
    if (file == null) {
        return null;
    }
    VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, file);
    if (vcsRoot == null) {
        return null;
    }
    HgRevisionNumber hgRevisionNumber = (HgRevisionNumber) revisionNumber;
    if (hgRevisionNumber.isWorkingVersion()) {
        throw new IllegalStateException("Should not compare against working copy");
    }
    HgFile hgFile = new HgFile(vcsRoot, HgUtil.getOriginalFileName(VcsUtil.getFilePath(file), ChangeListManager.getInstance(project)));
    return HgContentRevision.create(project, hgFile, hgRevisionNumber);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber)

Example 17 with HgFile

use of org.zmlx.hg4idea.HgFile 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 18 with HgFile

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

the class HgLogCommand method execute.

/**
   * @param limit Pass -1 to set no limits on history
   */
public final List<HgFileRevision> execute(final HgFile hgFile, int limit, boolean includeFiles, @Nullable List<String> argsForCmd) {
    if ((limit <= 0 && limit != -1) || hgFile == null) {
        return Collections.emptyList();
    }
    String[] templates = HgBaseLogParser.constructFullTemplateArgument(includeFiles, myVersion);
    String template = HgChangesetUtil.makeTemplate(templates);
    FilePath originalFileName = HgUtil.getOriginalFileName(hgFile.toFilePath(), ChangeListManager.getInstance(myProject));
    HgFile originalHgFile = new HgFile(hgFile.getRepo(), originalFileName);
    HgCommandResult result = execute(hgFile.getRepo(), template, limit, originalHgFile, argsForCmd);
    return HgHistoryUtil.getCommitRecords(myProject, result, new HgFileRevisionLogParser(myProject, originalHgFile, myVersion));
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgFile(org.zmlx.hg4idea.HgFile) HgFileRevisionLogParser(org.zmlx.hg4idea.log.HgFileRevisionLogParser)

Example 19 with HgFile

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

the class HgResolveCommand method handleResult.

private static Map<HgFile, HgResolveStatusEnum> handleResult(VirtualFile repo, HgCommandResult result) {
    final Map<HgFile, HgResolveStatusEnum> resolveStatus = new HashMap<>();
    for (String line : result.getOutputLines()) {
        if (StringUtil.isEmptyOrSpaces(line) || line.length() < ITEM_COUNT) {
            continue;
        }
        final HgResolveStatusEnum status = HgResolveStatusEnum.valueOf(line.charAt(0));
        if (status != null) {
            File ioFile = new File(repo.getPath(), line.substring(2));
            resolveStatus.put(new HgFile(repo, ioFile), status);
        }
    }
    return resolveStatus;
}
Also used : HgFile(org.zmlx.hg4idea.HgFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) HgFile(org.zmlx.hg4idea.HgFile)

Example 20 with HgFile

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

the class HgAnnotationTest method annotationWithWhitespaceOption.

private void annotationWithWhitespaceOption(boolean ignoreWhitespaces) {
    cd(myRepository);
    String whitespaceFile = "whitespaces.txt";
    touch(whitespaceFile, "not whitespaces");
    myRepository.refresh(false, true);
    String whiteSpaceAuthor = "Mr.Whitespace";
    final VirtualFile file = myRepository.findFileByRelativePath(whitespaceFile);
    assert file != null;
    hg("add " + whitespaceFile);
    hg("commit -m modify -u '" + defaultAuthor + "'");
    //add several whitespaces
    echo(whitespaceFile, "    ");
    hg("commit -m whitespaces -u '" + whiteSpaceAuthor + "'");
    final HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(file));
    myVcs.getProjectSettings().setIgnoreWhitespacesInAnnotations(ignoreWhitespaces);
    List<HgAnnotationLine> annotationLines = new HgAnnotateCommand(myProject).execute(hgFile, null);
    HgAnnotationLine line = annotationLines.get(0);
    assertEquals(ignoreWhitespaces ? defaultAuthor : whiteSpaceAuthor, line.get(HgAnnotation.FIELD.USER));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand)

Aggregations

HgFile (org.zmlx.hg4idea.HgFile)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)9 File (java.io.File)8 HgLogCommand (org.zmlx.hg4idea.command.HgLogCommand)8 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)5 FilePath (com.intellij.openapi.vcs.FilePath)4 NotNull (org.jetbrains.annotations.NotNull)4 HgAnnotateCommand (org.zmlx.hg4idea.command.HgAnnotateCommand)4 VcsException (com.intellij.openapi.vcs.VcsException)3 ArrayList (java.util.ArrayList)3 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)3 HgRepository (org.zmlx.hg4idea.repo.HgRepository)3 Change (com.intellij.openapi.vcs.changes.Change)2 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)2 HgResolveCommand (org.zmlx.hg4idea.command.HgResolveCommand)2 HgResolveStatusEnum (org.zmlx.hg4idea.command.HgResolveStatusEnum)2 HgWorkingCopyRevisionsCommand (org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)2 HgFileRevisionLogParser (org.zmlx.hg4idea.log.HgFileRevisionLogParser)2 HgAnnotationLine (org.zmlx.hg4idea.provider.annotate.HgAnnotationLine)2