开发者

Checking Out Directory / File with SVNKit

I can't see on the wiki where checking out is documented. Ideally, I would like to check out a file "example/folder/file.xml", if not ju开发者_开发问答st the folder... and then when the application closes down or otherwise, be able to commit back in changes to this file. How do I do this?


As SVNKit developer, I would recommend you to prefer new API based on SvnOperationFactory. The old API (based on SVNClientManager) will be operational still but all new SVN features will come only to the new API.

final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
    final SvnCheckout checkout = svnOperationFactory.createCheckout();
    checkout.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
    checkout.setSource(SvnTarget.fromURL(url));
    //... other options
    checkout.run();
} finally {
    svnOperationFactory.dispose();
}


You cannot check out a file in Subversion. You have to check out a folder.

To check out a folder with one or more files:

SVNClientManager ourClientManager = SVNClientManager.newInstance(null, 
            repository.getAuthenticationManager());
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
updateClient.doCheckout(url, destPath, revision, revision,
            isRecursive);

To commit a previously checked out folder:

SVNClientManager ourClientManager = SVNClientManager.newInstance(null, 
            repository.getAuthenticationManager());
ourClientManager.getWCClient().doInfo(wcPath, SVNRevision.HEAD);
ourClientManager.getCommitClient().doCommit
        (new File[] { wcPath }, keepLocks, commitMessage, false, true);


I also used the code snippet proposed by Dmitry Pavlenko and I had no problems. But it took nearly 30 minutes to checkout or update a repo struture of 35 MB. It's not useable in my usecase (simply checking out a directory structure as part of the content/documents/media of a web application). Or have I made some errors?

final ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password);
final SVNURL svnUrl = SVNURL.create(url.getProtocol(), name, url.getHost(), 443, url.getPath(), true);

SVNRepository svnRepo= SVNRepositoryFactory.create(svnUrl);
svnRepo.setAuthenticationManager(authManager);
svnOperationFactory.setAuthenticationManager(authManager);

SVNDirEntry entry = svnRepo.info(".", -1);
long remoteRevision = entry.getRevision();

if (!workingCopyDirectory.exists()) {
    workingCopyDirectory.mkdirs();
}

final SvnCheckout checkout = svnOperationFactory.createCheckout();
checkout.setSource(SvnTarget.fromURL(svnUrl));
checkout.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
remoteRevision = checkout.run();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜