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;
}
Aggregations