Search in sources :

Example 1 with FileRevisionTimestampComparator

use of com.intellij.history.FileRevisionTimestampComparator in project intellij-community by JetBrains.

the class GettingContentAtDateTest method testWithUnsavedDocuments.

public void testWithUnsavedDocuments() throws Exception {
    setContent(f, "FILE1", TIMESTAMP_INCREMENT);
    Clock.setTime(TIMESTAMP_INCREMENT * 2);
    LocalHistoryAction a = LocalHistory.getInstance().startAction(null);
    setDocumentTextFor(f, "DOC1");
    a.finish();
    Clock.setTime(TIMESTAMP_INCREMENT * 3);
    a = LocalHistory.getInstance().startAction(null);
    setDocumentTextFor(f, "DOC2");
    a.finish();
    FileDocumentManager.getInstance().saveAllDocuments();
    setContent(f, "FILE2", TIMESTAMP_INCREMENT * 4);
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT * 4;
        }
    }, "FILE2");
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT * 3;
        }
    }, "DOC2");
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT * 2;
        }
    }, "DOC1");
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT;
        }
    }, "FILE1");
}
Also used : FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) LocalHistoryAction(com.intellij.history.LocalHistoryAction)

Example 2 with FileRevisionTimestampComparator

use of com.intellij.history.FileRevisionTimestampComparator in project intellij-community by JetBrains.

the class CvsChangeProvider method getLastUpToDateContentFor.

@Nullable
public byte[] getLastUpToDateContentFor(@NotNull final VirtualFile f) {
    final VirtualFile parent = f.getParent();
    final String name = f.getName();
    final Entry entry = myEntriesManager.getEntryFor(parent, name);
    if (entry != null && entry.isResultOfMerge()) {
        // try created by VCS during merge
        final byte[] content = CvsUtil.getStoredContentForFile(f, entry.getRevision());
        if (content != null) {
            return content;
        }
        // try cached by IDEA in CVS dir
        return CvsUtil.getCachedStoredContent(parent, name, entry.getRevision());
    }
    final long upToDateTimestamp = getUpToDateTimeForFile(f);
    final FileRevisionTimestampComparator c = new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return CvsStatusProvider.timeStampsAreEqual(upToDateTimestamp, revisionTimestamp);
        }
    };
    final byte[] localHistoryContent = LocalHistory.getInstance().getByteContent(f, c);
    if (localHistoryContent == null) {
        if (entry != null && CvsUtil.haveCachedContent(f, entry.getRevision())) {
            return CvsUtil.getCachedStoredContent(parent, name, entry.getRevision());
        }
    }
    return localHistoryContent;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileEntry(com.intellij.cvsSupport2.checkinProject.VirtualFileEntry) Entry(org.netbeans.lib.cvsclient.admin.Entry) FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with FileRevisionTimestampComparator

use of com.intellij.history.FileRevisionTimestampComparator in project intellij-community by JetBrains.

the class GettingContentAtDateTest method testGettingMostRecentRevisionContent.

public void testGettingMostRecentRevisionContent() throws Exception {
    setContent(f, "1", TIMESTAMP_INCREMENT);
    setContent(f, "2", TIMESTAMP_INCREMENT * 2);
    FileRevisionTimestampComparator c = new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp < 10000;
        }
    };
    assertContentAt(c, "2");
}
Also used : FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator)

Example 4 with FileRevisionTimestampComparator

use of com.intellij.history.FileRevisionTimestampComparator in project intellij-community by JetBrains.

the class SrcFileAnnotator method doGetLineMapping.

@Nullable
private SoftReference<TIntIntHashMap> doGetLineMapping(final long date, boolean oldToNew, MyEditorBean editorBean) {
    VirtualFile virtualFile = editorBean.getVFile();
    final byte[] oldContent;
    synchronized (LOCK) {
        if (myOldContent == null) {
            if (ApplicationManager.getApplication().isDispatchThread())
                return null;
            final LocalHistory localHistory = LocalHistory.getInstance();
            byte[] byteContent = localHistory.getByteContent(virtualFile, new FileRevisionTimestampComparator() {

                public boolean isSuitable(long revisionTimestamp) {
                    return revisionTimestamp < date;
                }
            });
            if (byteContent == null && virtualFile.getTimeStamp() > date) {
                byteContent = loadFromVersionControl(date, virtualFile);
            }
            myOldContent = new SoftReference<>(byteContent);
        }
        oldContent = myOldContent.get();
    }
    if (oldContent == null)
        return null;
    String[] coveredLines = getCoveredLines(oldContent, virtualFile);
    final Document document = editorBean.getDocument();
    if (document == null)
        return null;
    String[] currentLines = getUpToDateLines(document);
    String[] oldLines = oldToNew ? coveredLines : currentLines;
    String[] newLines = oldToNew ? currentLines : coveredLines;
    Diff.Change change;
    try {
        change = Diff.buildChanges(oldLines, newLines);
    } catch (FilesTooBigForDiffException e) {
        LOG.info(e);
        return null;
    }
    return new SoftReference<>(getCoverageVersionToCurrentLineMapping(change, oldLines.length));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Diff(com.intellij.util.diff.Diff) FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) Document(com.intellij.openapi.editor.Document) SoftReference(com.intellij.reference.SoftReference) LocalHistory(com.intellij.history.LocalHistory) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileRevisionTimestampComparator (com.intellij.history.FileRevisionTimestampComparator)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 VirtualFileEntry (com.intellij.cvsSupport2.checkinProject.VirtualFileEntry)1 LocalHistory (com.intellij.history.LocalHistory)1 LocalHistoryAction (com.intellij.history.LocalHistoryAction)1 Document (com.intellij.openapi.editor.Document)1 SoftReference (com.intellij.reference.SoftReference)1 Diff (com.intellij.util.diff.Diff)1 FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)1 Entry (org.netbeans.lib.cvsclient.admin.Entry)1