import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
import org.apache.commons.lang.StringUtils;
+import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgChange;
import org.zmlx.hg4idea.HgFile;
import org.zmlx.hg4idea.HgFileStatusEnum;
return execute(repo, null);
}
- public Set<HgChange> execute(VirtualFile repo, String relativePath) {
+ public Set<HgChange> execute(VirtualFile repo, @Nullable Collection<FilePath> paths) {
if (repo == null) {
return Collections.emptySet();
}
HgCommandExecutor executor = new HgCommandExecutor(project);
executor.setSilent(true);
- List<String> arguments = new LinkedList<String>();
+ List<String> options = new LinkedList<String>();
if (includeAdded) {
- arguments.add("--added");
+ options.add("--added");
}
if (includeModified) {
- arguments.add("--modified");
+ options.add("--modified");
}
if (includeRemoved) {
- arguments.add("--removed");
+ options.add("--removed");
}
if (includeDeleted) {
- arguments.add("--deleted");
+ options.add("--deleted");
}
if (includeUnknown) {
- arguments.add("--unknown");
+ options.add("--unknown");
}
if (includeIgnored) {
- arguments.add("--ignored");
+ options.add("--ignored");
}
if (includeCopySource) {
- arguments.add("--copies");
+ options.add("--copies");
}
if (baseRevision != null) {
- arguments.add("--rev");
- arguments.add(baseRevision.getChangeset());
+ options.add("--rev");
+ options.add(baseRevision.getChangeset());
if (targetRevision != null) {
- arguments.add("--rev");
- arguments.add(targetRevision.getChangeset());
+ options.add("--rev");
+ options.add(targetRevision.getChangeset());
}
}
- if (relativePath != null) {
- arguments.add(relativePath);
+ final Set<HgChange> changes = new HashSet<HgChange>();
+
+ if (paths != null) {
+ final List<List<String>> chunked = VcsFileUtil.chunkPaths(repo, paths);
+ for (List<String> chunk : chunked) {
+ List<String> args = new ArrayList<String>();
+ args.addAll(options);
+ args.addAll(chunk);
+ HgCommandResult result = executor.executeInCurrentThread(repo, "status", args);
+ changes.addAll(parseChangesFromResult(repo, result));
+ }
+ } else {
+ HgCommandResult result = executor.executeInCurrentThread(repo, "status", options);
+ changes.addAll(parseChangesFromResult(repo, result));
}
+ return changes;
+ }
- //executor.setSilent(true);
- HgCommandResult result = executor.executeInCurrentThread(repo, "status", arguments);
- Set<HgChange> changes = new HashSet<HgChange>();
+ private static Collection<HgChange> parseChangesFromResult(VirtualFile repo, HgCommandResult result) {
+ final Set<HgChange> changes = new HashSet<HgChange>();
HgChange previous = null;
if (result == null) {
return changes;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsUtil;
import org.zmlx.hg4idea.*;
-import org.zmlx.hg4idea.command.*;
+import org.zmlx.hg4idea.command.HgResolveCommand;
+import org.zmlx.hg4idea.command.HgResolveStatusEnum;
+import org.zmlx.hg4idea.command.HgStatusCommand;
+import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand;
+import org.zmlx.hg4idea.util.HgUtil;
import java.awt.*;
import java.util.*;
myVcsKey = vcsKey;
}
+ public boolean isModifiedDocumentTrackingRequired() {
+ return true;
+ }
+
+ public void doCleanup(List<VirtualFile> files) {
+ }
+
public void getChanges(VcsDirtyScope dirtyScope, ChangelistBuilder builder,
ProgressIndicator progress, ChangeListManagerGate addGate) throws VcsException {
final Collection<HgChange> changes = new HashSet<HgChange>();
-
- for (FilePath filePath : dirtyScope.getRecursivelyDirtyDirectories()) {
- changes.addAll(process(builder, filePath));
- }
- for (FilePath filePath : dirtyScope.getDirtyFiles()) {
- changes.addAll(process(builder, filePath));
- }
-
+ changes.addAll(process(builder, dirtyScope.getRecursivelyDirtyDirectories()));
+ changes.addAll(process(builder, dirtyScope.getDirtyFiles()));
processUnsavedChanges(builder, dirtyScope.getDirtyFilesNoExpand(), changes);
}
- public boolean isModifiedDocumentTrackingRequired() {
- return true;
- }
+ private Collection<HgChange> process(ChangelistBuilder builder, Collection<FilePath> files) {
+ final Set<HgChange> hgChanges = new HashSet<HgChange>();
+ for (Map.Entry<VirtualFile, Collection<FilePath>> entry : HgUtil.groupFilePathsByHgRoots(myProject, files).entrySet()) {
+ VirtualFile repo = entry.getKey();
- public void doCleanup(List<VirtualFile> files) {
- }
+ final HgRevisionNumber workingRevision = new HgWorkingCopyRevisionsCommand(myProject).identify(repo);
+ final HgRevisionNumber parentRevision = new HgWorkingCopyRevisionsCommand(myProject).firstParent(repo);
+ final Map<HgFile, HgResolveStatusEnum> list = new HgResolveCommand(myProject).getListSynchronously(repo);
- private Collection<HgChange> process(ChangelistBuilder builder,
- FilePath filePath) {
- VirtualFile repo = VcsUtil.getVcsRootFor(myProject, filePath);
- if (repo == null) {
- return new HashSet<HgChange>();
+ hgChanges.addAll(new HgStatusCommand(myProject).execute(repo, entry.getValue()));
+ sendChanges(builder, hgChanges, list, workingRevision, parentRevision);
}
- Set<HgChange> hgChanges = new HgStatusCommand(myProject).execute(repo, filePath.getPath());
- if (hgChanges == null || hgChanges.isEmpty()) {
- return new HashSet<HgChange>();
- }
- sendChanges(builder, hgChanges,
- new HgResolveCommand(myProject).getListSynchronously(repo),
- new HgWorkingCopyRevisionsCommand(myProject).identify(repo),
- new HgWorkingCopyRevisionsCommand(myProject).firstParent(repo)
- );
return hgChanges;
}