【问题标题】:How to get the changed list between revision numbers of SVN in java如何在java中获取SVN修订号之间的更改列表
【发布时间】:2012-11-16 22:59:50
【问题描述】:

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

【问题讨论】:

    标签: svn svnkit


    【解决方案1】:

    我不确定我是否理解正确,
    但是对于一个使用 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){
    
        }
    
    }
    
    }
    

    【讨论】:

    • 我只是补充一点,SVNKit 的 SvnOperationFactory#createDiffSummarize 方法会有所帮助。
    • org.tmatesoft.svn.core.io.SVNRepository.log 方法是否有任何错误?为什么我在使用SVN diff 命令时得到不同的logEntries 编号?
    • 我做了一些测试,使用 log api 我得到了一个大小为 25 的 Collection。但是当我使用命令行时,我得到了 100 多行日志,谁能告诉我为什么?是错误还是我犯了错误?谢谢
    • SVNKit 是否有 bug 很容易理解:jsvn 可执行文件与 SVNKit 发行版一起提供。如果它表现得像本机 SVN,则没有错误。如果不查看您运行的命令和代码,我无法告诉您您是否做错了什么。
    • 抱歉弄错了,现在我明白了repository.log的方法可以获取您指定范围内的所有修订号。不是文件更改日志列表。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多