IDEA-68118 Fixed annotation of selected revision of the file
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Mon, 25 Apr 2011 12:00:24 +0000 (16:00 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Mon, 25 Apr 2011 12:02:17 +0000 (16:02 +0400)
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAnnotateCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationProvider.java

index c30a73d67c4b04203d8f767be1063d46169b06b7..6fc4bbd22f015b204ddbf8ef8c6c858d23651154 100644 (file)
 package org.zmlx.hg4idea.command;
 
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vcs.history.VcsFileRevision;
+import org.jetbrains.annotations.NotNull;
 import org.zmlx.hg4idea.HgFile;
 import org.zmlx.hg4idea.HgRevisionNumber;
-import org.zmlx.hg4idea.execution.HgCommandResult;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
+import org.zmlx.hg4idea.execution.HgCommandResult;
 import org.zmlx.hg4idea.provider.annotate.HgAnnotationLine;
-import org.jetbrains.annotations.NotNull;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -45,9 +45,16 @@ public class HgAnnotateCommand {
     this.project = project;
   }
 
-  public List<HgAnnotationLine> execute(@NotNull HgFile hgFile) {
-    HgCommandExecutor executor = new HgCommandExecutor(project);
-    HgCommandResult result = executor.executeInCurrentThread(hgFile.getRepo(), "annotate", Arrays.asList("-cqnudl", hgFile.getRelativePath()));
+  public List<HgAnnotationLine> execute(@NotNull HgFile hgFile, VcsFileRevision revision) {
+    final List<String> arguments = new ArrayList<String>();
+    arguments.add("-cqnudl");
+    if (revision != null) {
+      arguments.add("-r");
+      HgRevisionNumber revisionNumber = (HgRevisionNumber)revision.getRevisionNumber();
+      arguments.add(revisionNumber.getChangeset());
+    }
+    arguments.add(hgFile.getRelativePath());
+    final HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(hgFile.getRepo(), "annotate", arguments);
 
     final List<HgAnnotationLine> annotations = new ArrayList<HgAnnotationLine>();
     if (result == null) {
@@ -58,15 +65,12 @@ public class HgAnnotateCommand {
       Matcher matcher = LINE_PATTERN.matcher(line);
       if (matcher.matches()) {
         String user = matcher.group(USER_GROUP);
-        HgRevisionNumber revision = HgRevisionNumber.getInstance(
-          matcher.group(REVISION_GROUP),
-          matcher.group(CHANGESET_GROUP)
-        );
+        HgRevisionNumber rev = HgRevisionNumber.getInstance(matcher.group(REVISION_GROUP), matcher.group(CHANGESET_GROUP));
         String date = matcher.group(DATE_GROUP);
         Integer lineNumber = Integer.valueOf(matcher.group(LINE_NUMBER_GROUP));
         String content = matcher.group(CONTENT_GROUP);
         HgAnnotationLine annotationLine = new HgAnnotationLine(
-          user, revision, date, lineNumber, content
+          user, rev, date, lineNumber, content
         );
         annotations.add(annotationLine);
       }
index b9803ea0a37788e654aba4dc9e482234e02732df..197e47a4facd4e51913dae9127a7f2ed77d6350c 100644 (file)
@@ -21,9 +21,12 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.vcsUtil.VcsUtil;
 import org.zmlx.hg4idea.HgFile;
+import org.zmlx.hg4idea.HgFileRevision;
 import org.zmlx.hg4idea.command.HgAnnotateCommand;
 import org.zmlx.hg4idea.command.HgLogCommand;
 
+import java.util.List;
+
 public class HgAnnotationProvider implements AnnotationProvider {
 
   private static final int DEFAULT_LIMIT = 500;
@@ -35,20 +38,18 @@ public class HgAnnotationProvider implements AnnotationProvider {
   }
 
   public FileAnnotation annotate(VirtualFile file) throws VcsException {
+    return annotate(file, null);
+  }
+
+  public FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException {
     final VirtualFile vcsRoot = VcsUtil.getVcsRootFor(myProject, VcsUtil.getFilePath(file.getPath()));
     if (vcsRoot == null) {
       throw new VcsException("vcs root is null");
     }
     final HgFile hgFile = new HgFile(vcsRoot, VfsUtil.virtualToIoFile(file));
-    return new HgAnnotation(
-      hgFile,
-      (new HgAnnotateCommand(myProject)).execute(hgFile),
-      (new HgLogCommand(myProject)).execute(hgFile, DEFAULT_LIMIT, false)
-    );
-  }
-
-  public FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException {
-    return annotate(file);
+    final List<HgAnnotationLine> annotationResult = (new HgAnnotateCommand(myProject)).execute(hgFile, revision);
+    final List<HgFileRevision> logResult = (new HgLogCommand(myProject)).execute(hgFile, DEFAULT_LIMIT, false);
+    return new HgAnnotation(hgFile, annotationResult, logResult);
   }
 
   public boolean isAnnotationValid(VcsFileRevision rev) {