blob: c2423de0b70d9da1489fd35b53cd01ddaa60c9ef [file] [log] [blame]
package org.jetbrains.idea.svn.annotate;
import com.intellij.openapi.vcs.VcsException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.api.BaseSvnClient;
import org.jetbrains.idea.svn.checkin.CommitInfo;
import org.jetbrains.idea.svn.diff.DiffOptions;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.wc.ISVNAnnotateHandler;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import java.io.File;
import java.util.Date;
/**
* @author Konstantin Kolosovsky.
*/
public class SvnKitAnnotateClient extends BaseSvnClient implements AnnotateClient {
@Override
public void annotate(@NotNull SvnTarget target,
@NotNull SVNRevision startRevision,
@NotNull SVNRevision endRevision,
@Nullable SVNRevision pegRevision,
boolean includeMergedRevisions,
@Nullable DiffOptions diffOptions,
@Nullable AnnotationConsumer handler) throws VcsException {
try {
SVNLogClient client = myVcs.getSvnKitManager().createLogClient();
client.setDiffOptions(toDiffOptions(diffOptions));
if (target.isFile()) {
client
.doAnnotate(target.getFile(), pegRevision, startRevision, endRevision, true, includeMergedRevisions, toAnnotateHandler(handler),
null);
}
else {
client
.doAnnotate(target.getURL(), pegRevision, startRevision, endRevision, true, includeMergedRevisions, toAnnotateHandler(handler),
null);
}
}
catch (SVNException e) {
throw new VcsException(e);
}
}
@Nullable
private static ISVNAnnotateHandler toAnnotateHandler(@Nullable final AnnotationConsumer handler) {
ISVNAnnotateHandler result = null;
if (handler != null) {
result = new ISVNAnnotateHandler() {
@Override
public void handleLine(Date date, long revision, String author, String line) throws SVNException {
// deprecated - not called
}
@Override
public void handleLine(Date date,
long revision,
String author,
String line,
Date mergedDate,
long mergedRevision,
String mergedAuthor,
String mergedPath,
int lineNumber) throws SVNException {
if (revision > 0) {
CommitInfo info = new CommitInfo.Builder(revision, date, author).build();
CommitInfo mergeInfo = mergedDate != null ? new CommitInfo.Builder(mergedRevision, mergedDate, mergedAuthor).build() : null;
handler.consume(lineNumber, info, mergeInfo);
}
}
@Override
public boolean handleRevision(Date date, long revision, String author, File contents) throws SVNException {
return false;
}
@Override
public void handleEOF() throws SVNException {
}
};
}
return result;
}
}