Thread problems with updateTo action fixed

*do not call updateToFromLog from awt thread;
*unnecessary pool thread removed from UpdateToAction;
*create one common method for updateTo as background task
This commit is contained in:
Nadya Zabrodina
2014-02-11 11:26:05 +04:00
parent 6c1effc099
commit 828b80f5cb
3 changed files with 27 additions and 55 deletions
@@ -16,7 +16,6 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
@@ -75,7 +74,7 @@ abstract class HgAbstractGlobalAction extends AnAction {
new HgCommandResultNotifier(project).notifyError(null, title, e.getMessage());
}
protected void markDirtyAndHandleErrors(Project project, VirtualFile repository) {
static void markDirtyAndHandleErrors(Project project, VirtualFile repository) {
try {
HgUtil.markDirectoryDirty(project, repository);
}
@@ -12,7 +12,6 @@
// limitations under the License.
package org.zmlx.hg4idea.action;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
@@ -21,7 +20,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgVcs;
import org.zmlx.hg4idea.HgVcsMessages;
import org.zmlx.hg4idea.command.HgUpdateCommand;
import org.zmlx.hg4idea.execution.HgCommandResult;
@@ -46,54 +44,42 @@ public class HgUpdateToAction extends HgAbstractGlobalAction {
});
}
private void showUpdateDialogAndExecute(final Project project,
Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo,
HgBranchesAndTags branchesAndTags) {
private static void showUpdateDialogAndExecute(@NotNull final Project project,
@NotNull Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo,
@NotNull HgBranchesAndTags branchesAndTags) {
final HgUpdateToDialog dialog = new HgUpdateToDialog(project);
dialog.setRoots(repos, selectedRepo, branchesAndTags);
dialog.show();
if (dialog.isOK()) {
FileDocumentManager.getInstance().saveAllDocuments();
String updateToValue = dialog.isBranchSelected()
? dialog.getBranch().getName()
: dialog.isTagSelected() ? dialog.getTag().getName() : dialog.getRevision();
new Task.Backgroundable(project, HgVcsMessages.message("hg4idea.progress.updatingTo", updateToValue)) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
updateTo(dialog, project);
markDirtyAndHandleErrors(project, dialog.getRepository());
}
}.queue();
final String updateToValue = dialog.isBranchSelected()
? dialog.getBranch().getName()
: dialog.isBookmarkSelected()
? dialog.getBookmark().getName()
: dialog.isTagSelected() ? dialog.getTag().getName() : dialog.getRevision();
String title = HgVcsMessages.message("hg4idea.progress.updatingTo", updateToValue);
runUpdateToInBackground(project, title, dialog.getRepository(), updateToValue, dialog.isRemoveLocalChanges());
}
}
public void updateTo(HgUpdateToDialog dialog, final Project project) {
final VirtualFile repository = dialog.getRepository();
final HgUpdateCommand command = new HgUpdateCommand(project, repository);
command.setClean(dialog.isRemoveLocalChanges());
if (dialog.isRevisionSelected()) {
command.setRevision(dialog.getRevision());
}
if (dialog.isBranchSelected()) {
command.setBranch(dialog.getBranch().getName());
}
if (dialog.isTagSelected()) {
command.setRevision(dialog.getTag().getName());
}
if (dialog.isBookmarkSelected()) {
command.setRevision(dialog.getBookmark().getName());
}
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public static void runUpdateToInBackground(@NotNull final Project project,
@NotNull String title,
@NotNull final VirtualFile root,
@NotNull final String updateToNameOrRevision,
final boolean clean) {
new Task.Backgroundable(project, title) {
@Override
public void run() {
public void run(@NotNull ProgressIndicator indicator) {
final HgUpdateCommand command = new HgUpdateCommand(project, root);
command.setRevision(updateToNameOrRevision);
command.setClean(clean);
HgCommandResult result = command.execute();
new HgConflictResolver(project).resolve(repository);
new HgConflictResolver(project).resolve(root);
if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
new HgCommandResultNotifier(project).notifyError(result, "", "Update failed");
}
project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project, null);
markDirtyAndHandleErrors(project, root);
}
});
}.queue();
}
}
@@ -19,29 +19,16 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.VcsFullCommitDetails;
import org.jetbrains.annotations.NotNull;
import org.zmlx.hg4idea.HgVcs;
import org.zmlx.hg4idea.command.HgUpdateCommand;
import org.zmlx.hg4idea.execution.HgCommandResult;
import org.zmlx.hg4idea.provider.update.HgConflictResolver;
import org.zmlx.hg4idea.HgVcsMessages;
import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.util.HgErrorUtil;
/**
* @author Nadya Zabrodina
*/
public class HgUpdateToFromLogAction extends HgLogSingleCommitAction {
@Override
protected void actionPerformed(@NotNull HgRepository repository, @NotNull VcsFullCommitDetails commit) {
String revisionHash = commit.getHash().asString();
Project project = repository.getProject();
VirtualFile rootFile = repository.getRoot();
HgUpdateCommand updateCommand = new HgUpdateCommand(project, rootFile);
updateCommand.setRevision(revisionHash);
HgCommandResult result = updateCommand.execute();
new HgConflictResolver(project).resolve(rootFile);
if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
new HgCommandResultNotifier(project).notifyError(result, "", "Update failed");
}
project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project, null);
String title = HgVcsMessages.message("hg4idea.progress.updatingTo", revisionHash);
HgUpdateToAction.runUpdateToInBackground(project, title, rootFile, revisionHash, false);
}
}