mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: do not call read action to access to local read-only document
This commit is contained in:
+54
-53
@@ -112,63 +112,64 @@ public class FragmentedDiffRequestFromChange {
|
||||
return myOldDocument;
|
||||
}
|
||||
|
||||
public void execute(final Change change, final FilePath filePath, final SLRUMap<Pair<Long, String>, List<BeforeAfter<TextRange>>> cache,
|
||||
public void execute(final Change change,
|
||||
final FilePath filePath,
|
||||
final SLRUMap<Pair<Long, String>, List<BeforeAfter<TextRange>>> cache,
|
||||
final LineStatusTrackerManagerI lstManager) {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
myDocument = null;
|
||||
myOldDocument = documentFromRevision(change.getBeforeRevision());
|
||||
final String convertedPath = FilePathsHelper.convertPath(filePath);
|
||||
if (filePath.getVirtualFile() != null) {
|
||||
myDocument = FileStatus.DELETED.equals(change.getFileStatus()) ? new DocumentImpl("") :
|
||||
FileDocumentManager.getInstance().getDocument(filePath.getVirtualFile());
|
||||
if (myDocument != null) {
|
||||
final List<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath));
|
||||
if (cached != null) {
|
||||
myRanges = cached;
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
myDocument = null;
|
||||
myOldDocument = documentFromRevision(change.getBeforeRevision());
|
||||
final String convertedPath = FilePathsHelper.convertPath(filePath);
|
||||
if (filePath.getVirtualFile() != null) {
|
||||
myDocument = FileStatus.DELETED.equals(change.getFileStatus())
|
||||
? new DocumentImpl("")
|
||||
: FileDocumentManager.getInstance().getDocument(filePath.getVirtualFile());
|
||||
if (myDocument != null) {
|
||||
final List<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath));
|
||||
if (cached != null) {
|
||||
myRanges = cached;
|
||||
return;
|
||||
}
|
||||
|
||||
if (myDocument == null) {
|
||||
myDocument = documentFromRevision(change.getAfterRevision());
|
||||
final List<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(-1L, convertedPath));
|
||||
if (cached != null) {
|
||||
myRanges = cached;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy();
|
||||
if (comparisonPolicy == null) {
|
||||
comparisonPolicy = ComparisonPolicy.DEFAULT;
|
||||
}
|
||||
final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
|
||||
final ArrayList<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
|
||||
myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size());
|
||||
for (LineFragment lineFragment : lineFragments) {
|
||||
if (! lineFragment.isEqual()) {
|
||||
final TextRange oldRange = lineFragment.getRange(FragmentSide.SIDE1);
|
||||
final TextRange newRange = lineFragment.getRange(FragmentSide.SIDE2);
|
||||
myRanges.add(new BeforeAfter<TextRange>(new UnfairTextRange(myOldDocument.getLineNumber(oldRange.getStartOffset()),
|
||||
myOldDocument.getLineNumber(correctRangeEnd(oldRange.getEndOffset(), myOldDocument))),
|
||||
new UnfairTextRange(myDocument.getLineNumber(newRange.getStartOffset()),
|
||||
myDocument.getLineNumber(correctRangeEnd(newRange.getEndOffset(), myDocument)))));
|
||||
}
|
||||
}
|
||||
cache.put(new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath), new ArrayList<BeforeAfter<TextRange>>(myRanges));
|
||||
}
|
||||
catch (VcsException e) {
|
||||
myException = e;
|
||||
}
|
||||
catch (FilesTooBigForDiffException e) {
|
||||
myException = new VcsException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (myDocument == null) {
|
||||
myDocument = documentFromRevision(change.getAfterRevision());
|
||||
final List<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(-1L, convertedPath));
|
||||
if (cached != null) {
|
||||
myRanges = cached;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy();
|
||||
if (comparisonPolicy == null) {
|
||||
comparisonPolicy = ComparisonPolicy.DEFAULT;
|
||||
}
|
||||
final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
|
||||
final ArrayList<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
|
||||
myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size());
|
||||
for (LineFragment lineFragment : lineFragments) {
|
||||
if (!lineFragment.isEqual()) {
|
||||
final TextRange oldRange = lineFragment.getRange(FragmentSide.SIDE1);
|
||||
final TextRange newRange = lineFragment.getRange(FragmentSide.SIDE2);
|
||||
myRanges.add(new BeforeAfter<TextRange>(new UnfairTextRange(myOldDocument.getLineNumber(oldRange.getStartOffset()),
|
||||
myOldDocument.getLineNumber(
|
||||
correctRangeEnd(oldRange.getEndOffset(), myOldDocument))),
|
||||
new UnfairTextRange(myDocument.getLineNumber(newRange.getStartOffset()), myDocument
|
||||
.getLineNumber(correctRangeEnd(newRange.getEndOffset(), myDocument)))
|
||||
));
|
||||
}
|
||||
}
|
||||
cache
|
||||
.put(new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath), new ArrayList<BeforeAfter<TextRange>>(myRanges));
|
||||
}
|
||||
catch (VcsException e) {
|
||||
myException = e;
|
||||
}
|
||||
catch (FilesTooBigForDiffException e) {
|
||||
myException = new VcsException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private int correctRangeEnd(final int end, final Document document) {
|
||||
|
||||
Reference in New Issue
Block a user