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");
}
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;
}
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");
}
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));
}
Aggregations