Search in sources :

Example 11 with VcsHistoryProvider

use of com.intellij.openapi.vcs.history.VcsHistoryProvider in project intellij-community by JetBrains.

the class SrcFileAnnotator method loadFromVersionControl.

@Nullable
private byte[] loadFromVersionControl(long date, VirtualFile f) {
    try {
        final AbstractVcs vcs = VcsUtil.getVcsFor(myProject, f);
        if (vcs == null)
            return null;
        final VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
        if (historyProvider == null)
            return null;
        final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(f);
        final VcsHistorySession session = historyProvider.createSessionFor(filePath);
        if (session == null)
            return null;
        final List<VcsFileRevision> list = session.getRevisionList();
        if (list != null) {
            for (VcsFileRevision revision : list) {
                final Date revisionDate = revision.getRevisionDate();
                if (revisionDate == null) {
                    return null;
                }
                if (revisionDate.getTime() < date) {
                    return revision.loadContent();
                }
            }
        }
    } catch (Exception e) {
        LOG.info(e);
        return null;
    }
    return null;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with VcsHistoryProvider

use of com.intellij.openapi.vcs.history.VcsHistoryProvider in project intellij-community by JetBrains.

the class SvnHistoryTest method testLocallyMovedToRenamedDirectory.

@Test
public void testLocallyMovedToRenamedDirectory() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
    myCnt = 0;
    final VcsHistoryProvider provider = SvnVcs.getInstance(myProject).getVcsHistoryProvider();
    final SubTree tree = new SubTree(myWorkingCopyDir);
    checkin();
    for (int i = 0; i < 10; i++) {
        VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n" + i);
        checkin();
    }
    VcsTestUtil.renameFileInCommand(myProject, tree.myTargetDir, "renamedTarget");
    VcsTestUtil.moveFileInCommand(myProject, tree.myS1File, tree.myTargetDir);
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    ChangeListManager.getInstance(myProject).ensureUpToDate(false);
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    provider.reportAppendableHistory(VcsUtil.getFilePath(tree.myS1File), new VcsAppendableHistorySessionPartner() {

        @Override
        public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
        }

        @Override
        public void acceptRevision(VcsFileRevision revision) {
            ++myCnt;
        }

        @Override
        public void reportException(VcsException exception) {
            throw new RuntimeException(exception);
        }

        @Override
        public void finished() {
            semaphore.up();
        }

        @Override
        public void beforeRefresh() {
        }

        @Override
        public void forceRefresh() {
        }
    });
    semaphore.waitFor(1000);
    Assert.assertEquals(11, myCnt);
    myCnt = 0;
    semaphore.down();
    provider.reportAppendableHistory(VcsUtil.getFilePath(tree.myTargetDir), new VcsAppendableHistorySessionPartner() {

        @Override
        public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
        }

        @Override
        public void acceptRevision(VcsFileRevision revision) {
            ++myCnt;
        }

        @Override
        public void reportException(VcsException exception) {
            throw new RuntimeException(exception);
        }

        @Override
        public void finished() {
            semaphore.up();
        }

        @Override
        public void beforeRefresh() {
        }

        @Override
        public void forceRefresh() {
        }
    });
    semaphore.waitFor(1000);
    Assert.assertEquals(1, myCnt);
    myCnt = 0;
    semaphore.down();
    provider.reportAppendableHistory(VcsUtil.getFilePath(tree.myTargetFiles.get(0)), new VcsAppendableHistorySessionPartner() {

        @Override
        public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
        }

        @Override
        public void acceptRevision(VcsFileRevision revision) {
            ++myCnt;
        }

        @Override
        public void reportException(VcsException exception) {
            throw new RuntimeException(exception);
        }

        @Override
        public void finished() {
            semaphore.up();
        }

        @Override
        public void beforeRefresh() {
        }

        @Override
        public void forceRefresh() {
        }
    });
    semaphore.waitFor(1000);
    Assert.assertEquals(1, myCnt);
}
Also used : VcsAppendableHistorySessionPartner(com.intellij.openapi.vcs.history.VcsAppendableHistorySessionPartner) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) Semaphore(com.intellij.util.concurrency.Semaphore) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VcsAbstractHistorySession(com.intellij.openapi.vcs.history.VcsAbstractHistorySession) Test(org.junit.Test)

Aggregations

VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)12 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)8 VcsAbstractHistorySession (com.intellij.openapi.vcs.history.VcsAbstractHistorySession)5 VcsAppendableHistorySessionPartner (com.intellij.openapi.vcs.history.VcsAppendableHistorySessionPartner)5 Semaphore (com.intellij.util.concurrency.Semaphore)5 Test (org.junit.Test)5 Project (com.intellij.openapi.project.Project)4 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 VcsHistorySession (com.intellij.openapi.vcs.history.VcsHistorySession)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 VcsHistoryProviderEx (com.intellij.vcs.history.VcsHistoryProviderEx)2 VcsSelection (com.intellij.vcsUtil.VcsSelection)2 FileHyperlinkInfo (com.intellij.execution.filters.FileHyperlinkInfo)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 EditorHyperlinkSupport (com.intellij.execution.impl.EditorHyperlinkSupport)1 AllIcons (com.intellij.icons.AllIcons)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1