java 使用 SVNKit 检出目录/文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3395322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Checking Out Directory / File with SVNKit
提问by Federer
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 just 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?
我在 wiki 上看不到记录了签出的地方。理想情况下,我想检查一个文件“example/folder/file.xml”,如果不仅仅是文件夹......然后当应用程序关闭或以其他方式关闭时,能够提交对该文件的更改。我该怎么做呢?
采纳答案by Gilbert Le Blanc
You cannot check out a file in Subversion. You have to check out a folder.
您不能在 Subversion 中检出文件。您必须检出一个文件夹。
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);
回答by Dmitry Pavlenko
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.
作为 SVNKit 开发人员,我建议您更喜欢基于 SvnOperationFactory 的新 API。旧 API(基于 SVNClientManager)仍可运行,但所有新的 SVN 功能都将仅适用于新 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();
}
回答by Wilfried
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?
我还使用了 Dmitry Pavlenko 提出的代码片段,我没有遇到任何问题。但是签出或更新 35 MB 的存储库结构花了将近 30 分钟。它在我的用例中不可用(只需将目录结构检出作为 Web 应用程序的内容/文档/媒体的一部分)。还是我犯了一些错误?
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();

