Search in sources :

Example 21 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 22 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 23 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)

Example 24 with ContentRevision

use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.

the class LocalChangesUnderRootsTest method createChangeForPath.

private Change createChangeForPath(String path) {
    VirtualFile file = VfsTestUtil.createFile(myBaseDir, path);
    FilePath filePath = VcsUtil.getFilePath(file);
    ContentRevision beforeRevision = new MockContentRevision(filePath, new VcsRevisionNumber.Int(1));
    ContentRevision afterRevision = new MockContentRevision(filePath, new VcsRevisionNumber.Int(2));
    return new Change(beforeRevision, afterRevision);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) MockContentRevision(com.intellij.testFramework.vcs.MockContentRevision) Change(com.intellij.openapi.vcs.changes.Change) MockContentRevision(com.intellij.testFramework.vcs.MockContentRevision)

Example 25 with ContentRevision

use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.

the class BlobIndexUtil method getBeforeAfterSha1.

@NotNull
public static Couple<String> getBeforeAfterSha1(@NotNull Change change) throws VcsException {
    ContentRevision beforeRevision = change.getBeforeRevision();
    ContentRevision afterRevision = change.getAfterRevision();
    //noinspection ConstantConditions
    Charset detectCharset = ObjectUtils.chooseNotNull(afterRevision, beforeRevision).getFile().getCharset();
    String before = beforeRevision == null ? NOT_COMMITTED_HASH : getSha1(getContentBytes(beforeRevision, detectCharset));
    String after = afterRevision == null ? NOT_COMMITTED_HASH : getSha1(getContentBytes(afterRevision, detectCharset));
    return new Couple<>(before, after);
}
Also used : Couple(com.intellij.openapi.util.Couple) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) BinaryContentRevision(com.intellij.openapi.vcs.changes.BinaryContentRevision) Charset(java.nio.charset.Charset) NotNull(org.jetbrains.annotations.NotNull)

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