Search in sources :

Example 16 with FileAnnotation

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

the class AbstractVcsTestCase method createTestAnnotation.

public FileAnnotation createTestAnnotation(@NotNull AnnotationProvider provider, VirtualFile file) throws VcsException {
    final FileAnnotation annotation = provider.annotate(file);
    Disposer.register(myProject, annotation::dispose);
    return annotation;
}
Also used : FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation)

Example 17 with FileAnnotation

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

the class VcsContentAnnotationImpl method intervalRecentlyChanged.

@Override
public boolean intervalRecentlyChanged(VirtualFile file, TextRange lineInterval, VcsRevisionNumber currentRevisionNumber) {
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
    final AbstractVcs vcs = vcsManager.getVcsFor(file);
    if (vcs == null || vcs.getDiffProvider() == null)
        return false;
    if (currentRevisionNumber == null) {
        currentRevisionNumber = vcs.getDiffProvider().getCurrentRevision(file);
        assert currentRevisionNumber != null;
    }
    final ThreeState isRecent = myContentAnnotationCache.isRecent(file, vcs.getKeyInstanceMethod(), currentRevisionNumber, lineInterval, System.currentTimeMillis() - mySettings.getLimit());
    if (!ThreeState.UNSURE.equals(isRecent))
        return ThreeState.YES.equals(isRecent);
    final FileAnnotation fileAnnotation;
    try {
        fileAnnotation = vcs.getAnnotationProvider().annotate(file);
    } catch (VcsException e) {
        LOG.info(e);
        return false;
    }
    myContentAnnotationCache.register(file, vcs.getKeyInstanceMethod(), currentRevisionNumber, fileAnnotation);
    for (int i = lineInterval.getStartOffset(); i <= lineInterval.getEndOffset(); i++) {
        Date lineDate = fileAnnotation.getLineDate(i);
        if (lineDate != null && isRecent(lineDate))
            return true;
    }
    return false;
}
Also used : ThreeState(com.intellij.util.ThreeState) VcsException(com.intellij.openapi.vcs.VcsException) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) Date(java.util.Date)

Example 18 with FileAnnotation

use of com.intellij.openapi.vcs.annotate.FileAnnotation 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 19 with FileAnnotation

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

the class SvnAnnotationIsClosedTest method testClosedByUpdateInIdea.

@Test
public void testClosedByUpdateInIdea() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    //#1
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n");
    //#2
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4\n");
    //#3
    checkin();
    runInAndVerifyIgnoreOutput("up", "-r", "2");
    final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener();
    final FileAnnotation annotation = createTestAnnotation(myVcs.getAnnotationProvider(), tree.myS1File);
    annotation.setCloser(() -> {
        myIsClosed = true;
        listener.unregisterAnnotation(tree.myS1File, annotation);
    });
    listener.registerAnnotation(tree.myS1File, annotation);
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    imitUpdate(myProject);
    Assert.assertTrue(myIsClosed);
}
Also used : VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Test(org.junit.Test)

Example 20 with FileAnnotation

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

the class SvnAnnotationIsClosedTest method testClosedByCommitFromIdea.

@Test
public void testClosedByCommitFromIdea() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n");
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4\n");
    checkin();
    final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener();
    final FileAnnotation annotation = createTestAnnotation(myVcs.getAnnotationProvider(), tree.myS1File);
    annotation.setCloser(() -> {
        myIsClosed = true;
        listener.unregisterAnnotation(tree.myS1File, annotation);
    });
    listener.registerAnnotation(tree.myS1File, annotation);
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4++\n");
    // not closed on typing
    Assert.assertFalse(myIsClosed);
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    final Change change = myChangeListManager.getChange(tree.myS1File);
    Assert.assertNotNull(change);
    final List<VcsException> exceptions = myVcs.getCheckinEnvironment().commit(Collections.singletonList(change), "commit");
    Assert.assertTrue(exceptions == null || exceptions.isEmpty());
    myDirtyScopeManager.fileDirty(tree.myS1File);
    myChangeListManager.ensureUpToDate(false);
    // wait for after-events like annotations recalculation
    myChangeListManager.ensureUpToDate(false);
    // zipper updater
    sleep(100);
    Assert.assertTrue(myIsClosed);
}
Also used : VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) VcsException(com.intellij.openapi.vcs.VcsException) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Change(com.intellij.openapi.vcs.changes.Change) Test(org.junit.Test)

Aggregations

FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)28 VcsAnnotationLocalChangesListener (com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener)16 Test (org.junit.Test)16 Change (com.intellij.openapi.vcs.changes.Change)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 VcsException (com.intellij.openapi.vcs.VcsException)7 File (java.io.File)7 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 Ref (com.intellij.openapi.util.Ref)3 FilePath (com.intellij.openapi.vcs.FilePath)3 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)3 AnnotationProvider (com.intellij.openapi.vcs.annotate.AnnotationProvider)3 List (java.util.List)3 AnnotateOperation (com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation)2 Annotation (com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation)2 ActionManager (com.intellij.openapi.actionSystem.ActionManager)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)2