Search in sources :

Example 6 with AnnotationProvider

use of com.intellij.openapi.vcs.annotate.AnnotationProvider in project intellij-community by JetBrains.

the class VcsAnnotationCachedProxy method annotate.

/**
   * @param currentRevision - just a hint for optimization
   */
private FileAnnotation annotate(VirtualFile file, final VcsRevisionNumber revisionNumber, final boolean currentRevision, final ThrowableComputable<FileAnnotation, VcsException> delegate) throws VcsException {
    final AnnotationProvider annotationProvider = myAnnotationProvider;
    final FilePath filePath = VcsUtil.getFilePath(file);
    final VcsCacheableAnnotationProvider cacheableAnnotationProvider = (VcsCacheableAnnotationProvider) annotationProvider;
    VcsAnnotation vcsAnnotation = null;
    if (revisionNumber != null) {
        Object cachedData = myCache.get(filePath, myVcs.getKeyInstanceMethod(), revisionNumber);
        vcsAnnotation = ObjectUtils.tryCast(cachedData, VcsAnnotation.class);
    }
    if (vcsAnnotation != null) {
        final VcsHistoryProvider historyProvider = myVcs.getVcsHistoryProvider();
        final VcsAbstractHistorySession history = getHistory(revisionNumber, filePath, historyProvider, vcsAnnotation.getFirstRevision());
        if (history == null)
            return null;
        // question is whether we need "not moved" path here?
        final ContentRevision fileContent = myVcs.getDiffProvider().createFileContent(revisionNumber, file);
        final FileAnnotation restored = cacheableAnnotationProvider.restore(vcsAnnotation, history, fileContent.getContent(), currentRevision, revisionNumber);
        if (restored != null) {
            return restored;
        }
    }
    final FileAnnotation fileAnnotation = delegate.compute();
    vcsAnnotation = cacheableAnnotationProvider.createCacheable(fileAnnotation);
    if (vcsAnnotation == null)
        return fileAnnotation;
    if (revisionNumber != null) {
        myCache.put(filePath, myVcs.getKeyInstanceMethod(), revisionNumber, vcsAnnotation);
    }
    if (myVcs.getVcsHistoryProvider() instanceof VcsCacheableHistorySessionFactory) {
        loadHistoryInBackgroundToCache(revisionNumber, filePath, vcsAnnotation);
    }
    return fileAnnotation;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsAnnotation(com.intellij.openapi.vcs.annotate.VcsAnnotation) VcsCacheableAnnotationProvider(com.intellij.openapi.vcs.annotate.VcsCacheableAnnotationProvider) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) VcsCacheableAnnotationProvider(com.intellij.openapi.vcs.annotate.VcsCacheableAnnotationProvider) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation)

Example 7 with AnnotationProvider

use of com.intellij.openapi.vcs.annotate.AnnotationProvider in project intellij-community by JetBrains.

the class AnnotateDiffViewerAction method doCreateAnnotationsLoader.

@Nullable
private static FileAnnotationLoader doCreateAnnotationsLoader(@NotNull Project project, @Nullable AbstractVcs vcs, @Nullable final VirtualFile file) {
    if (vcs == null || file == null)
        return null;
    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    if (annotationProvider == null)
        return null;
    FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
    if (fileStatus == FileStatus.UNKNOWN || fileStatus == FileStatus.ADDED || fileStatus == FileStatus.IGNORED) {
        return null;
    }
    return new FileAnnotationLoader(vcs) {

        @Override
        public FileAnnotation compute() throws VcsException {
            return annotationProvider.annotate(file);
        }
    };
}
Also used : AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AnnotationProvider (com.intellij.openapi.vcs.annotate.AnnotationProvider)7 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Project (com.intellij.openapi.project.Project)2 Ref (com.intellij.openapi.util.Ref)2 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VcsKey (com.intellij.openapi.vcs.VcsKey)1 VcsAnnotation (com.intellij.openapi.vcs.annotate.VcsAnnotation)1 VcsCacheableAnnotationProvider (com.intellij.openapi.vcs.annotate.VcsCacheableAnnotationProvider)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)1 ContentRevisionVirtualFile (com.intellij.openapi.vcs.vfs.ContentRevisionVirtualFile)1 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)1 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)1