Search in sources :

Example 1 with VcsAnnotation

use of com.intellij.openapi.vcs.annotate.VcsAnnotation 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)

Aggregations

FilePath (com.intellij.openapi.vcs.FilePath)1 AnnotationProvider (com.intellij.openapi.vcs.annotate.AnnotationProvider)1 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)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