IDEA-71379 Throwable at org.zmlx.hg4idea.execution.HgCommandExecutor.executeInCurrentThread

also, report when files just edited, but not changed
This commit is contained in:
irengrig
2011-06-24 20:34:40 +04:00
parent 829bc33f7b
commit 6997afc859
3 changed files with 74 additions and 2 deletions
@@ -0,0 +1,49 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.progress;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.util.concurrency.Semaphore;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author irengrig
* Date: 6/24/11
* Time: 7:34 PM
*/
public abstract class BackgroundSynchronousInvisibleComputable<T> {
protected abstract T runImpl();
public T compute() {
final Semaphore semaphore = new Semaphore();
semaphore.down();
final AtomicReference<T> reference = new AtomicReference<T>();
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
reference.set(runImpl());
}
finally {
semaphore.up();
}
}
});
semaphore.waitFor();
return reference.get();
}
}
@@ -25,8 +25,10 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.progress.BackgroundSynchronousInvisibleComputable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.FilePath;
@@ -220,7 +222,23 @@ public class FragmentedDiffRequestFromChange implements DiffRequestFromChange<Sh
}
private String notNullContentRevision(final ContentRevision cr) throws VcsException {
final String s = cr == null ? "" : cr.getContent();
if (cr == null) return "";
final Ref<VcsException> ref = new Ref<VcsException>();
final String s = new BackgroundSynchronousInvisibleComputable<String>() {
@Override
protected String runImpl() {
try {
return cr.getContent();
}
catch (VcsException e) {
ref.set(e);
return null;
}
}
}.compute();
if (! ref.isNull()) {
throw ref.get();
}
return s == null ? "" : s;
}
}
@@ -16,6 +16,7 @@
package com.intellij.openapi.vcs.changes;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diff.DiffBundle;
import com.intellij.openapi.diff.DiffContent;
import com.intellij.openapi.diff.DiffPanel;
import com.intellij.openapi.diff.ShiftedSimpleContent;
@@ -148,7 +149,11 @@ public class VcsChangeDetailsManager {
public Pair<JPanel, Disposable> convert(Change o) {
try {
final List<BeforeAfter<ShiftedSimpleContent>> requestForChange = myRequestFromChange.createRequestForChange(o, extraLines);
if (requestForChange == null || requestForChange.isEmpty()) return null;
if (requestForChange == null) return null;
if (requestForChange.isEmpty()) {
return new Pair<JPanel, Disposable>(
errorPanel(DiffBundle.message("diff.contents.have.differences.only.in.line.separators.message.text"), false), null);
}
final ChangesFragmentedDiffPanel panel =
new ChangesFragmentedDiffPanel(myProject, requestForChange, myDiffPanelCache, changeDescription(o));
return new Pair<JPanel, Disposable>(panel.getPanel(), panel);