mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
hg: simplify: don't use the asynchronous HgCommandExecutor#execute
This method just wraps the code into BackgroundTaskUtil.executeOnPooledThread(). On the other hand, its signature is not easy to read and understand. So better to inline the method and call executeOnPooledThread() directly. The method is used in a 3-party plugin => keep and deprecate it. GitOrigin-RevId: d467ca103a3f9e9a073e5ec87a70bed6eb8aaca1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4016a923a6
commit
986de05156
@@ -15,15 +15,31 @@
|
||||
*/
|
||||
package org.zmlx.hg4idea.action.mq;
|
||||
|
||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.zmlx.hg4idea.command.mq.HgQFinishCommand;
|
||||
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
|
||||
import org.zmlx.hg4idea.execution.HgCommandExecutor;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.repo.HgRepository;
|
||||
import org.zmlx.hg4idea.util.HgErrorUtil;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public class HgQFinishFromLogAction extends HgMqAppliedPatchAction {
|
||||
@Override
|
||||
protected void actionPerformed(@NotNull HgRepository repository, @NotNull Hash commit) {
|
||||
String revisionHash = commit.asString();
|
||||
new HgQFinishCommand(repository).execute(revisionHash);
|
||||
String revision = commit.asString();
|
||||
Project project = repository.getProject();
|
||||
BackgroundTaskUtil.executeOnPooledThread(project, () -> {
|
||||
HgCommandExecutor executor = new HgCommandExecutor(project);
|
||||
HgCommandResult result = executor.executeInCurrentThread(repository.getRoot(), "qfinish", singletonList("qbase:" + revision));
|
||||
if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
|
||||
new HgCommandResultNotifier(project).notifyError(result, "QFinish command failed",
|
||||
"Could not apply patches into repository history.");
|
||||
}
|
||||
repository.update();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// limitations under the License.
|
||||
package org.zmlx.hg4idea.command;
|
||||
|
||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
@@ -20,11 +21,9 @@ import com.intellij.util.Consumer;
|
||||
import com.intellij.vcsUtil.VcsFileUtil;
|
||||
import com.intellij.vcsUtil.VcsUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.zmlx.hg4idea.HgFile;
|
||||
import org.zmlx.hg4idea.execution.HgCommandExecutor;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -57,18 +56,15 @@ public class HgResolveCommand {
|
||||
if (repo == null) {
|
||||
resultHandler.consume(Collections.emptyMap());
|
||||
}
|
||||
final HgCommandExecutor executor = new HgCommandExecutor(myProject);
|
||||
HgCommandExecutor executor = new HgCommandExecutor(myProject);
|
||||
executor.setSilent(true);
|
||||
executor.execute(repo, "resolve", Collections.singletonList("--list"), new HgCommandResultHandler() {
|
||||
@Override
|
||||
public void process(@Nullable HgCommandResult result) {
|
||||
if (result == null) {
|
||||
resultHandler.consume(Collections.emptyMap());
|
||||
}
|
||||
|
||||
final Map<HgFile, HgResolveStatusEnum> resolveStatus = handleResult(repo, result);
|
||||
resultHandler.consume(resolveStatus);
|
||||
BackgroundTaskUtil.executeOnPooledThread(myProject, () -> {
|
||||
HgCommandResult result = executor.executeInCurrentThread(repo, "resolve", Collections.singletonList("--list"));
|
||||
if (result == null) {
|
||||
resultHandler.consume(Collections.emptyMap());
|
||||
}
|
||||
Map<HgFile, HgResolveStatusEnum> resolveStatus = handleResult(repo, result);
|
||||
resultHandler.consume(resolveStatus);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -93,10 +89,11 @@ public class HgResolveCommand {
|
||||
|
||||
public void markResolved(@NotNull VirtualFile repo, @NotNull Collection<FilePath> paths) {
|
||||
for (List<String> chunk : VcsFileUtil.chunkPaths(repo, paths)) {
|
||||
final List<String> args = new ArrayList<>();
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("--mark");
|
||||
args.addAll(chunk);
|
||||
new HgCommandExecutor(myProject).execute(repo, "resolve", args, null);
|
||||
BackgroundTaskUtil.executeOnPooledThread(myProject, () ->
|
||||
new HgCommandExecutor(myProject).executeInCurrentThread(repo, "resolve", args));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,14 @@
|
||||
// limitations under the License.
|
||||
package org.zmlx.hg4idea.command;
|
||||
|
||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.zmlx.hg4idea.execution.HgCommandException;
|
||||
import org.zmlx.hg4idea.execution.HgCommandExecutor;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
|
||||
import org.zmlx.hg4idea.repo.HgRepositoryManager;
|
||||
import org.zmlx.hg4idea.util.HgUtil;
|
||||
@@ -49,7 +51,13 @@ public class HgTagCreateCommand {
|
||||
arguments.add("--rev");
|
||||
arguments.add(revisionNumberOrHash);
|
||||
}
|
||||
new HgCommandExecutor(project).execute(repo, "tag", arguments, resultHandler);
|
||||
HgCommandExecutor executor = new HgCommandExecutor(project);
|
||||
BackgroundTaskUtil.executeOnPooledThread(project, () -> {
|
||||
HgCommandResult result = executor.executeInCurrentThread(repo, "tag", arguments);
|
||||
if (resultHandler != null) {
|
||||
resultHandler.process(result);
|
||||
}
|
||||
});
|
||||
if (!project.isDisposed()) {
|
||||
HgRepositoryManager manager = HgUtil.getRepositoryManager(project);
|
||||
manager.updateRepository(repo);
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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 org.zmlx.hg4idea.command.mq;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
|
||||
import org.zmlx.hg4idea.execution.HgCommandExecutor;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
|
||||
import org.zmlx.hg4idea.repo.HgRepository;
|
||||
import org.zmlx.hg4idea.util.HgErrorUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class HgQFinishCommand {
|
||||
@NotNull private final HgRepository myRepository;
|
||||
|
||||
public HgQFinishCommand(@NotNull HgRepository repository) {
|
||||
myRepository = repository;
|
||||
}
|
||||
|
||||
public void execute(@NotNull final String revision) {
|
||||
final Project project = myRepository.getProject();
|
||||
new HgCommandExecutor(project)
|
||||
.execute(myRepository.getRoot(), "qfinish", Collections.singletonList("qbase:" + revision), new HgCommandResultHandler() {
|
||||
@Override
|
||||
public void process(@Nullable HgCommandResult result) {
|
||||
if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
|
||||
new HgCommandResultNotifier(project)
|
||||
.notifyError(result, "QFinish command failed", "Could not apply patches into repository history.");
|
||||
}
|
||||
myRepository.update();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,16 @@
|
||||
package org.zmlx.hg4idea.command.mq;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.zmlx.hg4idea.HgNameWithHashInfo;
|
||||
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
|
||||
import org.zmlx.hg4idea.execution.HgCommandExecutor;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
|
||||
import org.zmlx.hg4idea.repo.HgRepository;
|
||||
import org.zmlx.hg4idea.util.HgErrorUtil;
|
||||
import org.zmlx.hg4idea.util.HgPatchReferenceValidator;
|
||||
@@ -58,21 +57,19 @@ public class HgQRenameCommand {
|
||||
}
|
||||
}
|
||||
|
||||
public static void performPatchRename(@NotNull final HgRepository repository,
|
||||
@NotNull final String oldName,
|
||||
@NotNull final String newName) {
|
||||
public static void performPatchRename(@NotNull HgRepository repository,
|
||||
@NotNull String oldName,
|
||||
@NotNull String newName) {
|
||||
if (oldName.equals(newName)) return;
|
||||
final Project project = repository.getProject();
|
||||
new HgCommandExecutor(project)
|
||||
.execute(repository.getRoot(), "qrename", Arrays.asList(oldName, newName), new HgCommandResultHandler() {
|
||||
@Override
|
||||
public void process(@Nullable HgCommandResult result) {
|
||||
if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
|
||||
new HgCommandResultNotifier(project)
|
||||
.notifyError(result, "Qrename command failed", "Could not rename patch " + oldName + " to " + newName);
|
||||
}
|
||||
repository.update();
|
||||
}
|
||||
});
|
||||
Project project = repository.getProject();
|
||||
BackgroundTaskUtil.executeOnPooledThread(project, () -> {
|
||||
HgCommandExecutor executor = new HgCommandExecutor(project);
|
||||
HgCommandResult result = executor.executeInCurrentThread(repository.getRoot(), "qrename", Arrays.asList(oldName, newName));
|
||||
if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
|
||||
new HgCommandResultNotifier(project).notifyError(result, "Qrename command failed",
|
||||
"Could not rename patch " + oldName + " to " + newName);
|
||||
}
|
||||
repository.update();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.zmlx.hg4idea.execution;
|
||||
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -99,6 +100,11 @@ public class HgCommandExecutor {
|
||||
myOutputAlwaysSuppressed = outputAlwaysSuppressed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use synchronous versions of "execute", e.g. {@link #executeInCurrentThread(VirtualFile, String, List)}.
|
||||
* Use {@link BackgroundTaskUtil#executeOnPooledThread(Disposable, Runnable)} if need to execute on a pooled thread.
|
||||
*/
|
||||
@Deprecated
|
||||
public void execute(@Nullable final VirtualFile repo,
|
||||
@NotNull final String operation,
|
||||
@Nullable final List<String> arguments,
|
||||
|
||||
Reference in New Issue
Block a user