LazyPatchContentRevision: retrieve document text in a read action
authorpeter <peter@jetbrains.com>
Tue, 3 Feb 2015 19:34:32 +0000 (20:34 +0100)
committerpeter <peter@jetbrains.com>
Tue, 3 Feb 2015 19:36:31 +0000 (20:36 +0100)
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/LazyPatchContentRevision.java

index beb175ed906dec15c3af6d8aad5ce8650a41d6b4..8132dd457b99f40cfe6c6f3220e6e304cd879dee 100644 (file)
  */
 package com.intellij.openapi.vcs.changes.patch;
 
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diff.impl.patch.TextFilePatch;
 import com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vcs.changes.ContentRevision;
 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
@@ -42,12 +44,17 @@ public class LazyPatchContentRevision implements ContentRevision {
 
   public String getContent() {
     if (myContent == null) {
-      final Document doc = FileDocumentManager.getInstance().getDocument(myVf);
-      if (doc == null) {
+      final String localContext = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
+        @Override
+        public String compute() {
+          final Document doc = FileDocumentManager.getInstance().getDocument(myVf);
+          return doc == null ? null : doc.getText();
+        }
+      });
+      if (localContext == null) {
         myPatchApplyFailed = true;
         return null;
       }
-      final String localContext = doc.getText();
 
       final GenericPatchApplier applier = new GenericPatchApplier(localContext, myPatch.getHunks());
       if (applier.execute()) {