use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class ApplyBinaryShelvedFilePatch method applyChange.
protected Result applyChange(Project project, final VirtualFile fileToPatch, FilePath pathBeforeRename, Getter<CharSequence> baseContents) throws IOException {
try {
ContentRevision contentRevision = myPatch.getShelvedBinaryFile().createChange(project).getAfterRevision();
if (contentRevision != null) {
assert (contentRevision instanceof ShelvedBinaryContentRevision);
byte[] binaryContent = ((ShelvedBinaryContentRevision) contentRevision).getBinaryContent();
//it may be new empty binary file
fileToPatch.setBinaryContent(binaryContent != null ? binaryContent : ArrayUtil.EMPTY_BYTE_ARRAY);
}
} catch (VcsException e) {
LOG.error("Couldn't apply shelved binary patch", e);
return new Result(ApplyPatchStatus.FAILURE) {
@Override
public ApplyPatchForBaseRevisionTexts getMergeData() {
return null;
}
};
}
return SUCCESS;
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class AnnotateVcsVirtualFileAction method extractData.
@Nullable
private static AnnotationData extractData(@NotNull Project project, @NotNull VirtualFile file) {
FilePath filePath = null;
VcsRevisionNumber revisionNumber = null;
if (file instanceof VcsVirtualFile) {
filePath = VcsUtil.getFilePath(file.getPath());
VcsFileRevision revision = ((VcsVirtualFile) file).getFileRevision();
revisionNumber = revision != null ? revision.getRevisionNumber() : null;
} else if (file instanceof ContentRevisionVirtualFile) {
ContentRevision revision = ((ContentRevisionVirtualFile) file).getContentRevision();
filePath = revision.getFile();
revisionNumber = revision.getRevisionNumber();
}
if (filePath == null || revisionNumber == null)
return null;
AbstractVcs vcs = VcsUtil.getVcsFor(project, filePath);
return vcs != null ? new AnnotationData(vcs, filePath, revisionNumber) : null;
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class DiffActionExecutor method createRemote.
@Nullable
protected DiffContent createRemote(final VcsRevisionNumber revisionNumber) throws IOException, VcsException {
final ContentRevision fileRevision = myDiffProvider.createFileContent(revisionNumber, mySelectedFile);
if (fileRevision == null)
return null;
DiffContentFactoryEx contentFactory = DiffContentFactoryEx.getInstanceEx();
DiffContent diffContent;
if (fileRevision instanceof BinaryContentRevision) {
FilePath filePath = fileRevision.getFile();
final byte[] content = ((BinaryContentRevision) fileRevision).getBinaryContent();
if (content == null)
return null;
diffContent = contentFactory.createBinary(myProject, content, filePath.getFileType(), filePath.getName());
} else if (fileRevision instanceof ByteBackedContentRevision) {
byte[] content = ((ByteBackedContentRevision) fileRevision).getContentAsBytes();
if (content == null)
throw new VcsException("Failed to load content");
diffContent = contentFactory.createFromBytes(myProject, content, fileRevision.getFile());
} else {
String content = fileRevision.getContent();
if (content == null)
throw new VcsException("Failed to load content");
diffContent = contentFactory.create(myProject, content, fileRevision.getFile());
}
diffContent.putUserData(DiffUserDataKeysEx.REVISION_INFO, Pair.create(fileRevision.getFile(), fileRevision.getRevisionNumber()));
return diffContent;
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class TabbedShowHistoryForRevisionAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
Project project = event.getRequiredData(CommonDataKeys.PROJECT);
AbstractVcs vcs = assertNotNull(getVcs(project, event.getData(VcsDataKeys.VCS)));
VcsHistoryProviderEx vcsHistoryProvider = assertNotNull((VcsHistoryProviderEx) vcs.getVcsHistoryProvider());
Change change = event.getRequiredData(VcsDataKeys.SELECTED_CHANGES)[0];
ContentRevision revision = assertNotNull(getContentRevision(change));
AbstractVcsHelperImpl helper = assertNotNull(getVcsHelper(project));
helper.showFileHistory(vcsHistoryProvider, revision.getFile(), vcs, revision.getRevisionNumber());
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class CommitCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null)
return;
CommitMessage commitMessage = document.getUserData(CommitMessage.DATA_KEY);
if (commitMessage == null)
return;
result.stopHere();
if (parameters.getInvocationCount() <= 0)
return;
List<ChangeList> lists = commitMessage.getChangeLists();
if (lists.isEmpty())
return;
String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters);
CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix));
for (ChangeList list : lists) {
for (Change change : list.getChanges()) {
ContentRevision revision = change.getAfterRevision() == null ? change.getBeforeRevision() : change.getAfterRevision();
if (revision != null) {
FilePath filePath = revision.getFile();
LookupElementBuilder element = LookupElementBuilder.create(filePath.getName()).withIcon(filePath.getFileType().getIcon());
insensitive.addElement(element);
}
}
}
}
Aggregations