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;
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) {
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);
}
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;
}
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) {