Search in sources :

Example 1 with GitContentRevision

use of git4idea.GitContentRevision in project intellij-community by JetBrains.

the class GitDiffProvider method createFileContent.

/**
   * {@inheritDoc}
   */
@Nullable
public ContentRevision createFileContent(VcsRevisionNumber revisionNumber, VirtualFile selectedFile) {
    if (selectedFile.isDirectory()) {
        return null;
    }
    final String path = selectedFile.getPath();
    if (GitUtil.gitRootOrNull(selectedFile) == null) {
        return null;
    }
    // faster, if there were no renames
    FilePath filePath = VcsUtil.getFilePath(path);
    try {
        final CommittedChangesProvider committedChangesProvider = GitVcs.getInstance(myProject).getCommittedChangesProvider();
        final Pair<CommittedChangeList, FilePath> pair = committedChangesProvider.getOneList(selectedFile, revisionNumber);
        if (pair != null) {
            return GitContentRevision.createRevision(pair.getSecond(), revisionNumber, myProject, selectedFile.getCharset());
        }
    } catch (VcsException e) {
        GitVcs.getInstance(myProject).showErrors(Collections.singletonList(e), GitBundle.message("diff.find.error", path));
    }
    try {
        for (VcsFileRevision f : GitHistoryUtils.history(myProject, filePath)) {
            GitFileRevision gitRevision = (GitFileRevision) f;
            if (f.getRevisionNumber().equals(revisionNumber)) {
                return GitContentRevision.createRevision(gitRevision.getPath(), revisionNumber, myProject, selectedFile.getCharset());
            }
        }
        GitContentRevision candidate = (GitContentRevision) GitContentRevision.createRevision(filePath, revisionNumber, myProject, selectedFile.getCharset());
        try {
            candidate.getContent();
            return candidate;
        } catch (VcsException e) {
        // file does not exists
        }
    } catch (VcsException e) {
        GitVcs.getInstance(myProject).showErrors(Collections.singletonList(e), GitBundle.message("diff.find.error", path));
    }
    return null;
}
Also used : GitFileRevision(git4idea.GitFileRevision) GitContentRevision(git4idea.GitContentRevision) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 GitContentRevision (git4idea.GitContentRevision)1 GitFileRevision (git4idea.GitFileRevision)1 Nullable (org.jetbrains.annotations.Nullable)1