import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
+import com.intellij.vcsUtil.VcsFileUtil;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgFile;
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
import java.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
public class HgResolveCommand {
new HgCommandExecutor(myProject).execute(repo, "resolve", Arrays.asList("--mark", path.getPath()), null);
}
- public void markResolved(VirtualFile repo, FilePath path) {
- new HgCommandExecutor(myProject).execute(repo, "resolve", Arrays.asList("--mark", path.getPath()), null);
+ public void markResolved(VirtualFile repo, Collection<FilePath> paths) {
+ for (List<String> chunk : VcsFileUtil.chunkPaths(repo, paths)) {
+ final List<String> args = new ArrayList<String>();
+ args.add("--mark");
+ args.addAll(chunk);
+ new HgCommandExecutor(myProject).execute(repo, "resolve", args, null);
+ }
}
}
\ No newline at end of file
package org.zmlx.hg4idea.command;
import com.intellij.openapi.project.Project;
-import com.intellij.util.containers.ContainerUtil;
+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.zmlx.hg4idea.HgFile;
import org.zmlx.hg4idea.HgRevisionNumber;
import org.zmlx.hg4idea.HgVcs;
import org.zmlx.hg4idea.execution.HgCommandExecutor;
+import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
this.project = project;
}
- public void execute(HgFile hgFile, HgRevisionNumber vcsRevisionNumber, boolean backupFile) {
- List<String> arguments = new LinkedList<String>();
-
+ public void execute(VirtualFile repo, Collection<FilePath> files, HgRevisionNumber vcsRevisionNumber, boolean backupFile) {
+ final List<String> options = new LinkedList<String>();
if (vcsRevisionNumber != null) {
- arguments.add("--rev");
+ options.add("--rev");
if (StringUtils.isNotBlank(vcsRevisionNumber.getChangeset())) {
- arguments.add(vcsRevisionNumber.getChangeset());
+ options.add(vcsRevisionNumber.getChangeset());
}
else {
- arguments.add(vcsRevisionNumber.getRevision());
+ options.add(vcsRevisionNumber.getRevision());
}
}
-
if (!backupFile) {
- arguments.add("--no-backup");
+ options.add("--no-backup");
}
- ContainerUtil.addAll(arguments, hgFile.getRelativePath());
-
- new HgCommandExecutor(project).execute(hgFile.getRepo(), "revert", arguments, null);
+ for (List<String> chunk : VcsFileUtil.chunkPaths(repo, files)) {
+ List<String> args = new LinkedList<String>();
+ args.addAll(options);
+ args.addAll(chunk);
+ new HgCommandExecutor(project).execute(repo, "revert", args, null);
+ }
project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project);
}
}
import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
import com.intellij.openapi.vcs.rollback.RollbackProgressListener;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
-import org.zmlx.hg4idea.HgFile;
import org.zmlx.hg4idea.HgRevisionNumber;
import org.zmlx.hg4idea.HgVcsMessages;
import org.zmlx.hg4idea.command.HgResolveCommand;
import org.zmlx.hg4idea.command.HgRevertCommand;
import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand;
+import org.zmlx.hg4idea.util.HgUtil;
+import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
public class HgRollbackEnvironment implements RollbackEnvironment {
HgRevertCommand revertCommand = new HgRevertCommand(project);
HgResolveCommand resolveCommand = new HgResolveCommand(project);
- for (FilePath filePath : filePaths) {
- VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, filePath);
- if (vcsRoot == null) {
- continue;
- }
-
- HgFile hgFile = new HgFile(vcsRoot, filePath);
-
- HgRevisionNumber revisionNumber = identifyCommand.firstParent(vcsRoot);
- revertCommand.execute(hgFile, revisionNumber, false);
- resolveCommand.markResolved(vcsRoot, filePath);
+ for (Map.Entry<VirtualFile,Collection<FilePath>> entry : HgUtil.groupFilePathsByHgRoots(project, filePaths).entrySet()) {
+ final VirtualFile repo = entry.getKey();
+ final Collection<FilePath> files = entry.getValue();
- dirtyScopeManager.dirDirtyRecursively(filePath.getParentPath());
+ HgRevisionNumber revisionNumber = identifyCommand.firstParent(repo);
+ revertCommand.execute(repo, files, revisionNumber, false);
+ resolveCommand.markResolved(repo, files);
}
}
package org.zmlx.hg4idea.test;
+import com.intellij.vcsUtil.VcsUtil;
import org.testng.annotations.Test;
import org.zmlx.hg4idea.HgRevisionNumber;
import org.zmlx.hg4idea.command.HgCatCommand;
import org.zmlx.hg4idea.command.HgRevertCommand;
+import java.io.File;
import java.nio.charset.Charset;
+import java.util.Collections;
import static org.testng.Assert.assertEquals;
fillFile(myProjectDir, new String[]{"file.txt"}, "new contents");
HgRevertCommand revertCommand = new HgRevertCommand(myProject);
- revertCommand.execute(getHgFile("file.txt"), null, false);
+ revertCommand.execute(myRepo.getDir(), Collections.singleton(VcsUtil.getFilePath(new File(myProjectDir, "file.txt"))), null, false);
HgCatCommand catCommand = new HgCatCommand(myProject);
String content = catCommand.execute(getHgFile("file.txt"), null, Charset.defaultCharset());
runHgOnProjectRepo("commit", "-m", "new contents");
HgRevertCommand revertCommand = new HgRevertCommand(myProject);
- revertCommand.execute(getHgFile("file.txt"), HgRevisionNumber.getLocalInstance("0"), false);
+ revertCommand.execute(myRepo.getDir(), Collections.singleton(VcsUtil.getFilePath(new File(myProjectDir, "file.txt"))), HgRevisionNumber.getLocalInstance("0"), false);
HgCatCommand catCommand = new HgCatCommand(myProject);
String content = catCommand.execute(getHgFile("file.txt"), HgRevisionNumber.getLocalInstance("0"), Charset.defaultCharset());