使用Java中的SVNKit调用doLog()时的奇怪URL

时间:2012-02-15 17:41:30

标签: java svn svnkit

这是一个奇怪的。我希望你能提供帮助。

我正在尝试使用SVNKit设置并调用doLog()。设置有点复杂,我不确定一些参数。错误是(我认为)一些“未知”字符被插入到SVN URL中,可能是因为设置不正确。这是稍微消毒的代码:

    // Auth manager
    String userName = "ksnortum";
    String password = "p@ssw0rd";
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( userName, password );

    // Options
    boolean readonly = true;
    ISVNOptions options = SVNWCUtil.createDefaultOptions( readonly );

    // Get log client
    SVNLogClient logClient = new SVNLogClient( authManager, options );

    // SVN URL parameters
    String protocol = "https";
    String userInfo = userName;
    String host = "svn.hostname.com";
    int port = 8443;
    String path = "";
    boolean uriEncoded = true;
    SVNURL url = null;

    // Create URL
    try {
        url = SVNURL.create( protocol, userInfo, host, port, path, uriEncoded );
    }
    catch ( SVNException e ) {
        System.out.println( "Can't create URL: " + e.toString() );
    }

    System.out.println( "URL: " + url.toString() ); // debug

    // Parameters for doLog()
    String[] paths = { "svn/Training/PDX_Cycle_2_2011" };
    SVNRevision pegRevision = SVNRevision.create( 0l );
    SVNRevision startRevision = SVNRevision.create( 0l );
    SVNRevision endRevision = SVNRevision.create( -1l );
    boolean stopOnCopy = false;
    boolean discoverChangedPaths = true;
    long limit = 9999l;

    // Log event handler
    ISVNLogEntryHandler handler = new ISVNLogEntryHandler() {

        /**
         * This method will process when doLog() is done
         */
        @Override
        public void handleLogEntry( SVNLogEntry logEntry ) throws SVNException {
            System.out.println( "Author: " + logEntry.getAuthor() );
            System.out.println( "Date: " + logEntry.getDate() );
            System.out.println( "Message: " + logEntry.getMessage() );
            System.out.println( "Revision: " + logEntry.getRevision() );
        }
    };

    // Do log
    try {
        logClient.doLog( url, paths, pegRevision, startRevision, endRevision, stopOnCopy, discoverChangedPaths, limit, handler );
    }
    catch ( SVNException e ) {
        System.out.println( "Error in doLog() " );
        e.printStackTrace();
    }

这是debug和stacktrace信息:

URL: https://ksnortum@svn.hostname.com:8443
org.tmatesoft.svn.core.SVNException: svn: '/svn/Training/!svn/bc/0/PDX_Cycle_2_2011' path not found: 404 Not Found (https://ksnortum@svn.hostname.com:8443)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.logImpl(DAVRepository.java:986)
at org.tmatesoft.svn.core.io.SVNRepository.log(SVNRepository.java:1034)
at org.tmatesoft.svn.core.wc.SVNLogClient.doLog(SVNLogClient.java:1028)
at org.tmatesoft.svn.core.wc.SVNLogClient.doLog(SVNLogClient.java:895)
at org.tmatesoft.svn.core.wc.SVNLogClient.doLog(SVNLogClient.java:827)
at org.tmatesoft.svn.examples.repository.LogEntry.start(LogEntry.java:93)
at org.tmatesoft.svn.examples.repository.LogEntry.main(LogEntry.java:27)
Error in doLog()

问题是svn: '/svn/Training/!svn/bc/0/PDX_Cycle_2_2011' path not found。我不知道为什么!svn/bc/0在路径名中。


编辑:

看起来我需要对修订做得更好。我更改了这一行:

SVNRevision endRevision = SVNRevision.HEAD;

这帮了很多忙。另外,我从doLog()参数中取出了路径:

String[] paths = { "" };

...并将它们放入网址:

String path = "svn/Training/PDX_Cycle_2_2011";

修订似乎是最大的问题。感谢您的评论。

1 个答案:

答案 0 :(得分:2)

它的长短是知道!svn/bc/0是一个合法的URL,它指向修订版零。因此,将结束修订更改为HEAD而不是-1使其正常工作。