这并不难。如果你想保留复制历史,你可以运行以下代码
ISVNCommitEditor editor = svnRepository.getCommitEditor("", null);
editor.openRoot(latestRevision);
editor.openDir("path", latestRevision); //or use addDir if it doesn't exist
editor.openDir("path/to", latestRevision); //or use addDir if it doesn't exist
editor.openDir("path/to/new", latestRevision); //or use addDir if it doesn't exist
editor.addDir("path/to/new/directory", "/path/to/old/directory", copySourceRevision);
editor.closeDir();
editor.closeDir();
editor.closeDir();
editor.closeDir();
editor.closeDir();
editor.closeEdit();
但如果你不想保留历史,你可以用
创建编辑器
ISVNCommitEditor editor = svnRepository.getCommitEditor("", null);
然后调用
anotherSvnRepository.setLocation(copySourceUrl, true);
anotherSvnRepository.update(copySourceRevision, "", SVNDepth.INFINITY, false, reporter, customEditor);
使用以下代码代替reporter:
ISVNReporterBaton reporter = new ISVNReporterBaton() {
@Override
public void report(ISVNReporter reporter) throws SVNException {
reporter.setPath("", null, copySourceRevision, SVNDepth.INFINITY, true);
reporter.finishReport();
}
};
customEditor 应该是上面构造的 editor 的包装器,它将以正确的路径调用 editor(也许您应该添加一些 openDir/closeDir 调用以使编辑器调用正确)。
例如,您可以查看我的 svnkitfilter 项目的源代码,该项目执行类似的操作。
要了解目录/文件是否存在,请使用 SVNRepository#checkPath 方法。