我正在使用SVNKit从我们的存储库中获取文件的内容.我想在代码中更改内容并提交更改,而不必先检出文件.我已经搜索过网络,只找到了需要结账到本地文件系统的解决方案.
有谁知道这样做的方法?
我和TMate Software的人们谈过,看来这确实是可能的.他们解释它的方式,是的,您可以使用本地文件并使用新内容生成校验和并将其发送到Subversion,但是(如果有的话)这只会帮助Subversion验证您的本地副本中是否有正确和最新的内容.在一天结束时,无论如何,Subversion将会做自己的差异和增量.
因此,如果您没有本地副本,则可以创建校验和,就像文件是新的一样.这是从我的大项目中提取的粗略代码.请注意SVNDirEntry,如果您已经知道文件是否存在,则不需要提前检查; 我在这里提供它是出于解释目的.
SVNDirEntry dirEntry = svnRepository.info(filePath, -1);
ISVNEditor editor = svnRepository.getCommitEditor("example modification", null, true, null);
editor.openRoot(-1);
if(dirEntry.getKind() == SVNNodeKind.NONE)
{
editor.addFile(filePath, null, -1);
}
else
{
editor.openFile(filePath, -1);
}
editor.applyTextDelta(filePath, null);
final SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
final String checksum = deltaGenerator.sendDelta(filePath, inputStream, editor, true);
editor.closeFile(filePath, checksum);
editor.closeDir(); //close the root
editor.closeEdit();
Run Code Online (Sandbox Code Playgroud)
在获取提交编辑器之后,不要忘记将所有内容包装closeEdit()在一个try...catch块中,以便在出现问题时可以中止编辑.
我试过这个,它使用SVNKIt 1.3.7(例如来自Maven)通过我的所有测试:
<repositories>
<repository>
<id>svnkit-repository</id>
<name>SVNKit Repository</name>
<url>http://maven.tmatesoft.com/content/repositories/releases/</url>
</repository>
</repositories>
...
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.3.7</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4383 次 |
| 最近记录: |