Search in sources :

Example 1 with HgFileStatusEnum

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

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 HgChange (org.zmlx.hg4idea.HgChange)1 HgFile (org.zmlx.hg4idea.HgFile)1 HgFileStatusEnum (org.zmlx.hg4idea.HgFileStatusEnum)1