IDEA-68731 Batch process hg revert and hg resolve. Get rid of HgFile.
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Tue, 26 Apr 2011 13:32:01 +0000 (17:32 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Tue, 26 Apr 2011 13:42:49 +0000 (17:42 +0400)
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgResolveCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRevertCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgRollbackEnvironment.java
plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgRevertTest.java

index e38814773a1f60da4c97c8673833cfe2d705f341..c0f408cd0e228681242a8ac179e6955133b1c4b8 100644 (file)
@@ -16,6 +16,7 @@ import com.intellij.openapi.project.Project;
 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;
@@ -24,10 +25,7 @@ import org.zmlx.hg4idea.execution.HgCommandResult;
 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 {
 
@@ -91,8 +89,13 @@ 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
index f8c984be9ba1524cd9c9d7a4ec556b54669a47d8..646b2c20159ed4555309d13f79c4f49c229b504d 100644 (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;
 
@@ -31,26 +33,27 @@ public class HgRevertCommand {
     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);
   }
 }
index b5847aca665256dd23185ce51776dcfc165e2277..1622c8e1fbef99f3299a427482cff26ca3d5a897 100644 (file)
@@ -21,17 +21,18 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
 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 {
 
@@ -92,19 +93,13 @@ 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);
     }
   }
 
index 451750a649e3ba6d10291232edfe97819e7c243d..42505a2bb901a633b6b2cef5ba4a31cfa27b1cfc 100644 (file)
@@ -1,11 +1,14 @@
 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;
 
@@ -19,7 +22,7 @@ public class HgRevertTest extends HgSingleUserTest {
     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());
@@ -38,7 +41,7 @@ public class HgRevertTest extends HgSingleUserTest {
     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());