Search in sources :

Example 26 with ContentRevision

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;
}
Also used : ShelvedBinaryContentRevision(com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryContentRevision) VcsException(com.intellij.openapi.vcs.VcsException) ShelvedBinaryContentRevision(com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryContentRevision) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) ApplyPatchForBaseRevisionTexts(com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts)

Example 27 with ContentRevision

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;
}
Also used : VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) ContentRevisionVirtualFile(com.intellij.openapi.vcs.vfs.ContentRevisionVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with ContentRevision

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;
}
Also used : BinaryContentRevision(com.intellij.openapi.vcs.changes.BinaryContentRevision) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) ByteBackedContentRevision(com.intellij.openapi.vcs.changes.ByteBackedContentRevision) BinaryContentRevision(com.intellij.openapi.vcs.changes.BinaryContentRevision) DiffContentFactoryEx(com.intellij.diff.DiffContentFactoryEx) DiffContent(com.intellij.diff.contents.DiffContent) ByteBackedContentRevision(com.intellij.openapi.vcs.changes.ByteBackedContentRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with ContentRevision

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());
}
Also used : Project(com.intellij.openapi.project.Project) VcsHistoryProviderEx(com.intellij.vcs.history.VcsHistoryProviderEx) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) AbstractVcsHelperImpl(com.intellij.openapi.vcs.impl.AbstractVcsHelperImpl) Change(com.intellij.openapi.vcs.changes.Change)

Example 30 with ContentRevision

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);
            }
        }
    }
}
Also used : CommitMessage(com.intellij.openapi.vcs.ui.CommitMessage) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiFile(com.intellij.psi.PsiFile) Change(com.intellij.openapi.vcs.changes.Change) Document(com.intellij.openapi.editor.Document) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher)

Aggregations

ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)53 Change (com.intellij.openapi.vcs.changes.Change)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 FilePath (com.intellij.openapi.vcs.FilePath)15 NotNull (org.jetbrains.annotations.NotNull)12 VcsException (com.intellij.openapi.vcs.VcsException)9 GitContentRevision (git4idea.GitContentRevision)9 File (java.io.File)9 FileStatus (com.intellij.openapi.vcs.FileStatus)5 Nullable (org.jetbrains.annotations.Nullable)5 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)4 CurrentContentRevision (com.intellij.openapi.vcs.changes.CurrentContentRevision)4 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)3 GitRevisionNumber (git4idea.GitRevisionNumber)3 AccessToken (com.intellij.openapi.application.AccessToken)2 Project (com.intellij.openapi.project.Project)2 Ref (com.intellij.openapi.util.Ref)2 BinaryContentRevision (com.intellij.openapi.vcs.changes.BinaryContentRevision)2 ByteBackedContentRevision (com.intellij.openapi.vcs.changes.ByteBackedContentRevision)2 ChangeList (com.intellij.openapi.vcs.changes.ChangeList)2