如何在java中获取SVN版本号之间的更改列表

时间:2012-11-16 09:48:04

标签: svn svnkit

假设您有SVN的开始修订号和最终修订号,是否有任何SDK api可以在java中获取更改后的列表?我正在使用TortoiseSVN。感谢。

1 个答案:

答案 0 :(得分:10)

我不确定我是否理解正确,
但是对于一个使用SVN的java库 你可以检查SVNKit。

http://svnkit.com/

这里有一个示例代码,用于获取存储库历史记录: http://wiki.svnkit.com/Printing_Out_Repository_History

修改

我使用svnkit 1.7.6和svn命令行版本1.6.5

尝试了示例代码
svn log [REPOSITORY URL] -r1000000:1000002

两者都给了我3条历史记录,我认为你正在做的事情存在问题。

这里是java的代码:

import java.util.Collection;
import java.util.Iterator;

import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNWCUtil;


public class TestSvnLog {

/**
 * @param args
 */
public static void main(String[] args) {
    DAVRepositoryFactory.setup( );

    String url = "[REPOSITORY URL]";
    String name = "anonymous";
    String password = "anonymous";
    long startRevision = 1000000;
    long endRevision = 1000002; //HEAD (the latest) revision

    SVNRepository repository = null;
    try {
        repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) );
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name, password );
        repository.setAuthenticationManager( authManager );


        Collection logEntries = null;

        logEntries = repository.log( new String[] { "" } , null , startRevision , endRevision , true , true );

        for ( Iterator entries = logEntries.iterator( ); entries.hasNext( ); ) {
            SVNLogEntry logEntry = ( SVNLogEntry ) entries.next( );
            System.out.println (String.format("revision: %d, date %s", logEntry.getRevision( ), logEntry.getDate()));
        }
    } catch (Exception e){

    }

}

}