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;
}
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;
}
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;
}
Aggregations