Search in sources :

Example 1 with HgChange

use of org.zmlx.hg4idea.HgChange 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 HgChange

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

the class HgStatusCommand method parseChangesFromResult.

private Collection<HgChange> parseChangesFromResult(VirtualFile repo, HgCommandResult result, List<String> args) {
    final Set<HgChange> changes = new HashSet<>();
    HgChange previous = null;
    if (result == null) {
        return changes;
    }
    List<String> errors = result.getErrorLines();
    if (!errors.isEmpty()) {
        if (result.getExitValue() != 0 && !myProject.isDisposed()) {
            String title = "Could not execute hg status command ";
            LOG.warn(title + errors.toString());
            VcsNotifier.getInstance(myProject).logInfo(title, errors.toString());
            return changes;
        }
        LOG.warn(errors.toString());
    }
    for (String line : result.getOutputLines()) {
        if (StringUtil.isEmptyOrSpaces(line) || line.length() < ITEM_COUNT) {
            LOG.warn("Unexpected line in status '" + line + '\'');
            continue;
        }
        char statusChar = line.charAt(STATUS_INDEX);
        HgFileStatusEnum status = HgFileStatusEnum.parse(statusChar);
        if (status == null) {
            LOG.error("Unknown status [" + statusChar + "] in line [" + line + "]" + "\n with arguments " + args);
            continue;
        }
        File ioFile = new File(repo.getPath(), line.substring(2));
        if (HgFileStatusEnum.COPY == status && previous != null && previous.getStatus() == HgFileStatusEnum.ADDED) {
            previous.setStatus(HgFileStatusEnum.COPY);
            previous.setBeforeFile(new HgFile(repo, ioFile));
            previous = null;
        } else {
            previous = new HgChange(new HgFile(repo, ioFile), status);
            changes.add(previous);
        }
    }
    return changes;
}
Also used : HgFile(org.zmlx.hg4idea.HgFile) HgChange(org.zmlx.hg4idea.HgChange) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) HgFile(org.zmlx.hg4idea.HgFile) HgFileStatusEnum(org.zmlx.hg4idea.HgFileStatusEnum)

Example 3 with HgChange

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

the class HgStatusCommand method getFiles.

@NotNull
public Collection<VirtualFile> getFiles(@NotNull VirtualFile repo, @Nullable List<VirtualFile> files) throws VcsException {
    Collection<VirtualFile> resultFiles = new HashSet<>();
    Set<HgChange> change = executeInCurrentThread(repo, files != null ? ObjectsConvertor.vf2fp(files) : null);
    for (HgChange hgChange : change) {
        resultFiles.add(hgChange.afterFile().toFilePath().getVirtualFile());
    }
    return resultFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgChange(org.zmlx.hg4idea.HgChange) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HgChange (org.zmlx.hg4idea.HgChange)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1 HgFile (org.zmlx.hg4idea.HgFile)1 HgFileStatusEnum (org.zmlx.hg4idea.HgFileStatusEnum)1 HgCommandExecutor (org.zmlx.hg4idea.execution.HgCommandExecutor)1 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)1