如何识别SVN路径是SVNkit的目录或文件?

时间:2012-11-16 13:05:44

标签: java svn svnkit

假设你有一个如下所示的指定SVN路径,我怎么知道这个项目是svn目录或svn文件。谢谢。

http://cvs-server.test.com:8001/svn/test

更新

            SVNURL svnUrl = SVNURL.parseURIEncoded(url);
            SVNRepository repos = SVNRepositoryFactory.create(svnUrl);
            ISVNAuthenticationManager authManager = 
            SVNWCUtil.createDefaultAuthenticationManager("user1","123");

            repos.setAuthenticationManager(authManager);

            SVNNodeKind nodeKind = repos.checkPath(url, repos.getLatestRevision());

为什么我得到none即使网址是文件?我确信这个网址存在于SVN中。 ORZ ... SVNkit存在许多错误。

3 个答案:

答案 0 :(得分:3)

如果遇到错误,请向http://issues.tmatesoft.com/issues/SVNKIT报告。

checkPath不适用于URL,它适用于路径,绝对(即相对于存储库根目录)或相对(对于构造SVNRepository实例的URL)---请参阅其更多细节的javadoc

所以你可以使用这段代码

SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());

甚至

SVNNodeKind nodeKind = repos.checkPath("", -1);

第二个变体会更快,因为它不会执行getLatestRevision请求,而且它是检查SVNKit本身经常使用的URL存在的一种相当流行的方法。

或者,您可以使用绝对路径(应以“/”开头),但要指定的路径取决于您的存储库根目录。您可以通过运行

来获取存储库根目录
$ svn info "http://cvs-server.test.com:8001/svn/test"

或通过运行

repos.getRepositoryRoot(true);

来自SVNKit代码。绝对路径应以“/”开头,并且相对于获得的存储库根目录。

答案 1 :(得分:2)

尝试这样的事情:

String url = "http://cvs-server.test.com:8001/svn/test";
SVNURL svnUrl = SVNURL.parseURIEncoded(url);
SVNRepository repos = SVNRepositoryFactory.create(svnUrl);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS);
repos.setAuthenticationManager(authManager); 
SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());

nodeKind将是FILEDIRNONE中的一个。

答案 2 :(得分:0)

这是正确的方法:

public static boolean isFolder(String url) throws SVNException {
    SVNURL svnURL = SVNURL.parseURIEncoded(url);
    SVNRepository repos = SVNRepositoryFactory.create(svnURL);
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS);
    repos.setAuthenticationManager(authManager);
    SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());
    System.out.println(nodeKind);
    return nodeKind != null && nodeKind == SVNNodeKind.DIR;
}
相关问题