From 6997afc859a3e47552b98b19be39c5e98ca6d9ef Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 20:32:35 +0400 Subject: [PATCH] IDEA-71379 Throwable at org.zmlx.hg4idea.execution.HgCommandExecutor.executeInCurrentThread also, report when files just edited, but not changed --- ...kgroundSynchronousInvisibleComputable.java | 49 +++++++++++++++++++ .../FragmentedDiffRequestFromChange.java | 20 +++++++- .../vcs/changes/VcsChangeDetailsManager.java | 7 ++- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java b/platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java new file mode 100644 index 000000000000..4f62bcbd3f3f --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java @@ -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 { + protected abstract T runImpl(); + + public T compute() { + final Semaphore semaphore = new Semaphore(); + semaphore.down(); + final AtomicReference reference = new AtomicReference(); + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + try { + reference.set(runImpl()); + } + finally { + semaphore.up(); + } + } + }); + semaphore.waitFor(); + return reference.get(); + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java index 5a3a20a7441b..3f97ae57b160 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java @@ -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 ref = new Ref(); + final String s = new BackgroundSynchronousInvisibleComputable() { + @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; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java index f9c9272ae0ad..32bed1d69f64 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java @@ -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 convert(Change o) { try { final List> requestForChange = myRequestFromChange.createRequestForChange(o, extraLines); - if (requestForChange == null || requestForChange.isEmpty()) return null; + if (requestForChange == null) return null; + if (requestForChange.isEmpty()) { + return new Pair( + 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(panel.getPanel(), panel);