[hg]: add an ability to skip default config options during hg execution

* cleanUp;
This commit is contained in:
Nadya Zabrodina
2017-03-30 19:54:19 +03:00
parent 04f9cd51be
commit 3bc9a07df4
2 changed files with 35 additions and 25 deletions
@@ -49,7 +49,9 @@ import java.util.List;
public class HgCommandExecutor {
protected static final Logger LOG = Logger.getInstance(HgCommandExecutor.class.getName());
private static final List<String> DEFAULT_OPTIONS = Arrays.asList("--config", "ui.merge=internal:merge");
// Other parts of the plugin count on the availability of the MQ extension, so make sure it is enabled
private static final List<String> DEFAULT_OPTIONS = Arrays.asList("--config", "extensions.mq=", "--config", "ui.merge=internal:merge");
protected final Project myProject;
protected final HgVcs myVcs;
@@ -95,15 +97,14 @@ public class HgCommandExecutor {
myOutputAlwaysSuppressed = outputAlwaysSuppressed;
}
public void execute(@Nullable final VirtualFile repo, @NotNull final String operation, @Nullable final List<String> arguments,
public void execute(@Nullable final VirtualFile repo,
@NotNull final String operation,
@Nullable final List<String> arguments,
@Nullable final HgCommandResultHandler handler) {
HgUtil.executeOnPooledThread(new Runnable() {
@Override
public void run() {
HgCommandResult result = executeInCurrentThread(repo, operation, arguments);
if (handler != null) {
handler.process(result);
}
HgUtil.executeOnPooledThread(() -> {
HgCommandResult result = executeInCurrentThread(repo, operation, arguments);
if (handler != null) {
handler.process(result);
}
}, myProject);
}
@@ -111,10 +112,17 @@ public class HgCommandExecutor {
public HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo,
@NotNull final String operation,
@Nullable final List<String> arguments) {
HgCommandResult result = executeInCurrentThreadAndLog(repo, operation, arguments);
return executeInCurrentThread(repo, operation, arguments, false);
}
public HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo,
@NotNull final String operation,
@Nullable final List<String> arguments,
boolean ignoreDefaultOptions) {
HgCommandResult result = executeInCurrentThreadAndLog(repo, operation, arguments, ignoreDefaultOptions);
if (HgErrorUtil.isUnknownEncodingError(result)) {
setCharset(Charset.forName("utf8"));
result = executeInCurrentThreadAndLog(repo, operation, arguments);
result = executeInCurrentThreadAndLog(repo, operation, arguments, ignoreDefaultOptions);
}
return result;
}
@@ -122,10 +130,11 @@ public class HgCommandExecutor {
@Nullable
private HgCommandResult executeInCurrentThreadAndLog(@Nullable final VirtualFile repo,
@NotNull final String operation,
@Nullable final List<String> arguments) {
@Nullable final List<String> arguments,
boolean ignoreDefaultOptions) {
if (myProject == null || myProject.isDisposed() || myVcs == null) return null;
ShellCommand shellCommand = createShellCommandWithArgs(repo, operation, arguments);
ShellCommand shellCommand = createShellCommandWithArgs(repo, operation, arguments, ignoreDefaultOptions);
try {
long startTime = System.currentTimeMillis();
LOG.debug(String.format("hg %s started", operation));
@@ -153,7 +162,10 @@ public class HgCommandExecutor {
}
@NotNull
private ShellCommand createShellCommandWithArgs(@Nullable VirtualFile repo, @NotNull String operation, @Nullable List<String> arguments) {
private ShellCommand createShellCommandWithArgs(@Nullable VirtualFile repo,
@NotNull String operation,
@Nullable List<String> arguments,
boolean ignoreDefaultOptions) {
logCommand(operation, arguments);
@@ -164,11 +176,9 @@ public class HgCommandExecutor {
cmdLine.add(repo.getPath());
}
// Other parts of the plugin count on the availability of the MQ extension, so make sure it is enabled
cmdLine.add("--config");
cmdLine.add("extensions.mq=");
cmdLine.addAll(DEFAULT_OPTIONS);
if (!ignoreDefaultOptions) {
cmdLine.addAll(DEFAULT_OPTIONS);
}
cmdLine.add(operation);
if (arguments != null && arguments.size() != 0) {
cmdLine.addAll(arguments);
@@ -49,7 +49,7 @@ public class HgRemoteCommandExecutor extends HgCommandExecutor {
@Nullable final List<String> arguments) {
HgCommandResult result = executeInCurrentThread(repo, operation, arguments, false);
HgCommandResult result = executeRemoteCommandInCurrentThread(repo, operation, arguments, false);
if (!myIgnoreAuthorizationRequest && HgErrorUtil.isAuthorizationError(result)) {
if (HgErrorUtil.hasAuthorizationInDestinationPath(myDestination)) {
new HgCommandResultNotifier(myProject)
@@ -57,16 +57,16 @@ public class HgRemoteCommandExecutor extends HgCommandExecutor {
"Please, update your .hg/hgrc file.");
return null;
}
result = executeInCurrentThread(repo, operation, arguments, true);
result = executeRemoteCommandInCurrentThread(repo, operation, arguments, true);
}
return result;
}
@Nullable
private HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo,
@NotNull final String operation,
@Nullable final List<String> arguments,
boolean forceAuthorization) {
private HgCommandResult executeRemoteCommandInCurrentThread(@Nullable final VirtualFile repo,
@NotNull final String operation,
@Nullable final List<String> arguments,
boolean forceAuthorization) {
PassReceiver passReceiver = new PassReceiver(myProject, forceAuthorization, myIgnoreAuthorizationRequest, myState);
SocketServer passServer = new SocketServer(passReceiver);