Search in sources :

Example 1 with HgCommandExecutor

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

the class HgStatusCommand method executeInCurrentThread.

public Set<HgChange> executeInCurrentThread(VirtualFile repo, @Nullable Collection<FilePath> paths) {
    if (repo == null) {
        return Collections.emptySet();
    }
    HgCommandExecutor executor = new HgCommandExecutor(myProject);
    executor.setSilent(true);
    List<String> options = new LinkedList<>();
    if (myIncludeAdded) {
        options.add("--added");
    }
    if (myIncludeModified) {
        options.add("--modified");
    }
    if (myIncludeRemoved) {
        options.add("--removed");
    }
    if (myIncludeDeleted) {
        options.add("--deleted");
    }
    if (myIncludeUnknown) {
        options.add("--unknown");
    }
    if (myIncludeIgnored) {
        options.add("--ignored");
    }
    if (myIncludeCopySource) {
        options.add("--copies");
    }
    if (myCleanStatus) {
        options.add("--clean");
    }
    executor.setOutputAlwaysSuppressed(myCleanStatus || myIncludeUnknown || myIncludeIgnored);
    if (myBaseRevision != null && (!myBaseRevision.getRevision().isEmpty() || !myBaseRevision.getChangeset().isEmpty())) {
        options.add("--rev");
        options.add(StringUtil.isEmptyOrSpaces(myBaseRevision.getChangeset()) ? myBaseRevision.getRevision() : myBaseRevision.getChangeset());
        if (myTargetRevision != null) {
            options.add("--rev");
            options.add(myTargetRevision.getChangeset());
        }
    }
    final Set<HgChange> changes = new HashSet<>();
    if (paths != null) {
        final List<List<String>> chunked = VcsFileUtil.chunkPaths(repo, paths);
        for (List<String> chunk : chunked) {
            List<String> args = new ArrayList<>();
            args.addAll(options);
            args.addAll(chunk);
            HgCommandResult result = executor.executeInCurrentThread(repo, "status", args);
            changes.addAll(parseChangesFromResult(repo, result, args));
        }
    } else {
        HgCommandResult result = executor.executeInCurrentThread(repo, "status", options);
        changes.addAll(parseChangesFromResult(repo, result, options));
    }
    return changes;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgChange(org.zmlx.hg4idea.HgChange)

Example 2 with HgCommandExecutor

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

the class HgTagCreateCommand method executeAsynchronously.

public void executeAsynchronously(HgCommandResultHandler resultHandler) throws HgCommandException {
    if (StringUtil.isEmptyOrSpaces(tagName)) {
        throw new HgCommandException("tag name is empty");
    }
    List<String> arguments = new ArrayList<>();
    arguments.add(tagName);
    if (!StringUtil.isEmptyOrSpaces(revisionNumberOrHash)) {
        arguments.add("--rev");
        arguments.add(revisionNumberOrHash);
    }
    new HgCommandExecutor(project).execute(repo, "tag", arguments, resultHandler);
    if (!project.isDisposed()) {
        HgRepositoryManager manager = HgUtil.getRepositoryManager(project);
        manager.updateRepository(repo);
    }
}
Also used : HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) ArrayList(java.util.ArrayList) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException)

Example 3 with HgCommandExecutor

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

the class HgWorkingCopyRevisionsCommand method identify.

/**
   * Returns the result of 'hg id' execution, i.e. current state of the repository.
   * @return one or two revision numbers. Two revisions is the case of unresolved merge. In other cases there are only one revision.
   */
@NotNull
public Couple<HgRevisionNumber> identify(@NotNull VirtualFile repo) {
    HgCommandExecutor commandExecutor = new HgCommandExecutor(myProject);
    commandExecutor.setSilent(true);
    HgCommandResult result = commandExecutor.executeInCurrentThread(repo, "identify", Arrays.asList("--num", "--id"));
    if (result == null) {
        return Couple.of(HgRevisionNumber.NULL_REVISION_NUMBER, null);
    }
    final List<String> lines = result.getOutputLines();
    if (lines != null && !lines.isEmpty()) {
        List<String> parts = StringUtil.split(lines.get(0), " ");
        String changesets = parts.get(0);
        String revisions = parts.get(1);
        if (parts.size() >= 2) {
            if (changesets.indexOf('+') != changesets.lastIndexOf('+')) {
                // in the case of unresolved merge we have 2 revisions at once, both current, so with "+"
                // 9f2e6c02913c+b311eb4eb004+ 186+183+
                List<String> chsets = StringUtil.split(changesets, "+");
                List<String> revs = StringUtil.split(revisions, "+");
                return Couple.of(HgRevisionNumber.getInstance(revs.get(0) + "+", chsets.get(0) + "+"), HgRevisionNumber.getInstance(revs.get(1) + "+", chsets.get(1) + "+"));
            } else {
                return Couple.of(HgRevisionNumber.getInstance(revisions, changesets), null);
            }
        }
    }
    return Couple.of(HgRevisionNumber.NULL_REVISION_NUMBER, null);
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with HgCommandExecutor

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

the class HgWorkingCopyRevisionsCommand method getRevisions.

/**
   * Returns the list of revisions returned by one mercurial commands (parents, identify, tip).
   * Executed a command on the whole repository or on the given file.
   * During a merge, the returned list contains 2 revision numbers. The order of these numbers is
   * important: the first parent was the parent of the working directory from <em>before</em>
   * the merge, the second parent is the changeset that was merged in.
   * @param repo     repository to execute on.
   * @param command  command to execute.
   * @param file     file which revisions are wanted. If <code><b>null</b></code> then repository revisions are considered.
   * @param revision revision to execute on. If <code><b>null</b></code> then executed without the '-r' parameter, i.e. on the latest revision.
   * @param silent   pass true if this command shouldn't be mentioned in the VCS console.
   * @return List of revisions.
   */
@NotNull
public List<HgRevisionNumber> getRevisions(@NotNull VirtualFile repo, @NotNull String command, @Nullable FilePath file, @Nullable HgRevisionNumber revision, boolean silent) {
    final List<String> args = new LinkedList<>();
    args.add("--template");
    args.add(HgChangesetUtil.makeTemplate("{rev}", "{node}"));
    if (revision != null) {
        args.add("-r");
        args.add(revision.getChangeset());
    }
    if (file != null) {
        // NB: this must be the last argument
        args.add(HgUtil.getOriginalFileName(file, ChangeListManager.getInstance(myProject)).getPath());
    }
    final HgCommandExecutor executor = new HgCommandExecutor(myProject);
    executor.setSilent(silent);
    final HgCommandResult result = executor.executeInCurrentThread(repo, command, args);
    if (result == null) {
        return new ArrayList<>(0);
    }
    final List<String> lines = new ArrayList<>();
    for (String line : result.getRawOutput().split(HgChangesetUtil.CHANGESET_SEPARATOR)) {
        if (!line.trim().isEmpty()) {
            // filter out empty lines
            lines.add(line);
        }
    }
    if (lines.isEmpty()) {
        return new ArrayList<>();
    }
    final List<HgRevisionNumber> revisions = new ArrayList<>(lines.size());
    for (String line : lines) {
        final List<String> parts = StringUtil.split(line, HgChangesetUtil.ITEM_SEPARATOR);
        if (parts.size() < 2) {
            LOG.error("getRevisions output parse error in line [" + line + "]\n All lines: \n" + lines);
            continue;
        }
        revisions.add(HgRevisionNumber.getInstance(parts.get(0), parts.get(1)));
    }
    return revisions;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with HgCommandExecutor

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

the class HgQFinishCommand method execute.

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();
        }
    });
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgCommandResultHandler(org.zmlx.hg4idea.execution.HgCommandResultHandler) 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