Search in sources :

Example 11 with HgCommandExecutor

use of org.zmlx.hg4idea.execution.HgCommandExecutor in project intellij-community by JetBrains.

the class HgResolveCommand method getListAsynchronously.

public void getListAsynchronously(final VirtualFile repo, final Consumer<Map<HgFile, HgResolveStatusEnum>> resultHandler) {
    if (repo == null) {
        resultHandler.consume(Collections.emptyMap());
    }
    final 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);
        }
    });
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgCommandResultHandler(org.zmlx.hg4idea.execution.HgCommandResultHandler)

Example 12 with HgCommandExecutor

use of org.zmlx.hg4idea.execution.HgCommandExecutor in project intellij-community by JetBrains.

the class HgRevertCommand method execute.

//all files should be already chunked
@Nullable
public HgCommandResult execute(@NotNull VirtualFile repo, @NotNull Collection<String> files, @Nullable HgRevisionNumber vcsRevisionNumber, boolean backupFile) {
    final List<String> options = new LinkedList<>();
    if (vcsRevisionNumber != null && !HgRevisionNumber.NULL_REVISION_NUMBER.equals(vcsRevisionNumber)) {
        options.add("--rev");
        if (!StringUtil.isEmptyOrSpaces(vcsRevisionNumber.getChangeset())) {
            options.add(vcsRevisionNumber.getChangeset());
        } else {
            options.add(vcsRevisionNumber.getRevision());
        }
    }
    if (!backupFile) {
        options.add("--no-backup");
    }
    options.addAll(files);
    return new HgCommandExecutor(project).executeInCurrentThread(repo, "revert", options);
}
Also used : HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) LinkedList(java.util.LinkedList) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with HgCommandExecutor

use of org.zmlx.hg4idea.execution.HgCommandExecutor in project intellij-community by JetBrains.

the class HgShowConfigCommand method execute.

@NotNull
public Map<String, Map<String, String>> execute(@Nullable VirtualFile repo) {
    if (repo == null) {
        return Collections.emptyMap();
    }
    final HgCommandExecutor executor = new HgCommandExecutor(project);
    executor.setSilent(true);
    //force override debug option while initialize hg configs
    HgCommandResult result = executor.executeInCurrentThread(repo, "showconfig", Arrays.asList("--config", "ui.debug=false"));
    if (result == null) {
        return Collections.emptyMap();
    }
    Map<String, Map<String, String>> configMap = new HashMap<>();
    for (String line : result.getOutputLines()) {
        List<String> option = StringUtil.split(line, "=", true, false);
        if (option.size() == 2) {
            String sectionAndName = option.get(0).trim();
            String value = option.get(1).trim();
            int dotIndex = sectionAndName.indexOf('.');
            if (dotIndex > 0) {
                String sectionName = sectionAndName.substring(0, dotIndex);
                String optionName = sectionAndName.substring(dotIndex + 1, sectionAndName.length());
                if (configMap.containsKey(sectionName)) {
                    configMap.get(sectionName).put(optionName, value);
                } else {
                    HashMap<String, String> sectionMap = new HashMap<>();
                    sectionMap.put(optionName, value);
                    configMap.put(sectionName, sectionMap);
                }
            }
        }
    }
    return configMap;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with HgCommandExecutor

use of org.zmlx.hg4idea.execution.HgCommandExecutor in project intellij-community by JetBrains.

the class HgQGotoCommand method executeInCurrentThread.

public HgCommandResult executeInCurrentThread(@NotNull final String name) {
    Project project = myRepository.getProject();
    HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(myRepository.getRoot(), "qgoto", Collections.singletonList(name));
    if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
        new HgCommandResultNotifier(project).notifyError(result, "QGoto command failed", "Could not go to patch " + name);
    }
    myRepository.update();
    return result;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier)

Example 15 with HgCommandExecutor

use of org.zmlx.hg4idea.execution.HgCommandExecutor in project intellij-community by JetBrains.

the class HgQImportCommand method executeInCurrentThread.

public void executeInCurrentThread(@NotNull final String startRevisionNumber) {
    final Project project = myRepository.getProject();
    String lastRevisionName = myRepository.getMQAppliedPatches().isEmpty() ? "tip" : "qparent";
    List<String> arguments = ContainerUtil.newArrayList("--rev", startRevisionNumber + ":" + lastRevisionName);
    HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(myRepository.getRoot(), "qimport", arguments);
    if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
        new HgCommandResultNotifier(project).notifyError(result, "Import failed", "Import revision from " + startRevisionNumber + " to qparent failed");
    }
    myRepository.update();
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier)

Aggregations

HgCommandExecutor (org.zmlx.hg4idea.execution.HgCommandExecutor)31 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)21 HgCommandResultNotifier (org.zmlx.hg4idea.action.HgCommandResultNotifier)11 Project (com.intellij.openapi.project.Project)8 Nullable (org.jetbrains.annotations.Nullable)6 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)4 HgCommandResultHandler (org.zmlx.hg4idea.execution.HgCommandResultHandler)4 NotNull (org.jetbrains.annotations.NotNull)3 AccessToken (com.intellij.openapi.application.AccessToken)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Date (java.util.Date)1 List (java.util.List)1 HgChange (org.zmlx.hg4idea.HgChange)1 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)1 HgVcs (org.zmlx.hg4idea.HgVcs)1 HgCommandException (org.zmlx.hg4idea.execution.HgCommandException)1 HgRepositoryManager (org.zmlx.hg4idea.repo.HgRepositoryManager)1