Search in sources :

Example 1 with DiffProvider

use of com.intellij.openapi.vcs.diff.DiffProvider in project intellij-community by JetBrains.

the class VcsAnnotationLocalChangesListenerImpl method fromDiffProvider.

private VcsRevisionNumber fromDiffProvider(final VirtualFile vf) {
    final VcsRoot vcsRoot = myVcsManager.getVcsRootObjectFor(vf);
    DiffProvider diffProvider;
    if (vcsRoot != null && vcsRoot.getVcs() != null && (diffProvider = vcsRoot.getVcs().getDiffProvider()) != null) {
        return diffProvider.getCurrentRevision(vf);
    }
    return null;
}
Also used : DiffProvider(com.intellij.openapi.vcs.diff.DiffProvider) VcsRoot(com.intellij.openapi.vcs.VcsRoot)

Example 2 with DiffProvider

use of com.intellij.openapi.vcs.diff.DiffProvider in project intellij-community by JetBrains.

the class VcsAnnotationCachedProxy method annotate.

@Override
public FileAnnotation annotate(final VirtualFile file) throws VcsException {
    final DiffProvider diffProvider = myVcs.getDiffProvider();
    final VcsRevisionNumber currentRevision = diffProvider.getCurrentRevision(file);
    return annotate(file, currentRevision, true, new ThrowableComputable<FileAnnotation, VcsException>() {

        @Override
        public FileAnnotation compute() throws VcsException {
            return myAnnotationProvider.annotate(file);
        }
    });
}
Also used : DiffProvider(com.intellij.openapi.vcs.diff.DiffProvider) VcsException(com.intellij.openapi.vcs.VcsException) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation)

Example 3 with DiffProvider

use of com.intellij.openapi.vcs.diff.DiffProvider in project intellij-community by JetBrains.

the class SelectAndCompareWithSelectedRevisionAction method actionPerformed.

@Override
protected void actionPerformed(@NotNull VcsContext vcsContext) {
    final VirtualFile file = vcsContext.getSelectedFiles()[0];
    final Project project = vcsContext.getProject();
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
    if (vcs == null) {
        return;
    }
    RevisionSelector selector = vcs.getRevisionSelector();
    final DiffProvider diffProvider = vcs.getDiffProvider();
    if (selector != null) {
        final VcsRevisionNumber vcsRevisionNumber = selector.selectNumber(file);
        if (vcsRevisionNumber != null) {
            DiffActionExecutor.showDiff(diffProvider, vcsRevisionNumber, file, project, VcsBackgroundableActions.COMPARE_WITH);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DiffProvider(com.intellij.openapi.vcs.diff.DiffProvider) RevisionSelector(com.intellij.openapi.vcs.diff.RevisionSelector) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 4 with DiffProvider

use of com.intellij.openapi.vcs.diff.DiffProvider in project intellij-community by JetBrains.

the class AbstractShowDiffAction method actionPerformed.

@Override
protected void actionPerformed(@NotNull VcsContext vcsContext) {
    Project project = assertNotNull(vcsContext.getProject());
    if (!ChangeListManager.getInstance(project).isFreezedWithNotification("Can not " + vcsContext.getActionName() + " now")) {
        VirtualFile file = vcsContext.getSelectedFiles()[0];
        AbstractVcs vcs = assertNotNull(ChangesUtil.getVcsForFile(file, project));
        DiffProvider provider = assertNotNull(vcs.getDiffProvider());
        getExecutor(provider, file, project).showDiff();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DiffProvider(com.intellij.openapi.vcs.diff.DiffProvider) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 5 with DiffProvider

use of com.intellij.openapi.vcs.diff.DiffProvider in project intellij-community by JetBrains.

the class DefaultPatchBaseVersionProvider method getBaseVersionContent.

public void getBaseVersionContent(final FilePath filePath, final Processor<CharSequence> processor, final List<String> warnings) throws VcsException {
    if (myVcs == null) {
        return;
    }
    final VcsHistoryProvider historyProvider = myVcs.getVcsHistoryProvider();
    if (historyProvider == null)
        return;
    VcsRevisionNumber revision = null;
    if (myRevisionPattern != null) {
        final Matcher matcher = myRevisionPattern.matcher(myVersionId);
        if (matcher.find()) {
            revision = myVcs.parseRevisionNumber(matcher.group(1), filePath);
            final VcsRevisionNumber finalRevision = revision;
            final Boolean[] loadedExactRevision = new Boolean[1];
            if (historyProvider instanceof VcsBaseRevisionAdviser) {
                final boolean success = VcsUtil.runVcsProcessWithProgress(new VcsRunnable() {

                    public void run() throws VcsException {
                        loadedExactRevision[0] = ((VcsBaseRevisionAdviser) historyProvider).getBaseVersionContent(filePath, processor, finalRevision.asString(), warnings);
                    }
                }, VcsBundle.message("progress.text2.loading.revision", revision.asString()), true, myProject);
                // was cancelled
                if (!success)
                    return;
            } else {
                // use diff provider
                final DiffProvider diffProvider = myVcs.getDiffProvider();
                if (diffProvider != null && filePath.getVirtualFile() != null) {
                    final ContentRevision fileContent = diffProvider.createFileContent(finalRevision, filePath.getVirtualFile());
                    final boolean success = VcsUtil.runVcsProcessWithProgress(new VcsRunnable() {

                        public void run() throws VcsException {
                            loadedExactRevision[0] = !processor.process(fileContent.getContent());
                        }
                    }, VcsBundle.message("progress.text2.loading.revision", revision.asString()), true, myProject);
                    // was cancelled
                    if (!success)
                        return;
                }
            }
            if (Boolean.TRUE.equals(loadedExactRevision[0]))
                return;
        }
    }
    Date versionDate = null;
    if (revision == null) {
        try {
            final Matcher tsMatcher = ourTsPattern.matcher(myVersionId);
            if (tsMatcher.find()) {
                final Long fromTsPattern = getFromTsPattern();
                if (fromTsPattern == null)
                    return;
                versionDate = new Date(fromTsPattern);
            } else {
                versionDate = new Date(myVersionId);
            }
        } catch (IllegalArgumentException ex) {
            return;
        }
    }
    try {
        final Ref<VcsHistorySession> ref = new Ref<>();
        boolean result = VcsUtil.runVcsProcessWithProgress(new VcsRunnable() {

            public void run() throws VcsException {
                ref.set(historyProvider.createSessionFor(filePath));
            }
        }, VcsBundle.message("loading.file.history.progress"), true, myProject);
        //if not found or cancelled
        if (ref.isNull() || !result)
            return;
        final VcsHistorySession session = ref.get();
        final List<VcsFileRevision> list = session.getRevisionList();
        if (list == null)
            return;
        for (VcsFileRevision fileRevision : list) {
            boolean found;
            if (revision != null) {
                found = fileRevision.getRevisionNumber().compareTo(revision) <= 0;
            } else {
                final Date date = fileRevision instanceof VcsFileRevisionDvcsSpecific ? ((VcsFileRevisionDvcsSpecific) fileRevision).getDateForRevisionsOrdering() : fileRevision.getRevisionDate();
                found = (date != null) && (date.before(versionDate) || date.equals(versionDate));
            }
            if (found) {
                fileRevision.loadContent();
                processor.process(LoadTextUtil.getTextByBinaryPresentation(fileRevision.getContent(), myFile, false, false));
                // TODO: try to download more than one version
                break;
            }
        }
    } catch (IOException e) {
        LOG.error(e);
    }
}
Also used : VcsRunnable(com.intellij.vcsUtil.VcsRunnable) Matcher(java.util.regex.Matcher) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) IOException(java.io.IOException) Date(java.util.Date) Ref(com.intellij.openapi.util.Ref) DiffProvider(com.intellij.openapi.vcs.diff.DiffProvider)

Aggregations

DiffProvider (com.intellij.openapi.vcs.diff.DiffProvider)5 Project (com.intellij.openapi.project.Project)2 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Ref (com.intellij.openapi.util.Ref)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VcsRoot (com.intellij.openapi.vcs.VcsRoot)1 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 RevisionSelector (com.intellij.openapi.vcs.diff.RevisionSelector)1 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)1 VcsRunnable (com.intellij.vcsUtil.VcsRunnable)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1