2

我正在尝试使用 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();
    }

但它只会给我第一次修订,我应该如何迭代打印特定日期范围的日志?

4

1 回答 1

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();
于 2013-03-13T09:57:42.727 回答