我正在尝试使用SVNKit从SVN仓库获取日志。
public static void svnLogTest() {
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
final SvnLog log = svnOperationFactory.createLog();
SVNURL url = null;
try {
url = SVNURL
.parseURIEncoded("https://svn-repo");
} catch (SVNException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.setSingleTarget(SvnTarget.fromURL(url));
log.addRange(SvnRevisionRange.create(SVNRevision.create(111),
SVNRevision.create(222)));
log.getRevisionRanges();
SVNLogEntry logEntry = null;
try {
logEntry = log.run();
System.out.println(logEntry.getAuthor() + " " + logEntry.getRevision() + " "
+ logEntry.getDate());
} catch (SVNException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但它只会给我第一个版本,我应该如何迭代打印特定日期范围的日志?
答案 0 :(得分:2)
这是因为
log.run();
始终只返回一个日志条目(对于其他SvnOperation#run方法也是如此)。要获得所有条目,请使用接收器:
log.setReceiver(new ISvnObjectReceiver<SVNLogEntry>() {
@Override
public void receive(SvnTarget target, SVNLogEntry logEntry) throws SVNException {
//process logEntry here
}
});
log.run();